27 #include "llvm/ADT/Hashing.h"
28 #include "llvm/ADT/StringExtras.h"
29 #include "llvm/IR/DataLayout.h"
30 #include "llvm/IR/Intrinsics.h"
31 #include "llvm/IR/LLVMContext.h"
32 #include "llvm/IR/MDBuilder.h"
33 #include "llvm/Support/ConvertUTF.h"
34 #include "llvm/Support/MathExtras.h"
36 using namespace clang;
37 using namespace CodeGen;
44 unsigned addressSpace =
45 cast<llvm::PointerType>(value->getType())->getAddressSpace();
49 destType = llvm::Type::getInt8PtrTy(
getLLVMContext(), addressSpace);
51 if (value->getType() == destType)
return value;
52 return Builder.CreateBitCast(value, destType);
59 if (!
Builder.isNamePreserving())
66 auto *
Store =
new llvm::StoreInst(Init, Var);
128 if (!ignoreResult && aggSlot.
isIgnored())
133 llvm_unreachable(
"bad evaluation kind");
176 llvm_unreachable(
"bad evaluation kind");
220 VD && isa<VarDecl>(VD) && VD->
hasAttr<ObjCPreciseLifetimeAttr>();
232 ObjCARCReferenceLifetimeType, *Destroy,
236 ObjCARCReferenceLifetimeType,
237 *Destroy, CleanupKind & EHCleanup);
241 llvm_unreachable(
"temporary cannot have dynamic storage duration");
243 llvm_unreachable(
"unknown storage duration");
251 auto *ClassDecl = cast<CXXRecordDecl>(RT->getDecl());
252 if (!ClassDecl->hasTrivialDestructor())
253 ReferenceTemporaryDtor = ClassDecl->getDestructor();
256 if (!ReferenceTemporaryDtor)
263 llvm::Constant *CleanupFn;
264 llvm::Constant *CleanupArg;
267 cast<llvm::Constant>(ReferenceTemporary), E->
getType(),
270 CleanupArg = llvm::Constant::getNullValue(CGF.
Int8PtrTy);
274 CleanupArg = cast<llvm::Constant>(ReferenceTemporary);
289 ReferenceTemporary, E->
getType(),
295 llvm_unreachable(
"temporary cannot have dynamic storage duration");
314 auto *GV =
new llvm::GlobalVariable(
316 llvm::GlobalValue::PrivateLinkage, Init,
".ref.tmp");
329 llvm_unreachable(
"temporary can't have dynamic storage duration");
331 llvm_unreachable(
"unknown storage duration");
345 if (
auto *Var = dyn_cast<llvm::GlobalVariable>(Object)) {
346 Object = llvm::ConstantExpr::getBitCast(
350 assert(!Var->hasInitializer());
356 default: llvm_unreachable(
"expected scalar or aggregate expression");
379 for (
const auto &Ignored : CommaLHSs)
382 if (
const auto *opaque = dyn_cast<OpaqueValueExpr>(E)) {
383 if (opaque->getType()->isRecordType()) {
384 assert(Adjustments.empty());
391 if (
auto *Var = dyn_cast<llvm::GlobalVariable>(Object)) {
392 Object = llvm::ConstantExpr::getBitCast(
397 if (!Var->hasInitializer()) {
409 for (
unsigned I = Adjustments.size(); I != 0; --I) {
411 switch (Adjustment.
Kind) {
423 assert(LV.isSimple() &&
424 "materialized temporary field is not a simple lvalue");
425 Object = LV.getAddress();
432 *
this, E, Object, Ptr, Adjustment.
Ptr.
MPT);
465 const llvm::Constant *Elts) {
466 return cast<llvm::ConstantInt>(Elts->getAggregateElement(Idx))
473 llvm::Value *KMul = Builder.getInt64(0x9ddfea08eb382d69ULL);
475 llvm::Value *A0 = Builder.CreateMul(Builder.CreateXor(Low, High), KMul);
476 llvm::Value *A1 = Builder.CreateXor(Builder.CreateLShr(A0, K47), A0);
477 llvm::Value *B0 = Builder.CreateMul(Builder.CreateXor(High, A1), KMul);
478 llvm::Value *B1 = Builder.CreateXor(Builder.CreateLShr(B0, K47), B0);
479 return Builder.CreateMul(B1, KMul);
491 CharUnits Alignment,
bool SkipNullCheck) {
498 if (Address->getType()->getPointerAddressSpace())
504 llvm::BasicBlock *Done =
nullptr;
508 if ((
SanOpts.
has(SanitizerKind::Null) || AllowNullPointers) &&
512 Address, llvm::Constant::getNullValue(Address->getType()));
514 if (AllowNullPointers) {
519 Builder.CreateCondBr(IsNonNull, Rest, Done);
522 Checks.push_back(std::make_pair(IsNonNull, SanitizerKind::Null));
539 llvm::ConstantInt::get(
IntPtrTy, Size));
540 Checks.push_back(std::make_pair(LargeEnough, SanitizerKind::ObjectSize));
543 uint64_t AlignVal = 0;
545 if (SanOpts.has(SanitizerKind::Alignment)) {
546 AlignVal = Alignment.getQuantity();
547 if (!Ty->isIncompleteType() && !AlignVal)
548 AlignVal = getContext().getTypeAlignInChars(Ty).getQuantity();
554 llvm::ConstantInt::get(IntPtrTy, AlignVal - 1));
556 Builder.CreateICmpEQ(Align, llvm::ConstantInt::get(IntPtrTy, 0));
557 Checks.push_back(std::make_pair(Aligned, SanitizerKind::Alignment));
561 if (Checks.size() > 0) {
562 llvm::Constant *StaticData[] = {
563 EmitCheckSourceLocation(Loc),
564 EmitCheckTypeDescriptor(Ty),
565 llvm::ConstantInt::get(SizeTy, AlignVal),
566 llvm::ConstantInt::get(Int8Ty, TCK)
568 EmitCheck(Checks,
"type_mismatch", StaticData, Address);
580 if (SanOpts.has(SanitizerKind::Vptr) &&
581 (TCK == TCK_MemberAccess || TCK == TCK_MemberCall ||
582 TCK == TCK_DowncastPointer || TCK == TCK_DowncastReference ||
583 TCK == TCK_UpcastToVirtualBase) &&
584 RD && RD->hasDefinition() && RD->isDynamicClass()) {
591 llvm::raw_svector_ostream Out(MangledName);
592 CGM.getCXXABI().getMangleContext().mangleCXXRTTI(Ty.getUnqualifiedType(),
596 if (!CGM.getContext().getSanitizerBlacklist().isBlacklistedType(
598 llvm::hash_code TypeHash = hash_value(Out.str());
601 llvm::Value *Low = llvm::ConstantInt::get(Int64Ty, TypeHash);
602 llvm::Type *VPtrTy = llvm::PointerType::get(IntPtrTy, 0);
608 Hash =
Builder.CreateTrunc(Hash, IntPtrTy);
611 const int CacheSize = 128;
612 llvm::Type *HashTable = llvm::ArrayType::get(IntPtrTy, CacheSize);
614 "__ubsan_vptr_type_cache");
616 llvm::ConstantInt::get(IntPtrTy,
627 llvm::Constant *StaticData[] = {
628 EmitCheckSourceLocation(Loc),
629 EmitCheckTypeDescriptor(Ty),
630 CGM.GetAddrOfRTTIDescriptor(Ty.getUnqualifiedType()),
631 llvm::ConstantInt::get(Int8Ty, TCK)
634 EmitCheck(std::make_pair(EqualHash, SanitizerKind::Vptr),
635 "dynamic_type_cache_miss", StaticData, DynamicData);
651 if (
const auto *CAT = dyn_cast<ConstantArrayType>(AT)) {
652 if (CAT->getSize().ugt(1))
654 }
else if (!isa<IncompleteArrayType>(AT))
660 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
663 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
666 return ++FI == FD->getParent()->field_end();
680 return CGF.
Builder.getInt32(VT->getNumElements());
685 if (
const auto *CE = dyn_cast<CastExpr>(Base)) {
688 IndexedType = CE->getSubExpr()->getType();
690 if (
const auto *CAT = dyn_cast<ConstantArrayType>(AT))
691 return CGF.
Builder.getInt(CAT->getSize());
692 else if (
const auto *VAT = dyn_cast<VariableArrayType>(AT))
703 assert(SanOpts.has(SanitizerKind::ArrayBounds) &&
704 "should not be called unless adding bounds checks");
716 llvm::Constant *StaticData[] = {
718 EmitCheckTypeDescriptor(IndexedType),
719 EmitCheckTypeDescriptor(IndexType)
722 :
Builder.CreateICmpULE(IndexVal, BoundVal);
723 EmitCheck(std::make_pair(Check, SanitizerKind::ArrayBounds),
"out_of_bounds",
730 bool isInc,
bool isPre) {
734 if (isa<llvm::IntegerType>(InVal.first->getType())) {
735 uint64_t AmountVal = isInc ? 1 : -1;
736 NextVal = llvm::ConstantInt::get(InVal.first->getType(), AmountVal,
true);
739 NextVal =
Builder.CreateAdd(InVal.first, NextVal, isInc ?
"inc" :
"dec");
742 llvm::APFloat FVal(getContext().getFloatTypeSemantics(ElemTy), 1);
745 NextVal = llvm::ConstantFP::get(getLLVMContext(), FVal);
748 NextVal =
Builder.CreateFAdd(InVal.first, NextVal, isInc ?
"inc" :
"dec");
754 EmitStoreOfComplex(IncVal, LV,
false);
758 return isPre ? IncVal : InVal;
767 return RValue::get(
nullptr);
769 switch (getEvaluationKind(Ty)) {
774 return RValue::getComplex(std::make_pair(U, U));
781 llvm::Value *DestPtr = CreateMemTemp(Ty,
"undef.agg.tmp");
782 return RValue::getAggregate(DestPtr);
786 return RValue::get(llvm::UndefValue::get(ConvertType(Ty)));
788 llvm_unreachable(
"bad evaluation kind");
793 ErrorUnsupported(E, Name);
794 return GetUndefRValue(E->
getType());
799 ErrorUnsupported(E, Name);
800 llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(E->
getType()));
801 return MakeAddrLValue(llvm::UndefValue::get(Ty), E->
getType());
806 if (SanOpts.has(SanitizerKind::ArrayBounds) && isa<ArraySubscriptExpr>(E))
807 LV = EmitArraySubscriptExpr(cast<ArraySubscriptExpr>(E),
true);
833 switch (E->getStmtClass()) {
834 default:
return EmitUnsupportedLValue(E,
"l-value expression");
836 case Expr::ObjCPropertyRefExprClass:
837 llvm_unreachable(
"cannot emit a property reference directly");
839 case Expr::ObjCSelectorExprClass:
840 return EmitObjCSelectorLValue(cast<ObjCSelectorExpr>(E));
841 case Expr::ObjCIsaExprClass:
842 return EmitObjCIsaExpr(cast<ObjCIsaExpr>(E));
843 case Expr::BinaryOperatorClass:
844 return EmitBinaryOperatorLValue(cast<BinaryOperator>(E));
845 case Expr::CompoundAssignOperatorClass: {
848 Ty = AT->getValueType();
850 return EmitCompoundAssignmentLValue(cast<CompoundAssignOperator>(E));
851 return EmitComplexCompoundAssignmentLValue(cast<CompoundAssignOperator>(E));
853 case Expr::CallExprClass:
854 case Expr::CXXMemberCallExprClass:
855 case Expr::CXXOperatorCallExprClass:
856 case Expr::UserDefinedLiteralClass:
857 return EmitCallExprLValue(cast<CallExpr>(E));
858 case Expr::VAArgExprClass:
859 return EmitVAArgExprLValue(cast<VAArgExpr>(E));
860 case Expr::DeclRefExprClass:
861 return EmitDeclRefLValue(cast<DeclRefExpr>(E));
862 case Expr::ParenExprClass:
863 return EmitLValue(cast<ParenExpr>(E)->getSubExpr());
864 case Expr::GenericSelectionExprClass:
865 return EmitLValue(cast<GenericSelectionExpr>(E)->getResultExpr());
866 case Expr::PredefinedExprClass:
867 return EmitPredefinedLValue(cast<PredefinedExpr>(E));
868 case Expr::StringLiteralClass:
869 return EmitStringLiteralLValue(cast<StringLiteral>(E));
870 case Expr::ObjCEncodeExprClass:
871 return EmitObjCEncodeExprLValue(cast<ObjCEncodeExpr>(E));
872 case Expr::PseudoObjectExprClass:
873 return EmitPseudoObjectLValue(cast<PseudoObjectExpr>(E));
874 case Expr::InitListExprClass:
875 return EmitInitListLValue(cast<InitListExpr>(E));
876 case Expr::CXXTemporaryObjectExprClass:
877 case Expr::CXXConstructExprClass:
878 return EmitCXXConstructLValue(cast<CXXConstructExpr>(E));
879 case Expr::CXXBindTemporaryExprClass:
880 return EmitCXXBindTemporaryLValue(cast<CXXBindTemporaryExpr>(E));
881 case Expr::CXXUuidofExprClass:
882 return EmitCXXUuidofLValue(cast<CXXUuidofExpr>(E));
883 case Expr::LambdaExprClass:
884 return EmitLambdaLValue(cast<LambdaExpr>(E));
886 case Expr::ExprWithCleanupsClass: {
887 const auto *cleanups = cast<ExprWithCleanups>(E);
888 enterFullExpression(cleanups);
890 return EmitLValue(cleanups->getSubExpr());
893 case Expr::CXXDefaultArgExprClass:
894 return EmitLValue(cast<CXXDefaultArgExpr>(E)->getExpr());
895 case Expr::CXXDefaultInitExprClass: {
897 return EmitLValue(cast<CXXDefaultInitExpr>(E)->getExpr());
899 case Expr::CXXTypeidExprClass:
900 return EmitCXXTypeidLValue(cast<CXXTypeidExpr>(E));
902 case Expr::ObjCMessageExprClass:
903 return EmitObjCMessageExprLValue(cast<ObjCMessageExpr>(E));
904 case Expr::ObjCIvarRefExprClass:
905 return EmitObjCIvarRefLValue(cast<ObjCIvarRefExpr>(E));
906 case Expr::StmtExprClass:
907 return EmitStmtExprLValue(cast<StmtExpr>(E));
908 case Expr::UnaryOperatorClass:
909 return EmitUnaryOpLValue(cast<UnaryOperator>(E));
910 case Expr::ArraySubscriptExprClass:
911 return EmitArraySubscriptExpr(cast<ArraySubscriptExpr>(E));
912 case Expr::ExtVectorElementExprClass:
913 return EmitExtVectorElementExpr(cast<ExtVectorElementExpr>(E));
914 case Expr::MemberExprClass:
915 return EmitMemberExpr(cast<MemberExpr>(E));
916 case Expr::CompoundLiteralExprClass:
917 return EmitCompoundLiteralLValue(cast<CompoundLiteralExpr>(E));
918 case Expr::ConditionalOperatorClass:
919 return EmitConditionalOperatorLValue(cast<ConditionalOperator>(E));
920 case Expr::BinaryConditionalOperatorClass:
921 return EmitConditionalOperatorLValue(cast<BinaryConditionalOperator>(E));
922 case Expr::ChooseExprClass:
923 return EmitLValue(cast<ChooseExpr>(E)->getChosenSubExpr());
924 case Expr::OpaqueValueExprClass:
925 return EmitOpaqueValueLValue(cast<OpaqueValueExpr>(E));
926 case Expr::SubstNonTypeTemplateParmExprClass:
927 return EmitLValue(cast<SubstNonTypeTemplateParmExpr>(E)->getReplacement());
928 case Expr::ImplicitCastExprClass:
929 case Expr::CStyleCastExprClass:
930 case Expr::CXXFunctionalCastExprClass:
931 case Expr::CXXStaticCastExprClass:
932 case Expr::CXXDynamicCastExprClass:
933 case Expr::CXXReinterpretCastExprClass:
934 case Expr::CXXConstCastExprClass:
935 case Expr::ObjCBridgedCastExprClass:
936 return EmitCastLValue(cast<CastExpr>(E));
938 case Expr::MaterializeTemporaryExprClass:
939 return EmitMaterializeTemporaryExpr(cast<MaterializeTemporaryExpr>(E));
951 if (!qs.hasConst() || qs.hasVolatile())
return false;
955 if (
const auto *RT = dyn_cast<RecordType>(type))
956 if (
const auto *RD = dyn_cast<CXXRecordDecl>(RT->getDecl()))
957 if (RD->hasMutableFields() || !RD->isTrivial())
978 if (
const auto *ref = dyn_cast<ReferenceType>(type)) {
999 if (isa<ParmVarDecl>(value)) {
1001 }
else if (
auto *var = dyn_cast<VarDecl>(value)) {
1003 }
else if (isa<EnumConstantDecl>(value)) {
1011 bool resultIsReference;
1017 resultIsReference =
false;
1018 resultType = refExpr->
getType();
1023 resultIsReference =
true;
1024 resultType = value->
getType();
1036 llvm::Constant *
C = CGM.EmitConstantValue(result.
Val, resultType,
this);
1040 if (isa<VarDecl>(value)) {
1041 if (!getContext().DeclMustBeEmitted(cast<VarDecl>(value)))
1042 EmitDeclRefExprDbgValue(refExpr, C);
1044 assert(isa<EnumConstantDecl>(value));
1045 EmitDeclRefExprDbgValue(refExpr, C);
1049 if (resultIsReference)
1050 return ConstantEmission::forReference(C);
1052 return ConstantEmission::forValue(C);
1068 return ET->getDecl()->getIntegerType()->isBooleanType();
1077 llvm::APInt &Min, llvm::APInt &
End,
1080 bool IsRegularCPlusPlusEnum = CGF.
getLangOpts().CPlusPlus && StrictEnums &&
1083 if (!IsBool && !IsRegularCPlusPlusEnum)
1092 unsigned Bitwidth = LTy->getScalarSizeInBits();
1096 if (NumNegativeBits) {
1097 unsigned NumBits = std::max(NumNegativeBits, NumPositiveBits + 1);
1098 assert(NumBits <= Bitwidth);
1099 End = llvm::APInt(Bitwidth, 1) << (NumBits - 1);
1102 assert(NumPositiveBits <= Bitwidth);
1103 End = llvm::APInt(Bitwidth, 1) << NumPositiveBits;
1104 Min = llvm::APInt(Bitwidth, 0);
1110 llvm::MDNode *CodeGenFunction::getRangeForLoadFromType(
QualType Ty) {
1111 llvm::APInt Min,
End;
1113 CGM.getCodeGenOpts().StrictEnums))
1116 llvm::MDBuilder MDHelper(getLLVMContext());
1117 return MDHelper.createRange(Min, End);
1123 llvm::MDNode *TBAAInfo,
1125 uint64_t TBAAOffset) {
1129 const llvm::Type *EltTy =
1132 const auto *VTy = cast<llvm::VectorType>(EltTy);
1135 if (VTy->getNumElements() == 3) {
1138 llvm::VectorType *vec4Ty = llvm::VectorType::get(VTy->getElementType(),
1140 llvm::PointerType *ptVec4Ty =
1141 llvm::PointerType::get(vec4Ty,
1142 (cast<llvm::PointerType>(
1143 Addr->getType()))->getAddressSpace());
1150 llvm::Constant *Mask[] = {
1151 llvm::ConstantInt::get(llvm::Type::getInt32Ty(getLLVMContext()), 0),
1152 llvm::ConstantInt::get(llvm::Type::getInt32Ty(getLLVMContext()), 1),
1153 llvm::ConstantInt::get(llvm::Type::getInt32Ty(getLLVMContext()), 2)
1156 llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
1157 V =
Builder.CreateShuffleVector(LoadVal,
1158 llvm::UndefValue::get(vec4Ty),
1159 MaskV,
"extractVec");
1160 return EmitFromMemory(V, Ty);
1165 if (Ty->
isAtomicType() || typeIsSuitableForInlineAtomic(Ty, Volatile)) {
1166 LValue lvalue = LValue::MakeAddr(Addr, Ty,
1168 getContext(), TBAAInfo);
1169 return EmitAtomicLoad(lvalue, Loc).getScalarVal();
1172 llvm::LoadInst *Load =
Builder.CreateLoad(Addr);
1174 Load->setVolatile(
true);
1176 Load->setAlignment(Alignment);
1178 llvm::MDNode *TBAAPath = CGM.getTBAAStructTagInfo(TBAABaseType, TBAAInfo,
1181 CGM.DecorateInstruction(Load, TBAAPath,
false);
1184 bool NeedsBoolCheck =
1186 bool NeedsEnumCheck =
1188 if (NeedsBoolCheck || NeedsEnumCheck) {
1190 llvm::APInt Min,
End;
1195 Check =
Builder.CreateICmpULE(
1196 Load, llvm::ConstantInt::get(getLLVMContext(), End));
1199 Load, llvm::ConstantInt::get(getLLVMContext(), End));
1201 Load, llvm::ConstantInt::get(getLLVMContext(), Min));
1202 Check =
Builder.CreateAnd(Upper, Lower);
1204 llvm::Constant *StaticArgs[] = {
1205 EmitCheckSourceLocation(Loc),
1206 EmitCheckTypeDescriptor(Ty)
1208 SanitizerMask Kind = NeedsEnumCheck ? SanitizerKind::Enum : SanitizerKind::Bool;
1209 EmitCheck(std::make_pair(Check, Kind),
"load_invalid_value", StaticArgs,
1210 EmitCheckValue(Load));
1212 }
else if (CGM.getCodeGenOpts().OptimizationLevel > 0)
1213 if (llvm::MDNode *RangeInfo = getRangeForLoadFromType(Ty))
1214 Load->setMetadata(llvm::LLVMContext::MD_range, RangeInfo);
1216 return EmitFromMemory(Load, Ty);
1224 if (Value->getType()->isIntegerTy(1))
1225 return Builder.CreateZExt(Value, ConvertTypeForMem(Ty),
"frombool");
1226 assert(Value->getType()->isIntegerTy(getContext().getTypeSize(Ty)) &&
1227 "wrong value rep of bool");
1236 assert(Value->getType()->isIntegerTy(getContext().getTypeSize(Ty)) &&
1237 "wrong value rep of bool");
1238 return Builder.CreateTrunc(Value,
Builder.getInt1Ty(),
"tobool");
1245 bool Volatile,
unsigned Alignment,
1246 QualType Ty, llvm::MDNode *TBAAInfo,
1247 bool isInit,
QualType TBAABaseType,
1248 uint64_t TBAAOffset) {
1252 llvm::Type *SrcTy = Value->getType();
1253 auto *VecTy = cast<llvm::VectorType>(SrcTy);
1255 if (VecTy->getNumElements() == 3) {
1256 llvm::LLVMContext &VMContext = getLLVMContext();
1260 Mask.push_back(llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
1262 Mask.push_back(llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
1264 Mask.push_back(llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
1266 Mask.push_back(llvm::UndefValue::get(llvm::Type::getInt32Ty(VMContext)));
1268 llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
1269 Value =
Builder.CreateShuffleVector(Value,
1270 llvm::UndefValue::get(VecTy),
1271 MaskV,
"extractVec");
1272 SrcTy = llvm::VectorType::get(VecTy->getElementType(), 4);
1274 auto *DstPtr = cast<llvm::PointerType>(Addr->getType());
1275 if (DstPtr->getElementType() != SrcTy) {
1277 llvm::PointerType::get(SrcTy, DstPtr->getAddressSpace());
1278 Addr =
Builder.CreateBitCast(Addr, MemTy,
"storetmp");
1282 Value = EmitToMemory(Value, Ty);
1285 (!isInit && typeIsSuitableForInlineAtomic(Ty, Volatile))) {
1286 EmitAtomicStore(RValue::get(Value),
1287 LValue::MakeAddr(Addr, Ty,
1289 getContext(), TBAAInfo),
1294 llvm::StoreInst *
Store =
Builder.CreateStore(Value, Addr, Volatile);
1296 Store->setAlignment(Alignment);
1298 llvm::MDNode *TBAAPath = CGM.getTBAAStructTagInfo(TBAABaseType, TBAAInfo,
1301 CGM.DecorateInstruction(Store, TBAAPath,
false);
1320 return RValue::get(CGM.getObjCRuntime().EmitObjCWeakRead(*
this,
1325 Object = EmitObjCConsumeObject(LV.
getType(), Object);
1326 return RValue::get(Object);
1333 return RValue::get(EmitLoadOfScalar(LV, Loc));
1347 return EmitLoadOfExtVectorElementLValue(LV);
1351 return EmitLoadOfGlobalRegLValue(LV);
1353 assert(LV.
isBitField() &&
"Unknown LValue type!");
1354 return EmitLoadOfBitfieldLValue(LV);
1362 llvm::Type *ResLTy = ConvertType(LV.
getType());
1373 Val =
Builder.CreateShl(Val, HighBits,
"bf.shl");
1374 if (Info.
Offset + HighBits)
1375 Val =
Builder.CreateAShr(Val, Info.
Offset + HighBits,
"bf.ashr");
1386 return RValue::get(Val);
1403 unsigned InIdx = getAccessedFieldNo(0, Elts);
1404 llvm::Value *Elt = llvm::ConstantInt::get(SizeTy, InIdx);
1405 return RValue::get(
Builder.CreateExtractElement(Vec, Elt));
1412 for (
unsigned i = 0; i != NumResultElts; ++i)
1413 Mask.push_back(
Builder.getInt32(getAccessedFieldNo(i, Elts)));
1415 llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
1416 Vec =
Builder.CreateShuffleVector(Vec, llvm::UndefValue::get(Vec->getType()),
1418 return RValue::get(Vec);
1426 llvm::Type *VectorElementTy = CGM.getTypes().ConvertType(EQT);
1427 llvm::Type *VectorElementPtrToTy = VectorElementTy->getPointerTo();
1430 Builder.CreateBitCast(VectorAddress,
1431 VectorElementPtrToTy,
"conv.ptr.element");
1434 unsigned ix = getAccessedFieldNo(0, Elts);
1437 Builder.CreateInBoundsGEP(CastToPointerElement,
1438 llvm::ConstantInt::get(SizeTy, ix),
"add.ptr");
1440 return VectorBasePtrPlusIx;
1446 "Bad type for register variable");
1447 llvm::MDNode *RegName = cast<llvm::MDNode>(
1448 cast<llvm::MetadataAsValue>(LV.
getGlobalReg())->getMetadata());
1451 llvm::Type *OrigTy = CGM.getTypes().ConvertType(LV.
getType());
1452 llvm::Type *Ty = OrigTy;
1453 if (OrigTy->isPointerTy())
1454 Ty = CGM.getTypes().getDataLayout().getIntPtrType(OrigTy);
1455 llvm::Type *Types[] = { Ty };
1457 llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::read_register, Types);
1459 F, llvm::MetadataAsValue::get(Ty->getContext(), RegName));
1460 if (OrigTy->isPointerTy())
1461 Call =
Builder.CreateIntToPtr(Call, OrigTy);
1462 return RValue::get(Call);
1489 return EmitStoreThroughExtVectorComponentLValue(Src, Dst);
1492 return EmitStoreThroughGlobalRegLValue(Src, Dst);
1494 assert(Dst.
isBitField() &&
"Unknown LValue type");
1495 return EmitStoreThroughBitfieldLValue(Src, Dst);
1502 llvm_unreachable(
"present but none");
1517 Src = RValue::get(EmitObjCExtendObjectLifetime(Dst.
getType(),
1528 CGM.getObjCRuntime().EmitObjCWeakAssign(*
this, src, LvalueDst);
1538 llvm::Type *ResultType = ConvertType(getContext().LongTy);
1541 RHS =
Builder.CreatePtrToInt(RHS, ResultType,
"sub.ptr.rhs.cast");
1543 Builder.CreatePtrToInt(LvalueDst, ResultType,
"sub.ptr.lhs.cast");
1545 CGM.getObjCRuntime().EmitObjCIvarAssign(*
this, src, dst,
1548 CGM.getObjCRuntime().EmitObjCGlobalAssign(*
this, src, LvalueDst,
1552 CGM.getObjCRuntime().EmitObjCStrongCastAssign(*
this, src, LvalueDst);
1556 assert(Src.
isScalar() &&
"Can't emit an agg store with this method");
1560 void CodeGenFunction::EmitStoreThroughBitfieldLValue(
RValue Src,
LValue Dst,
1564 llvm::Type *ResLTy = ConvertTypeForMem(Dst.
getType());
1571 SrcVal =
Builder.CreateIntCast(SrcVal,
1572 Ptr->getType()->getPointerElementType(),
1586 SrcVal =
Builder.CreateAnd(SrcVal,
1602 SrcVal =
Builder.CreateOr(Val, SrcVal,
"bf.set");
1604 assert(Info.
Offset == 0);
1620 ResultVal =
Builder.CreateShl(ResultVal, HighBits,
"bf.result.shl");
1621 ResultVal =
Builder.CreateAShr(ResultVal, HighBits,
"bf.result.ashr");
1627 *Result = EmitFromMemory(ResultVal, Dst.
getType());
1631 void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(
RValue Src,
1644 unsigned NumSrcElts = VTy->getNumElements();
1645 unsigned NumDstElts =
1646 cast<llvm::VectorType>(Vec->getType())->getNumElements();
1647 if (NumDstElts == NumSrcElts) {
1652 for (
unsigned i = 0; i != NumSrcElts; ++i)
1653 Mask[getAccessedFieldNo(i, Elts)] =
Builder.getInt32(i);
1655 llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
1656 Vec =
Builder.CreateShuffleVector(SrcVal,
1657 llvm::UndefValue::get(Vec->getType()),
1659 }
else if (NumDstElts > NumSrcElts) {
1665 for (
unsigned i = 0; i != NumSrcElts; ++i)
1666 ExtMask.push_back(
Builder.getInt32(i));
1667 ExtMask.resize(NumDstElts, llvm::UndefValue::get(Int32Ty));
1668 llvm::Value *ExtMaskV = llvm::ConstantVector::get(ExtMask);
1670 Builder.CreateShuffleVector(SrcVal,
1671 llvm::UndefValue::get(SrcVal->getType()),
1675 for (
unsigned i = 0; i != NumDstElts; ++i)
1676 Mask.push_back(
Builder.getInt32(i));
1681 if (getAccessedFieldNo(NumSrcElts - 1, Elts) == Mask.size())
1685 for (
unsigned i = 0; i != NumSrcElts; ++i)
1686 Mask[getAccessedFieldNo(i, Elts)] =
Builder.getInt32(i+NumDstElts);
1687 llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
1688 Vec =
Builder.CreateShuffleVector(Vec, ExtSrcVal, MaskV);
1691 llvm_unreachable(
"unexpected shorten vector length");
1695 unsigned InIdx = getAccessedFieldNo(0, Elts);
1696 llvm::Value *Elt = llvm::ConstantInt::get(SizeTy, InIdx);
1697 Vec =
Builder.CreateInsertElement(Vec, SrcVal, Elt);
1706 void CodeGenFunction::EmitStoreThroughGlobalRegLValue(
RValue Src,
LValue Dst) {
1708 "Bad type for register variable");
1709 llvm::MDNode *RegName = cast<llvm::MDNode>(
1710 cast<llvm::MetadataAsValue>(Dst.
getGlobalReg())->getMetadata());
1711 assert(RegName &&
"Register LValue is not metadata");
1714 llvm::Type *OrigTy = CGM.getTypes().ConvertType(Dst.
getType());
1715 llvm::Type *Ty = OrigTy;
1716 if (OrigTy->isPointerTy())
1717 Ty = CGM.getTypes().getDataLayout().getIntPtrType(OrigTy);
1718 llvm::Type *Types[] = { Ty };
1720 llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::write_register, Types);
1722 if (OrigTy->isPointerTy())
1723 Value =
Builder.CreatePtrToInt(Value, Ty);
1725 F, {llvm::MetadataAsValue::get(Ty->getContext(), RegName), Value});
1733 bool IsMemberAccess=
false) {
1737 if (isa<ObjCIvarRefExpr>(E)) {
1750 auto *Exp = cast<ObjCIvarRefExpr>(
const_cast<Expr *
>(E));
1756 if (
const auto *Exp = dyn_cast<DeclRefExpr>(E)) {
1757 if (
const auto *VD = dyn_cast<VarDecl>(Exp->getDecl())) {
1758 if (VD->hasGlobalStorage()) {
1767 if (
const auto *Exp = dyn_cast<UnaryOperator>(E)) {
1772 if (
const auto *Exp = dyn_cast<ParenExpr>(E)) {
1786 if (
const auto *Exp = dyn_cast<GenericSelectionExpr>(E)) {
1791 if (
const auto *Exp = dyn_cast<ImplicitCastExpr>(E)) {
1796 if (
const auto *Exp = dyn_cast<CStyleCastExpr>(E)) {
1801 if (
const auto *Exp = dyn_cast<ObjCBridgedCastExpr>(E)) {
1806 if (
const auto *Exp = dyn_cast<ArraySubscriptExpr>(E)) {
1819 if (
const auto *Exp = dyn_cast<MemberExpr>(E)) {
1831 StringRef Name = StringRef()) {
1832 unsigned AS = cast<llvm::PointerType>(V->getType())->getAddressSpace();
1833 return CGF.
Builder.CreateBitCast(V, IRType->getPointerTo(AS), Name);
1864 llvm::LoadInst *LI = CGF.
Builder.CreateLoad(V);
1911 AsmLabelAttr *Asm = VD->
getAttr<AsmLabelAttr>();
1912 assert(Asm->getLabel().size() < 64-Name.size() &&
1913 "Register name too big");
1914 Name.append(Asm->getLabel());
1915 llvm::NamedMDNode *M =
1916 CGM.
getModule().getOrInsertNamedMetadata(Name);
1917 if (M->getNumOperands() == 0) {
1920 llvm::Metadata *Ops[] = {Str};
1923 return LValue::MakeGlobalReg(
1924 llvm::MetadataAsValue::get(CGM.
getLLVMContext(), M->getOperand(0)),
1930 CharUnits Alignment = getContext().getDeclAlign(ND);
1933 if (
const auto *VD = dyn_cast<VarDecl>(ND)) {
1936 VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())
1941 const Expr *Init = VD->getAnyInitializer(VD);
1943 VD->isUsableInConstantExpressions(getContext()) &&
1944 VD->checkInitIsICE()) {
1945 llvm::Constant *Val =
1946 CGM.EmitConstantValue(*VD->evaluateValue(), VD->getType(),
this);
1947 assert(Val &&
"failed to emit reference constant expression");
1949 return MakeAddrLValue(Val, T, Alignment);
1954 if (
auto *FD = LambdaCaptureFields.lookup(VD))
1956 else if (CapturedStmtInfo) {
1957 if (
auto *V = LocalDeclMap.lookup(VD))
1958 return MakeAddrLValue(V, T, Alignment);
1961 CapturedStmtInfo->getContextValue());
1963 assert(isa<BlockDecl>(CurCodeDecl));
1964 return MakeAddrLValue(GetAddrOfBlockDecl(VD, VD->hasAttr<BlocksAttr>()),
1972 assert((ND->
isUsed(
false) || !isa<VarDecl>(ND) ||
1974 "Should not use decl without marking it used!");
1976 if (ND->
hasAttr<WeakRefAttr>()) {
1977 const auto *VD = cast<ValueDecl>(ND);
1978 llvm::Constant *Aliasee = CGM.GetWeakRefReference(VD);
1979 return MakeAddrLValue(Aliasee, T, Alignment);
1982 if (
const auto *VD = dyn_cast<VarDecl>(ND)) {
1984 if (VD->hasLinkage() || VD->isStaticDataMember())
1987 bool isBlockVariable = VD->hasAttr<BlocksAttr>();
1990 if (!V && VD->isStaticLocal())
1991 V = CGM.getOrCreateStaticVarDecl(
1992 *VD, CGM.getLLVMLinkageVarDefinition(VD,
false));
1995 if (V && getLangOpts().OpenMP && VD->hasAttr<OMPThreadPrivateDeclAttr>())
1997 *
this, VD, T, V, getTypes().ConvertTypeForMem(VD->getType()),
2000 assert(V &&
"DeclRefExpr not entered in LocalDeclMap?");
2002 if (isBlockVariable)
2003 V = BuildBlockByrefAddress(V, VD);
2006 if (VD->getType()->isReferenceType()) {
2007 llvm::LoadInst *LI =
Builder.CreateLoad(V);
2010 LV = MakeNaturalAlignAddrLValue(V, T);
2012 LV = MakeAddrLValue(V, T, Alignment);
2015 bool isLocalStorage = VD->hasLocalStorage();
2017 bool NonGCable = isLocalStorage &&
2018 !VD->getType()->isReferenceType() &&
2025 bool isImpreciseLifetime =
2026 (isLocalStorage && !VD->hasAttr<ObjCPreciseLifetimeAttr>());
2027 if (isImpreciseLifetime)
2033 if (
const auto *FD = dyn_cast<FunctionDecl>(ND))
2036 llvm_unreachable(
"Unhandled DeclRefExpr");
2046 default: llvm_unreachable(
"Unknown unary operator lvalue!");
2049 assert(!T.
isNull() &&
"CodeGenFunction::EmitUnaryOpLValue: Illegal type");
2051 LValue LV = MakeNaturalAlignAddrLValue(EmitScalarExpr(E->
getSubExpr()), T);
2058 if (getLangOpts().ObjC1 &&
2067 assert(LV.
isSimple() &&
"real/imag on non-ordinary l-value");
2073 !cast<llvm::PointerType>(Addr->getType())
2082 return MakeAddrLValue(
2091 EmitComplexPrePostIncDec(E, LV, isInc,
true);
2093 EmitScalarPrePostIncDec(E, LV, isInc,
true);
2100 return MakeAddrLValue(CGM.GetAddrOfConstantStringFromLiteral(E),
2105 return MakeAddrLValue(CGM.GetAddrOfConstantStringFromObjCEncode(E),
2111 assert(SL !=
nullptr &&
"No StringLiteral name in PredefinedExpr");
2112 StringRef FnName = CurFn->getName();
2113 if (FnName.startswith(
"\01"))
2114 FnName = FnName.substr(1);
2115 StringRef NameItems[] = {
2117 std::string GVName = llvm::join(NameItems, NameItems + 2,
".");
2118 if (CurCodeDecl && isa<BlockDecl>(CurCodeDecl)) {
2119 auto C = CGM.GetAddrOfConstantCString(FnName, GVName.c_str(), 1);
2120 return MakeAddrLValue(
C, E->
getType());
2122 auto C = CGM.GetAddrOfConstantStringFromLiteral(SL, GVName);
2123 return MakeAddrLValue(
C, E->
getType());
2135 llvm::Constant *CodeGenFunction::EmitCheckTypeDescriptor(
QualType T) {
2137 if (llvm::Constant *
C = CGM.getTypeDescriptorFromMap(T))
2140 uint16_t TypeKind = -1;
2145 TypeInfo = (llvm::Log2_32(getContext().getTypeSize(T)) << 1) |
2149 TypeInfo = getContext().getTypeSize(T);
2157 StringRef(), StringRef(),
None, Buffer,
2160 llvm::Constant *Components[] = {
2162 llvm::ConstantDataArray::getString(getLLVMContext(), Buffer)
2164 llvm::Constant *Descriptor = llvm::ConstantStruct::getAnon(Components);
2166 auto *GV =
new llvm::GlobalVariable(
2167 CGM.getModule(), Descriptor->getType(),
2168 true, llvm::GlobalVariable::PrivateLinkage, Descriptor);
2169 GV->setUnnamedAddr(
true);
2170 CGM.getSanitizerMetadata()->disableSanitizerForGlobal(GV);
2173 CGM.setTypeDescriptorInMap(T, GV);
2179 llvm::Type *TargetTy = IntPtrTy;
2183 if (V->getType()->isFloatingPointTy()) {
2184 unsigned Bits = V->getType()->getPrimitiveSizeInBits();
2185 if (Bits <= TargetTy->getIntegerBitWidth())
2186 V =
Builder.CreateBitCast(V, llvm::Type::getIntNTy(getLLVMContext(),
2191 if (V->getType()->isIntegerTy() &&
2192 V->getType()->getIntegerBitWidth() <= TargetTy->getIntegerBitWidth())
2193 return Builder.CreateZExt(V, TargetTy);
2196 if (!V->getType()->isPointerTy()) {
2197 llvm::Value *Ptr = CreateTempAlloca(V->getType());
2201 return Builder.CreatePtrToInt(V, TargetTy);
2214 llvm::Constant *Filename;
2217 PresumedLoc PLoc = getContext().getSourceManager().getPresumedLoc(Loc);
2219 auto FilenameGV = CGM.GetAddrOfConstantCString(PLoc.
getFilename(),
".src");
2220 CGM.getSanitizerMetadata()->disableSanitizerForGlobal(FilenameGV);
2221 Filename = FilenameGV;
2225 Filename = llvm::Constant::getNullValue(Int8PtrTy);
2229 llvm::Constant *Data[] = {Filename,
Builder.getInt32(Line),
2232 return llvm::ConstantStruct::getAnon(Data);
2249 assert(llvm::countPopulation(Kind) == 1);
2251 case SanitizerKind::Vptr:
2252 return CheckRecoverableKind::AlwaysRecoverable;
2253 case SanitizerKind::Return:
2254 case SanitizerKind::Unreachable:
2257 return CheckRecoverableKind::Recoverable;
2262 llvm::FunctionType *FnType,
2264 StringRef CheckName,
2266 llvm::BasicBlock *ContBB) {
2268 bool NeedsAbortSuffix =
2270 std::string FnName = (
"__ubsan_handle_" + CheckName +
2271 (NeedsAbortSuffix ?
"_abort" :
"")).str();
2273 !IsFatal || RecoverKind == CheckRecoverableKind::AlwaysRecoverable;
2275 llvm::AttrBuilder B;
2277 B.addAttribute(llvm::Attribute::NoReturn)
2278 .addAttribute(llvm::Attribute::NoUnwind);
2280 B.addAttribute(llvm::Attribute::UWTable);
2285 llvm::AttributeSet::FunctionIndex, B));
2288 HandlerCall->setDoesNotReturn();
2289 CGF.
Builder.CreateUnreachable();
2295 void CodeGenFunction::EmitCheck(
2296 ArrayRef<std::pair<llvm::Value *, SanitizerMask>> Checked,
2299 assert(IsSanitizerScope);
2300 assert(Checked.size() > 0);
2305 for (
int i = 0, n = Checked.size(); i < n; ++i) {
2309 CGM.getCodeGenOpts().SanitizeTrap.has(Checked[i].second)
2311 : CGM.getCodeGenOpts().SanitizeRecover.has(Checked[i].second)
2314 Cond = Cond ?
Builder.CreateAnd(Cond, Check) : Check;
2318 EmitTrapCheck(TrapCond);
2319 if (!FatalCond && !RecoverableCond)
2323 if (FatalCond && RecoverableCond)
2324 JointCond =
Builder.CreateAnd(FatalCond, RecoverableCond);
2326 JointCond = FatalCond ? FatalCond : RecoverableCond;
2330 assert(SanOpts.has(Checked[0].second));
2332 for (
int i = 1, n = Checked.size(); i < n; ++i) {
2334 "All recoverable kinds in a single check must be same!");
2335 assert(SanOpts.has(Checked[i].second));
2339 llvm::BasicBlock *Cont = createBasicBlock(
"cont");
2340 llvm::BasicBlock *Handlers = createBasicBlock(
"handler." + CheckName);
2341 llvm::Instruction *Branch =
Builder.CreateCondBr(JointCond, Cont, Handlers);
2344 llvm::MDBuilder MDHelper(getLLVMContext());
2345 llvm::MDNode *
Node = MDHelper.createBranchWeights((1U << 20) - 1, 1);
2346 Branch->setMetadata(llvm::LLVMContext::MD_prof, Node);
2347 EmitBlock(Handlers);
2350 llvm::Constant *Info = llvm::ConstantStruct::getAnon(StaticArgs);
2352 new llvm::GlobalVariable(CGM.getModule(), Info->getType(),
false,
2353 llvm::GlobalVariable::PrivateLinkage, Info);
2354 InfoPtr->setUnnamedAddr(
true);
2355 CGM.getSanitizerMetadata()->disableSanitizerForGlobal(InfoPtr);
2359 Args.reserve(DynamicArgs.size() + 1);
2360 ArgTypes.reserve(DynamicArgs.size() + 1);
2365 Args.push_back(
Builder.CreateBitCast(InfoPtr, Int8PtrTy));
2366 ArgTypes.push_back(Int8PtrTy);
2367 for (
size_t i = 0, n = DynamicArgs.size(); i != n; ++i) {
2368 Args.push_back(EmitCheckValue(DynamicArgs[i]));
2369 ArgTypes.push_back(IntPtrTy);
2372 llvm::FunctionType *FnType =
2373 llvm::FunctionType::get(CGM.VoidTy, ArgTypes,
false);
2375 if (!FatalCond || !RecoverableCond) {
2379 (FatalCond !=
nullptr), Cont);
2383 llvm::BasicBlock *NonFatalHandlerBB =
2384 createBasicBlock(
"non_fatal." + CheckName);
2385 llvm::BasicBlock *FatalHandlerBB = createBasicBlock(
"fatal." + CheckName);
2386 Builder.CreateCondBr(FatalCond, NonFatalHandlerBB, FatalHandlerBB);
2387 EmitBlock(FatalHandlerBB);
2390 EmitBlock(NonFatalHandlerBB);
2399 llvm::BasicBlock *Cont = createBasicBlock(
"cont");
2403 if (!CGM.getCodeGenOpts().OptimizationLevel || !TrapBB) {
2404 TrapBB = createBasicBlock(
"trap");
2405 Builder.CreateCondBr(Checked, Cont, TrapBB);
2407 llvm::CallInst *TrapCall = EmitTrapCall(llvm::Intrinsic::trap);
2408 TrapCall->setDoesNotReturn();
2409 TrapCall->setDoesNotThrow();
2412 Builder.CreateCondBr(Checked, Cont, TrapBB);
2419 llvm::CallInst *TrapCall =
Builder.CreateCall(CGM.getIntrinsic(IntrID));
2421 if (!CGM.getCodeGenOpts().TrapFuncName.empty())
2422 TrapCall->addAttribute(llvm::AttributeSet::FunctionIndex,
2424 CGM.getCodeGenOpts().TrapFuncName);
2433 const auto *CE = dyn_cast<
CastExpr>(E);
2438 const Expr *SubExpr = CE->getSubExpr();
2452 if (SanOpts.has(SanitizerKind::ArrayBounds))
2453 EmitBoundsCheck(E, E->
getBase(), Idx, IdxTy, Accessed);
2458 !isa<ExtVectorElementExpr>(E->
getBase())) {
2461 assert(LHS.
isSimple() &&
"Can only subscript lvalue vectors here!");
2462 return LValue::MakeVectorElt(LHS.
getAddress(), Idx,
2467 if (Idx->getType() != IntPtrTy)
2468 Idx =
Builder.CreateIntCast(Idx, IntPtrTy, IdxSigned,
"idxprom");
2474 if (isa<ExtVectorElementExpr>(E->
getBase())) {
2476 Address = EmitExtVectorElementLValue(LV);
2477 Address =
Builder.CreateInBoundsGEP(Address, Idx,
"arrayidx");
2480 return MakeAddrLValue(Address, EQT,
2481 getContext().getTypeAlignInChars(EQT));
2484 getContext().getAsVariableArrayType(E->
getType())) {
2488 Address = EmitScalarExpr(E->
getBase());
2497 if (getLangOpts().isSignedOverflowDefined()) {
2498 Idx =
Builder.CreateMul(Idx, numElements);
2499 Address =
Builder.CreateGEP(Address, Idx,
"arrayidx");
2501 Idx =
Builder.CreateNSWMul(Idx, numElements);
2502 Address =
Builder.CreateInBoundsGEP(Address, Idx,
"arrayidx");
2507 llvm::ConstantInt::get(Idx->getType(),
2508 getContext().getTypeSizeInChars(OIT).getQuantity());
2510 Idx =
Builder.CreateMul(Idx, InterfaceSize);
2514 Address = EmitCastToVoidPtr(Base);
2515 Address =
Builder.CreateGEP(Address, Idx,
"arrayidx");
2516 Address =
Builder.CreateBitCast(Address, Base->getType());
2522 assert(Array->getType()->isArrayType() &&
2523 "Array to pointer decay must have array source type!");
2527 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(Array))
2528 ArrayLV = EmitArraySubscriptExpr(ASE,
true);
2530 ArrayLV = EmitLValue(Array);
2532 llvm::Value *Zero = llvm::ConstantInt::get(Int32Ty, 0);
2536 ArrayAlignment = ArrayLV.getAlignment();
2538 if (getLangOpts().isSignedOverflowDefined())
2539 Address =
Builder.CreateGEP(ArrayPtr, Args,
"arrayidx");
2541 Address =
Builder.CreateInBoundsGEP(ArrayPtr, Args,
"arrayidx");
2545 if (getLangOpts().isSignedOverflowDefined())
2546 Address =
Builder.CreateGEP(Base, Idx,
"arrayidx");
2548 Address =
Builder.CreateInBoundsGEP(Base, Idx,
"arrayidx");
2553 "CodeGenFunction::EmitArraySubscriptExpr(): Illegal base type");
2558 if (!ArrayAlignment.
isZero()) {
2559 CharUnits Align = getContext().getTypeAlignInChars(T);
2560 ArrayAlignment = std::min(Align, ArrayAlignment);
2561 LV = MakeAddrLValue(Address, T, ArrayAlignment);
2563 LV = MakeNaturalAlignAddrLValue(Address, T);
2568 if (getLangOpts().ObjC1 &&
2580 for (
unsigned i = 0, e = Elts.size(); i != e; ++i)
2581 CElts.push_back(Builder.getInt32(Elts[i]));
2583 return llvm::ConstantVector::get(CElts);
2597 Base = MakeAddrLValue(Ptr, PT->getPointeeType());
2598 Base.getQuals().removeObjCGCAttr();
2603 Base = EmitLValue(E->
getBase());
2607 "Result must be a vector");
2612 Builder.CreateStore(Vec, VecMem);
2628 assert(Base.
isExtVectorElt() &&
"Can only subscript lvalue vec elts here!");
2633 for (
unsigned i = 0, e = Indices.size(); i != e; ++i)
2634 CElts.push_back(BaseElts->getAggregateElement(Indices[i]));
2635 llvm::Constant *CV = llvm::ConstantVector::get(CElts);
2648 EmitTypeCheck(TCK_MemberAccess, E->
getExprLoc(), Ptr, PtrTy);
2649 BaseLV = MakeNaturalAlignAddrLValue(Ptr, PtrTy);
2651 BaseLV = EmitCheckedLValue(BaseExpr, TCK_MemberAccess);
2654 if (
auto *Field = dyn_cast<FieldDecl>(ND)) {
2655 LValue LV = EmitLValueForField(BaseLV, Field);
2660 if (
auto *VD = dyn_cast<VarDecl>(ND))
2663 if (
const auto *FD = dyn_cast<FunctionDecl>(ND))
2666 llvm_unreachable(
"Unhandled member declaration!");
2672 assert(cast<CXXMethodDecl>(CurCodeDecl)->getParent()->isLambda());
2673 assert(cast<CXXMethodDecl>(CurCodeDecl)->getParent() == Field->
getParent());
2675 getContext().getTagDeclType(Field->
getParent());
2676 LValue LambdaLV = MakeNaturalAlignAddrLValue(CXXABIThisValue, LambdaTagType);
2677 return EmitLValueForField(LambdaLV, Field);
2684 CGM.getTypes().getCGRecordLayout(field->
getParent());
2690 Addr =
Builder.CreateStructGEP(
nullptr, Addr, Idx, field->
getName());
2692 llvm::Type *PtrTy = llvm::Type::getIntNPtrTy(
2694 CGM.getContext().getTargetAddressSpace(base.
getType()));
2695 if (Addr->getType() != PtrTy)
2696 Addr =
Builder.CreateBitCast(Addr, PtrTy);
2700 return LValue::MakeBitfield(Addr, Info, fieldType, base.
getAlignment());
2705 CharUnits alignment = getContext().getDeclAlign(field);
2712 bool mayAlias = rec->
hasAttr<MayAliasAttr>();
2716 bool TBAAPath = CGM.getCodeGenOpts().StructPathTBAA;
2724 unsigned idx = CGM.getTypes().getCGRecordLayout(rec).getLLVMFieldNo(field);
2725 addr =
Builder.CreateStructGEP(
nullptr, addr, idx, field->
getName());
2729 llvm::LoadInst *load =
Builder.CreateLoad(addr,
"ref");
2735 if (CGM.shouldUseTBAA()) {
2738 tbaa = CGM.getTBAAInfo(getContext().CharTy);
2740 tbaa = CGM.getTBAAInfo(type);
2742 CGM.DecorateInstruction(load, tbaa);
2751 alignment = getContext().getTypeAlignInChars(type);
2761 CGM.getTypes().ConvertTypeForMem(type),
2764 if (field->
hasAttr<AnnotateAttr>())
2765 addr = EmitFieldAnnotations(field, addr);
2767 LValue LV = MakeAddrLValue(addr, type, alignment);
2771 getContext().getASTRecordLayout(field->
getParent());
2777 getContext().getCharWidth());
2788 LV.
setTBAAInfo(CGM.getTBAAInfo(getContext().CharTy));
2799 return EmitLValueForField(Base, Field);
2802 CGM.getTypes().getCGRecordLayout(Field->
getParent());
2805 assert(!FieldType.
getObjCGCAttr() &&
"fields cannot have GC attrs");
2811 llvm::Type *llvmType = ConvertTypeForMem(FieldType);
2814 CharUnits Alignment = getContext().getDeclAlign(Field);
2821 return MakeAddrLValue(V, FieldType, Alignment);
2826 llvm::Value *GlobalPtr = CGM.GetAddrOfConstantCompoundLiteral(E);
2827 return MakeAddrLValue(GlobalPtr, E->
getType());
2831 EmitVariablyModifiedType(E->
getType());
2846 return EmitAggExprToLValue(E);
2849 assert(E->
getNumInits() == 1 &&
"reference init with multiple values");
2850 return EmitLValue(E->
getInit(0));
2857 const Expr *Operand) {
2858 if (
auto *ThrowExpr = dyn_cast<CXXThrowExpr>(Operand->
IgnoreParens())) {
2870 assert(hasAggregateEvaluationKind(expr->
getType()) &&
2871 "Unexpected conditional operator!");
2872 return EmitAggExprToLValue(expr);
2879 if (ConstantFoldsToSimpleInteger(condExpr, CondExprBool)) {
2881 if (!CondExprBool) std::swap(live, dead);
2883 if (!ContainsLabel(dead)) {
2886 incrementProfileCounter(expr);
2887 return EmitLValue(live);
2891 llvm::BasicBlock *lhsBlock = createBasicBlock(
"cond.true");
2892 llvm::BasicBlock *rhsBlock = createBasicBlock(
"cond.false");
2893 llvm::BasicBlock *contBlock = createBasicBlock(
"cond.end");
2896 EmitBranchOnBoolExpr(condExpr, lhsBlock, rhsBlock, getProfileCount(expr));
2899 EmitBlock(lhsBlock);
2900 incrementProfileCounter(expr);
2906 if (lhs && !lhs->isSimple())
2907 return EmitUnsupportedLValue(expr,
"conditional operator");
2909 lhsBlock =
Builder.GetInsertBlock();
2914 EmitBlock(rhsBlock);
2919 if (rhs && !rhs->isSimple())
2920 return EmitUnsupportedLValue(expr,
"conditional operator");
2921 rhsBlock =
Builder.GetInsertBlock();
2923 EmitBlock(contBlock);
2926 llvm::PHINode *phi =
Builder.CreatePHI(lhs->getAddress()->getType(),
2928 phi->addIncoming(lhs->getAddress(), lhsBlock);
2929 phi->addIncoming(rhs->getAddress(), rhsBlock);
2930 return MakeAddrLValue(phi, expr->
getType());
2932 assert((lhs || rhs) &&
2933 "both operands of glvalue conditional are throw-expressions?");
2934 return lhs ? *lhs : *rhs;
2984 return EmitUnsupportedLValue(E,
"unexpected cast lvalue");
2987 llvm_unreachable(
"dependent cast kind in IR gen!");
2990 llvm_unreachable(
"builtin functions are handled elsewhere");
2995 return EmitAggExprToLValue(E);
3000 const auto *DCE = cast<CXXDynamicCastExpr>(E);
3001 return MakeAddrLValue(EmitDynamicCast(V, DCE), E->
getType());
3016 auto *DerivedClassDecl = cast<CXXRecordDecl>(DerivedClassTy->
getDecl());
3026 return MakeAddrLValue(Base, E->
getType());
3029 return EmitAggExprToLValue(E);
3032 auto *DerivedClassDecl = cast<CXXRecordDecl>(DerivedClassTy->
getDecl());
3038 GetAddressOfDerivedClass(LV.getAddress(), DerivedClassDecl,
3044 if (sanitizePerformTypeCheck())
3045 EmitTypeCheck(TCK_DowncastReference, E->
getExprLoc(),
3048 if (SanOpts.has(SanitizerKind::CFIDerivedCast))
3049 EmitVTablePtrCheckForCast(E->
getType(), Derived,
false,
3050 CFITCK_DerivedCast, E->getLocStart());
3052 return MakeAddrLValue(Derived, E->
getType());
3056 const auto *CE = cast<ExplicitCastExpr>(E);
3060 ConvertType(CE->getTypeAsWritten()));
3062 if (SanOpts.has(SanitizerKind::CFIUnrelatedCast))
3063 EmitVTablePtrCheckForCast(E->
getType(), V,
false,
3064 CFITCK_UnrelatedCast, E->getLocStart());
3066 return MakeAddrLValue(V, E->
getType());
3072 ConvertType(ToType));
3073 return MakeAddrLValue(V, E->
getType());
3076 llvm_unreachable(
"NULL to OpenCL event lvalue cast is not valid");
3079 llvm_unreachable(
"Unhandled lvalue cast kind?");
3083 assert(OpaqueValueMappingData::shouldBindAsLValue(e));
3084 return getOpaqueLValueMapping(e);
3091 LValue FieldLV = EmitLValueForField(LV, FD);
3092 switch (getEvaluationKind(FT)) {
3094 return RValue::getComplex(EmitLoadOfComplex(FieldLV, Loc));
3098 return EmitLoadOfLValue(FieldLV, Loc);
3100 llvm_unreachable(
"bad evaluation kind");
3111 return EmitBlockCallExpr(E, ReturnValue);
3113 if (
const auto *CE = dyn_cast<CXXMemberCallExpr>(E))
3114 return EmitCXXMemberCallExpr(CE, ReturnValue);
3116 if (
const auto *CE = dyn_cast<CUDAKernelCallExpr>(E))
3117 return EmitCUDAKernelCallExpr(CE, ReturnValue);
3120 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl)) {
3121 if (
unsigned builtinID = FD->getBuiltinID())
3122 return EmitBuiltinExpr(FD, builtinID, E, ReturnValue);
3125 if (
const auto *CE = dyn_cast<CXXOperatorCallExpr>(E))
3126 if (
const CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>(TargetDecl))
3127 return EmitCXXOperatorMemberCallExpr(CE, MD, ReturnValue);
3129 if (
const auto *PseudoDtor =
3131 QualType DestroyedType = PseudoDtor->getDestroyedType();
3132 if (getLangOpts().ObjCAutoRefCount &&
3139 Expr *BaseExpr = PseudoDtor->getBase();
3144 if (PseudoDtor->isArrow()) {
3145 BaseValue = EmitScalarExpr(BaseExpr);
3149 LValue BaseLV = EmitLValue(BaseExpr);
3155 switch (PseudoDtor->getDestroyedType().getObjCLifetime()) {
3162 EmitARCRelease(
Builder.CreateLoad(BaseValue,
3163 PseudoDtor->getDestroyedType().isVolatileQualified()),
3168 EmitARCDestroyWeak(BaseValue);
3180 return RValue::get(
nullptr);
3191 EmitIgnoredExpr(E->
getLHS());
3192 EnsureInsertPoint();
3193 return EmitLValue(E->
getRHS());
3198 return EmitPointerToDataMemberBinaryExpr(E);
3205 switch (getEvaluationKind(E->
getType())) {
3209 return EmitARCStoreStrong(E,
false).first;
3212 return EmitARCStoreAutoreleasing(E).first;
3223 EmitStoreThroughLValue(RV, LV);
3228 return EmitComplexAssignmentLValue(E);
3231 return EmitAggExprToLValue(E);
3233 llvm_unreachable(
"bad evaluation kind");
3237 RValue RV = EmitCallExpr(E);
3243 "Can't have a scalar return unless the return type is a "
3251 return EmitAggExprToLValue(E);
3256 &&
"binding l-value to type which needs a temporary");
3258 EmitCXXConstructExpr(E, Slot);
3259 return MakeAddrLValue(Slot.getAddr(), E->
getType());
3264 return MakeAddrLValue(EmitCXXTypeidExpr(E), E->
getType());
3268 return Builder.CreateBitCast(CGM.GetAddrOfUuidDescriptor(E),
3269 ConvertType(E->
getType())->getPointerTo());
3273 return MakeAddrLValue(EmitCXXUuidofExpr(E), E->
getType());
3288 EmitLambdaExpr(E, Slot);
3293 RValue RV = EmitObjCMessageExpr(E);
3299 "Can't have a scalar return unless the return type is a "
3307 CGM.getObjCRuntime().GetSelector(*
this, E->
getSelector(),
true);
3308 return MakeAddrLValue(V, E->
getType());
3313 return CGM.getObjCRuntime().EmitIvarOffset(*
this, Interface, Ivar);
3319 unsigned CVRQualifiers) {
3320 return CGM.getObjCRuntime().EmitObjCValueForIvar(*
this, ObjectTy, BaseValue,
3321 Ivar, CVRQualifiers);
3331 BaseValue = EmitScalarExpr(BaseExpr);
3335 LValue BaseLV = EmitLValue(BaseExpr);
3338 ObjectTy = BaseExpr->
getType();
3343 EmitLValueForIvar(ObjectTy, BaseValue, E->
getDecl(),
3351 RValue RV = EmitAnyExprToTemp(E);
3361 "Call must have function pointer type!");
3365 const auto *FnType =
3366 cast<FunctionType>(cast<PointerType>(CalleeType)->getPointeeType());
3368 if (getLangOpts().CPlusPlus && SanOpts.has(SanitizerKind::Function) &&
3369 (!TargetDecl || !isa<FunctionDecl>(TargetDecl))) {
3370 if (llvm::Constant *PrefixSig =
3371 CGM.getTargetCodeGenInfo().getUBSanFunctionSignature(CGM)) {
3373 llvm::Constant *FTRTTIConst =
3374 CGM.GetAddrOfRTTIDescriptor(
QualType(FnType, 0),
true);
3375 llvm::Type *PrefixStructTyElems[] = {
3376 PrefixSig->getType(),
3377 FTRTTIConst->getType()
3379 llvm::StructType *PrefixStructTy = llvm::StructType::get(
3380 CGM.getLLVMContext(), PrefixStructTyElems,
true);
3383 Callee, llvm::PointerType::getUnqual(PrefixStructTy));
3385 Builder.CreateConstGEP2_32(PrefixStructTy, CalleePrefixStruct, 0, 0);
3389 llvm::BasicBlock *Cont = createBasicBlock(
"cont");
3390 llvm::BasicBlock *TypeCheck = createBasicBlock(
"typecheck");
3391 Builder.CreateCondBr(CalleeSigMatch, TypeCheck, Cont);
3393 EmitBlock(TypeCheck);
3395 Builder.CreateConstGEP2_32(PrefixStructTy, CalleePrefixStruct, 0, 1);
3398 Builder.CreateICmpEQ(CalleeRTTI, FTRTTIConst);
3399 llvm::Constant *StaticData[] = {
3401 EmitCheckTypeDescriptor(CalleeType)
3403 EmitCheck(std::make_pair(CalleeRTTIMatch, SanitizerKind::Function),
3404 "function_type_mismatch", StaticData, Callee);
3413 Args.
add(RValue::get(
Builder.CreateBitCast(Chain, CGM.VoidPtrTy)),
3414 CGM.getContext().VoidPtrTy);
3415 EmitCallArgs(Args, dyn_cast<FunctionProtoType>(FnType), E->
arg_begin(),
3418 const CGFunctionInfo &FnInfo = CGM.getTypes().arrangeFreeFunctionCall(
3419 Args, FnType, Chain);
3441 if (isa<FunctionNoProtoType>(FnType) || Chain) {
3442 llvm::Type *CalleeTy = getTypes().GetFunctionType(FnInfo);
3443 CalleeTy = CalleeTy->getPointerTo();
3444 Callee =
Builder.CreateBitCast(Callee, CalleeTy,
"callee.knr.cast");
3447 return EmitCall(FnInfo, Callee, ReturnValue, Args, TargetDecl);
3454 BaseV = EmitScalarExpr(E->
getLHS());
3456 BaseV = EmitLValue(E->
getLHS()).getAddress();
3463 llvm::Value *AddV = CGM.getCXXABI().EmitMemberDataPointerAddress(
3464 *
this, E, BaseV, OffsetV, MPT);
3466 return MakeAddrLValue(AddV, MPT->getPointeeType());
3474 LValue lvalue = MakeNaturalAlignAddrLValue(addr, type);
3475 switch (getEvaluationKind(type)) {
3477 return RValue::getComplex(EmitLoadOfComplex(lvalue, loc));
3481 return RValue::get(EmitLoadOfScalar(lvalue, loc));
3483 llvm_unreachable(
"bad evaluation kind");
3486 void CodeGenFunction::SetFPAccuracy(
llvm::Value *Val,
float Accuracy) {
3487 assert(Val->getType()->isFPOrFPVectorTy());
3488 if (Accuracy == 0.0 || !isa<llvm::Instruction>(Val))
3491 llvm::MDBuilder MDHelper(getLLVMContext());
3492 llvm::MDNode *
Node = MDHelper.createFPMath(Accuracy);
3494 cast<llvm::Instruction>(Val)->setMetadata(llvm::LLVMContext::MD_fpmath, Node);
3498 struct LValueOrRValue {
3512 LValueOrRValue result;
3516 const Expr *semantic = *i;
3520 if (
const auto *ov = dyn_cast<OpaqueValueExpr>(semantic)) {
3526 if (ov == resultExpr && ov->
isRValue() && !forLValue &&
3527 CodeGenFunction::hasAggregateEvaluationKind(ov->getType())) {
3531 opaqueData = OVMA::bind(CGF, ov, LV);
3536 opaqueData = OVMA::bind(CGF, ov, ov->getSourceExpr());
3539 if (ov == resultExpr) {
3547 opaques.push_back(opaqueData);
3551 }
else if (semantic == resultExpr) {
3564 for (
unsigned i = 0, e = opaques.size(); i != e; ++i)
3565 opaques[i].unbind(CGF);
unsigned getNumElements() const
unsigned getAddressSpace() const
getAddressSpace - Return the address space of this type.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Defines the clang::ASTContext interface.
unsigned getNumInits() const
const Expr * getBase() const
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
CastKind getCastKind() const
unsigned getVRQualifiers() const
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
void end(CodeGenFunction &CGF)
StringRef getName() const
unsigned getColumn() const
Return the presumed column number of this location.
llvm::Type * ConvertTypeForMem(QualType T)
Expr * getBaseIvarExp() const
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
bool isBitField() const
Determines whether this field is a bitfield.
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
llvm::Module & getModule() const
llvm::LLVMContext & getLLVMContext()
LValue EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
Expr * GetTemporaryExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
Qualifiers::GC getObjCGCAttr() const
getObjCGCAttr - Returns gc attribute of this type.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
bool isRecordType() const
void setTBAAInfo(llvm::MDNode *N)
const CastExpr * BasePath
static Destroyer destroyARCStrongPrecise
static void setObjCGCLValueClass(const ASTContext &Ctx, const Expr *E, LValue &LV, bool IsMemberAccess=false)
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit)
LValue EmitOpaqueValueLValue(const OpaqueValueExpr *e)
RValue asAggregateRValue() const
static llvm::Value * EmitBitCastOfLValueToProperType(CodeGenFunction &CGF, llvm::Value *V, llvm::Type *IRType, StringRef Name=StringRef())
bool sanitizePerformTypeCheck() const
Whether any type-checking sanitizers are enabled. If false, calls to EmitTypeCheck can be skipped...
Represents a call to a C++ constructor.
bool isBooleanType() const
StorageDuration
The storage duration for an object (per C++ [basic.stc]).
const LangOptions & getLangOpts() const
bool isBlockPointerType() const
[ARC] Consumes a retainable object pointer that has just been produced, e.g. as the return value of a...
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
llvm::Value * getAddress() const
IdentType getIdentType() const
unsigned getLLVMFieldNo(const FieldDecl *FD) const
Return llvm::StructType element number that corresponds to the field FD.
static Destroyer destroyARCWeak
void * getAsOpaquePtr() const
static bool hasBooleanRepresentation(QualType Ty)
RAII object to set/unset CodeGenFunction::IsSanitizerScope.
const Expr * getCallee() const
static void pushTemporaryCleanup(CodeGenFunction &CGF, const MaterializeTemporaryExpr *M, const Expr *E, llvm::Value *ReferenceTemporary)
TLSKind getTLSKind() const
ObjCLifetime getObjCLifetime() const
void setTBAAOffset(uint64_t O)
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
llvm::Constant * GetAddrOfGlobalVar(const VarDecl *D, llvm::Type *Ty=nullptr)
const CGBitFieldInfo & getBitFieldInfo(const FieldDecl *FD) const
Return the BitFieldInfo that corresponds to the field FD.
CK_Dynamic - A C++ dynamic_cast.
llvm::Type * ConvertTypeForMem(QualType T)
SourceLocation getLocation() const
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
An object to manage conditionally-evaluated expressions.
void setTBAABaseType(QualType T)
bool isVolatileQualified() const
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Converts between different integral complex types. _Complex char -> _Complex long long _Complex unsig...
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
bool isReferenceType() const
An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
Converting between two Objective-C object types, which can occur when performing reference binding to...
SourceLocation getExprLoc() const LLVM_READONLY
unsigned getCVRQualifiers() const
[ARC] Causes a value of block type to be copied to the heap, if it is not already there...
static LValue EmitGlobalNamedRegister(const VarDecl *VD, CodeGenModule &CGM, CharUnits Alignment)
static void emitCheckHandlerCall(CodeGenFunction &CGF, llvm::FunctionType *FnType, ArrayRef< llvm::Value * > FnArgs, StringRef CheckName, CheckRecoverableKind RecoverKind, bool IsFatal, llvm::BasicBlock *ContBB)
void setBaseIvarExp(Expr *V)
llvm::Value * EmitScalarConversion(llvm::Value *Src, QualType SrcTy, QualType DstTy)
static bool isFlexibleArrayMemberExpr(const Expr *E)
RValue EmitAnyExprToTemp(const Expr *E)
const Expr *const * const_semantics_iterator
void setNonGC(bool Value)
Converts a floating point complex to bool by comparing against 0+0i.
RValue EmitAnyExpr(const Expr *E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment=CharUnits())
Describes an C or C++ initializer list.
unsigned Size
The total size of the bit-field, in bits.
static LValueOrRValue emitPseudoObjectExpr(CodeGenFunction &CGF, const PseudoObjectExpr *E, bool forLValue, AggValueSlot slot)
void Destroyer(CodeGenFunction &CGF, llvm::Value *addr, QualType ty)
CharUnits getAlignment() const
const LangOptions & getLangOpts() const
Expr * getTrueExpr() const
APValue Val
Val - This is the value the expression can be folded to.
const Qualifiers & getQuals() const
const ValueDecl * getExtendingDecl() const
Get the declaration which triggered the lifetime-extension of this temporary, if any.
static LValue EmitFunctionDeclLValue(CodeGenFunction &CGF, const Expr *E, const FunctionDecl *FD)
CharUnits StorageOffset
The offset of the bitfield storage from the start of the struct.
static bool getRangeForType(CodeGenFunction &CGF, QualType Ty, llvm::APInt &Min, llvm::APInt &End, bool StrictEnums)
path_iterator path_begin()
bool isObjCLifetimeType() const
void addCVRQualifiers(unsigned mask)
semantics_iterator semantics_end()
A builtin binary operation expression such as "x + y" or "x <= y".
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr * > &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
RecordDecl * getDecl() const
llvm::Value * getAggregateAddr() const
getAggregateAddr() - Return the Value* of the address of the aggregate.
llvm::Value * GetAddressOfBaseClass(llvm::Value *Value, const CXXRecordDecl *Derived, CastExpr::path_const_iterator PathBegin, CastExpr::path_const_iterator PathEnd, bool NullCheckValue, SourceLocation Loc)
void pushDestroy(QualType::DestructionKind dtorKind, llvm::Value *addr, QualType type)
virtual llvm::Value * EmitMemberPointerIsNotNull(CodeGenFunction &CGF, llvm::Value *MemPtr, const MemberPointerType *MPT)
Determine if a member pointer is non-null. Returns an i1.
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
uint64_t getFieldOffset(unsigned FieldNo) const
void EmitIgnoredExpr(const Expr *E)
EmitIgnoredExpr - Emit an expression in a context which ignores the result.
An adjustment to be made to the temporary created when emitting a reference binding, which accesses a particular subobject of that temporary.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Def If non-NULL, and the type refers to some kind of declaration that can be completed (such as a C s...
Represents binding an expression to a temporary.
CXXTemporary * getTemporary()
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
unsigned getLine() const
Return the presumed line number of this location.
llvm::Function * generateDestroyHelper(llvm::Constant *addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray, const VarDecl *VD)
void setARCPreciseLifetime(ARCPreciseLifetime_t value)
bool isExtVectorElt() const
Represents an ObjC class declaration.
void begin(CodeGenFunction &CGF)
void setThreadLocalRef(bool Value)
LValue EmitLValueForField(LValue Base, const FieldDecl *Field)
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor)
EnumDecl * getDecl() const
llvm::GlobalValue * getAddrOfCXXStructor(const CXXMethodDecl *MD, StructorType Type, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false)
Return the address of the constructor/destructor of the given type.
const ArrayType * castAsArrayTypeUnsafe() const
std::pair< llvm::Value *, llvm::Value * > ComplexPairTy
llvm::CallInst * EmitNounwindRuntimeCall(llvm::Value *callee, const Twine &name="")
Qualifiers::ObjCLifetime getObjCLifetime() const
getObjCLifetime - Returns lifetime attribute of this type.
Causes a block literal to by copied to the heap and then autoreleased.
bool isOBJCGCCandidate(ASTContext &Ctx) const
bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const
static CheckRecoverableKind getRecoverableKind(SanitizerMask Kind)
virtual LValue EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF, const VarDecl *VD, QualType LValType)=0
CleanupKind getARCCleanupKind()
VAArgExpr, used for the builtin function __builtin_va_arg.
ID
Defines the set of possible language-specific address spaces.
QualType getPointeeType() const
bool isFunctionPointerType() const
Converts between different floating point complex types. _Complex float -> _Complex double...
const ObjCMethodDecl * getMethodDecl() const
bool isSignedIntegerOrEnumerationType() const
static TypeEvaluationKind getEvaluationKind(QualType T)
llvm::Value * getBitFieldAddr() const
void InitTempAlloca(llvm::AllocaInst *Alloca, llvm::Value *Value)
InitTempAlloca - Provide an initial value for the given alloca.
Converts an integral complex to an integral real of the source's element type by discarding the imagi...
CGCXXABI & getCXXABI() const
bool isAnyComplexType() const
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited...
static LValue EmitThreadPrivateVarDeclLValue(CodeGenFunction &CGF, const VarDecl *VD, QualType T, llvm::Value *V, llvm::Type *RealVarTy, CharUnits Alignment, SourceLocation Loc)
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
void setObjCArray(bool Value)
bool isAtomicType() const
Represents a C++ destructor within a class.
bool isVariableArrayType() const
static LValue EmitCapturedFieldLValue(CodeGenFunction &CGF, const FieldDecl *FD, llvm::Value *ThisValue)
AggValueSlot CreateAggTemp(QualType T, const Twine &Name="tmp")
bool isFloatingType() const
ObjCSelectorExpr used for @selector in Objective-C.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
void add(RValue rvalue, QualType type, bool needscopy=false)
static Optional< LValue > EmitLValueOrThrowExpression(CodeGenFunction &CGF, const Expr *Operand)
virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D, llvm::Constant *Dtor, llvm::Constant *Addr)=0
Selector getSelector() const
llvm::LLVMContext & getLLVMContext()
Expr * getSubExpr() const
static llvm::Constant * GenerateConstantVector(CGBuilderTy &Builder, SmallVectorImpl< unsigned > &Elts)
bool isThreadLocalRef() const
llvm::Value * getExtVectorAddr() const
LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T)
An expression that sends a message to the given Objective-C object or class.
Represents an unpacked "presumed" location which can be presented to the user.
Converts from an integral complex to a floating complex. _Complex unsigned -> _Complex float...
llvm::Value * EmitCastToVoidPtr(llvm::Value *value)
Emit a cast to void* in the appropriate address space.
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=None)
QualType getElementType() const
The result type of a method or function.
void getEncodedElementAccess(SmallVectorImpl< unsigned > &Elts) const
getEncodedElementAccess - We encode the fields as a llvm ConstantArray.
llvm::IRBuilder< PreserveNames, llvm::ConstantFolder, CGBuilderInserterTy > CGBuilderTy
Dynamic storage duration.
void EmitAnyExprToMem(const Expr *E, llvm::Value *Location, Qualifiers Quals, bool IsInitializer)
There is no lifetime qualification on this type.
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
llvm::Constant * CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeSet ExtraAttrs=llvm::AttributeSet())
Create a new runtime function with the specified type and name.
const char * getFilename() const
Return the presumed filename of this location.
llvm::AllocaInst * CreateIRTemp(QualType T, const Twine &Name="tmp")
llvm::Constant * EmitConstantExpr(const Expr *E, QualType DestType, CodeGenFunction *CGF=nullptr)
ASTContext & getContext() const
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
QualType getElementType() const
QualType withCVRQualifiers(unsigned CVR) const
llvm::Value * EvaluateExprAsBool(const Expr *E)
SourceLocation getExprLoc() const LLVM_READONLY
const CGBitFieldInfo & getBitFieldInfo() const
static llvm::Value * createReferenceTemporary(CodeGenFunction &CGF, const MaterializeTemporaryExpr *M, const Expr *Inner)
bool isValid() const
Return true if this is a valid SourceLocation object.
llvm::MDNode * getTBAAInfo() const
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Represents a static or instance method of a struct/union/class.
static LValue EmitGlobalVarDeclLValue(CodeGenFunction &CGF, const Expr *E, const VarDecl *VD)
SanitizerSet SanOpts
Sanitizers enabled for this function.
const CodeGenOptions & getCodeGenOpts() const
TypeCheckKind
Situations in which we might emit a check for the suitability of a pointer or glvalue.
const Type * getBaseElementTypeUnsafe() const
StringLiteral * getFunctionName()
Converts from an integral real to an integral complex whose element type matches the source...
llvm::AllocaInst * CreateMemTemp(QualType T, const Twine &Name="tmp")
void setObjCIvar(bool Value)
QualType getReturnType() const
bool isVectorType() const
llvm::Constant * GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E, const Expr *Inner)
Returns a pointer to a global variable representing a temporary with static or thread storage duratio...
Assigning into this object requires a lifetime extension.
const Expr * getBase() const
llvm::Value * getGlobalReg() const
static Destroyer destroyARCStrongImprecise
SourceLocation getExprLoc() const LLVM_READONLY
QualType getPointeeType() const
void setExternallyDestructed(bool destructed=true)
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
QualType getCallReturnType(const ASTContext &Ctx) const
ast_type_traits::DynTypedNode Node
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
TLS with a dynamic initializer.
Converts a floating point complex to floating point real of the source's element type. Just discards the imaginary component. _Complex long double -> long double.
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
static const Type * getElementType(const Expr *BaseExpr)
[C99 6.4.2.2] - A predefined identifier such as func.
static RValue getComplex(llvm::Value *V1, llvm::Value *V2)
EvalResult is a struct with detailed info about an evaluated expression.
llvm::Constant * GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty=0, bool ForVTable=false, bool DontDefer=false)
Converts an integral complex to bool by comparing against 0+0i.
bool isZero() const
isZero - Test whether the quantity equals zero.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return 0.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
static AggValueSlot ignored()
unsigned IsSigned
Whether the bit-field is signed.
llvm::IntegerType * IntPtrTy
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
bool isUsed(bool CheckUsedAttr=true) const
Whether this declaration was used, meaning that a definition is required.
llvm::Constant * EmitNullConstant(QualType T)
semantics_iterator semantics_begin()
A conversion of a floating point real to a floating point complex of the original type...
void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *V, QualType Type, CharUnits Alignment=CharUnits::Zero(), bool SkipNullCheck=false)
Emit a check that V is the address of storage of the appropriate size and alignment for an object of ...
void EmitAggExpr(const Expr *E, AggValueSlot AS)
[ARC] Reclaim a retainable object pointer object that may have been produced and autoreleased as part...
static bool hasAggregateEvaluationKind(QualType T)
llvm::Constant * getExtVectorElts() const
llvm::Value * EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, QualType DstTy)
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum. These widths include the rightmost leading 1; that is:
Expr * getFalseExpr() const
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
QualType getCanonicalType() const
virtual llvm::Value * EmitMemberDataPointerAddress(CodeGenFunction &CGF, const Expr *E, llvm::Value *Base, llvm::Value *MemPtr, const MemberPointerType *MPT)
Calculate an l-value from an object and a data member pointer.
static StringRef getIdentTypeName(IdentType IT)
virtual bool usesThreadWrapperFunction() const =0
[ARC] Produces a retainable object pointer so that it may be consumed, e.g. by being passed to a cons...
QualType getIntegerType() const
llvm::PointerType * Int8PtrTy
SourceLocation getLocStart() const LLVM_READONLY
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
llvm::AssertingVH< llvm::Instruction > AllocaInsertPt
bool isFunctionType() const
QualType getTBAABaseType() const
static llvm::Value * emitHash16Bytes(CGBuilderTy &Builder, llvm::Value *Low, llvm::Value *High)
Emit the hash_16_bytes function from include/llvm/ADT/Hashing.h.
Converts from T to _Atomic(T).
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Converts from a floating complex to an integral complex. _Complex float -> _Complex int...
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
void setGlobalObjCRef(bool Value)
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal=false, bool IgnoreImag=false)
const Expr * getInitializer() const
unsigned getFieldIndex() const
ObjCIvarRefExpr - A reference to an ObjC instance variable.
enum clang::SubobjectAdjustment::@40 Kind
llvm::Value * getVectorIdx() const
llvm::Value * getAddr() const
Reading or writing from this object requires a barrier call.
void setCurrentStmt(const Stmt *S)
static bool isConstantEmittableObjectType(QualType type)
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum...
Represents a C++ struct/union/class.
bool isObjCStrong() const
BoundNodesTreeBuilder *const Builder
llvm::Type * ConvertType(QualType T)
static Destroyer destroyCXXObject
LValue EmitLValue(const Expr *E)
static llvm::Value * getArrayIndexingBound(CodeGenFunction &CGF, const Expr *Base, QualType &IndexedType)
Converts from _Atomic(T) to T.
std::pair< llvm::Value *, QualType > getVLASize(const VariableArrayType *vla)
Full-expression storage duration (for temporaries).
const MemberPointerType * MPT
A reference to a declared variable, function, enum, etc. [C99 6.5.1p2].
static RValue get(llvm::Value *V)
static ConstantEmissionKind checkVarTypeForConstantEmission(QualType type)
static AggValueSlot forAddr(llvm::Value *addr, CharUnits align, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, IsZeroed_t isZeroed=IsNotZeroed)
const Expr * getInit(unsigned Init) const
const Expr * getSubExpr() const
CodeGenTypes & getTypes() const
CharUnits alignmentAtOffset(CharUnits offset)
void pushLifetimeExtendedDestroy(CleanupKind kind, llvm::Value *addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
bool isGlobalObjCRef() const
bool isArithmeticType() const
Automatic storage duration (most local variables).
bool isSignedIntegerType() const
llvm::Value * getVectorAddr() const
bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const
bool isNull() const
isNull - Return true if this QualType doesn't point to a type yet.
const CXXRecordDecl * DerivedClass
uint64_t getTBAAOffset() const
void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint=true)
bool isIntegerType() const
Structure with information about how a bitfield should be accessed.
const RecordDecl * getParent() const
CheckRecoverableKind
Specify under what conditions this check can be recovered.
Expr * IgnoreParens() LLVM_READONLY
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
bool isPointerType() const
static const Expr * isSimpleArrayDecayOperand(const Expr *E)
static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts)