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;
68 if (!
Builder.isNamePreserving())
85 assert(isa<llvm::AllocaInst>(Var.
getPointer()));
148 if (!ignoreResult && aggSlot.
isIgnored())
153 llvm_unreachable(
"bad evaluation kind");
194 llvm_unreachable(
"bad evaluation kind");
235 VD && isa<VarDecl>(VD) && VD->
hasAttr<ObjCPreciseLifetimeAttr>();
256 llvm_unreachable(
"temporary cannot have dynamic storage duration");
258 llvm_unreachable(
"unknown storage duration");
266 auto *ClassDecl = cast<CXXRecordDecl>(RT->getDecl());
267 if (!ClassDecl->hasTrivialDestructor())
268 ReferenceTemporaryDtor = ClassDecl->getDestructor();
271 if (!ReferenceTemporaryDtor)
278 llvm::Constant *CleanupFn;
279 llvm::Constant *CleanupArg;
282 ReferenceTemporary, E->
getType(),
285 CleanupArg = llvm::Constant::getNullValue(CGF.
Int8PtrTy);
289 CleanupArg = cast<llvm::Constant>(ReferenceTemporary.
getPointer());
304 ReferenceTemporary, E->
getType(),
310 llvm_unreachable(
"temporary cannot have dynamic storage duration");
329 auto *GV =
new llvm::GlobalVariable(
331 llvm::GlobalValue::PrivateLinkage, Init,
".ref.tmp");
333 GV->setAlignment(alignment.getQuantity());
344 llvm_unreachable(
"temporary can't have dynamic storage duration");
346 llvm_unreachable(
"unknown storage duration");
359 if (
auto *Var = dyn_cast<llvm::GlobalVariable>(Object.
getPointer())) {
360 Object =
Address(llvm::ConstantExpr::getBitCast(Var,
366 assert(!Var->hasInitializer());
373 default: llvm_unreachable(
"expected scalar or aggregate expression");
395 for (
const auto &Ignored : CommaLHSs)
398 if (
const auto *opaque = dyn_cast<OpaqueValueExpr>(E)) {
399 if (opaque->getType()->isRecordType()) {
400 assert(Adjustments.empty());
407 if (
auto *Var = dyn_cast<llvm::GlobalVariable>(Object.
getPointer())) {
408 Object =
Address(llvm::ConstantExpr::getBitCast(
414 if (!Var->hasInitializer()) {
426 for (
unsigned I = Adjustments.size();
I != 0; --
I) {
428 switch (Adjustment.
Kind) {
441 assert(LV.isSimple() &&
442 "materialized temporary field is not a simple lvalue");
443 Object = LV.getAddress();
483 const llvm::Constant *Elts) {
484 return cast<llvm::ConstantInt>(Elts->getAggregateElement(Idx))
491 llvm::Value *KMul = Builder.getInt64(0x9ddfea08eb382d69ULL);
493 llvm::Value *A0 = Builder.CreateMul(Builder.CreateXor(Low, High), KMul);
494 llvm::Value *A1 = Builder.CreateXor(Builder.CreateLShr(A0, K47), A0);
495 llvm::Value *B0 = Builder.CreateMul(Builder.CreateXor(High, A1), KMul);
496 llvm::Value *B1 = Builder.CreateXor(Builder.CreateLShr(B0, K47), B0);
497 return Builder.CreateMul(B1, KMul);
509 CharUnits Alignment,
bool SkipNullCheck) {
516 if (Ptr->getType()->getPointerAddressSpace())
522 llvm::BasicBlock *Done =
nullptr;
526 if ((
SanOpts.
has(SanitizerKind::Null) || AllowNullPointers) &&
531 if (AllowNullPointers) {
536 Builder.CreateCondBr(IsNonNull, Rest, Done);
539 Checks.push_back(std::make_pair(IsNonNull, SanitizerKind::Null));
556 llvm::ConstantInt::get(
IntPtrTy, Size));
557 Checks.push_back(std::make_pair(LargeEnough, SanitizerKind::ObjectSize));
560 uint64_t AlignVal = 0;
562 if (SanOpts.has(SanitizerKind::Alignment)) {
563 AlignVal = Alignment.getQuantity();
564 if (!Ty->isIncompleteType() && !AlignVal)
565 AlignVal = getContext().getTypeAlignInChars(Ty).getQuantity();
571 llvm::ConstantInt::get(IntPtrTy, AlignVal - 1));
573 Builder.CreateICmpEQ(Align, llvm::ConstantInt::get(IntPtrTy, 0));
574 Checks.push_back(std::make_pair(Aligned, SanitizerKind::Alignment));
578 if (Checks.size() > 0) {
579 llvm::Constant *StaticData[] = {
580 EmitCheckSourceLocation(Loc),
581 EmitCheckTypeDescriptor(Ty),
582 llvm::ConstantInt::get(SizeTy, AlignVal),
583 llvm::ConstantInt::get(Int8Ty, TCK)
585 EmitCheck(Checks,
"type_mismatch", StaticData, Ptr);
597 if (SanOpts.has(SanitizerKind::Vptr) &&
598 (TCK == TCK_MemberAccess || TCK == TCK_MemberCall ||
599 TCK == TCK_DowncastPointer || TCK == TCK_DowncastReference ||
600 TCK == TCK_UpcastToVirtualBase) &&
601 RD && RD->hasDefinition() && RD->isDynamicClass()) {
608 llvm::raw_svector_ostream Out(MangledName);
609 CGM.getCXXABI().getMangleContext().mangleCXXRTTI(Ty.getUnqualifiedType(),
613 if (!CGM.getContext().getSanitizerBlacklist().isBlacklistedType(
615 llvm::hash_code TypeHash = hash_value(Out.str());
618 llvm::Value *Low = llvm::ConstantInt::get(Int64Ty, TypeHash);
619 llvm::Type *VPtrTy = llvm::PointerType::get(IntPtrTy, 0);
620 Address VPtrAddr(
Builder.CreateBitCast(Ptr, VPtrTy), getPointerAlign());
625 Hash =
Builder.CreateTrunc(Hash, IntPtrTy);
628 const int CacheSize = 128;
629 llvm::Type *HashTable = llvm::ArrayType::get(IntPtrTy, CacheSize);
631 "__ubsan_vptr_type_cache");
633 llvm::ConstantInt::get(IntPtrTy,
637 Builder.CreateAlignedLoad(
Builder.CreateInBoundsGEP(Cache, Indices),
645 llvm::Constant *StaticData[] = {
646 EmitCheckSourceLocation(Loc),
647 EmitCheckTypeDescriptor(Ty),
648 CGM.GetAddrOfRTTIDescriptor(Ty.getUnqualifiedType()),
649 llvm::ConstantInt::get(Int8Ty, TCK)
652 EmitCheck(std::make_pair(EqualHash, SanitizerKind::Vptr),
653 "dynamic_type_cache_miss", StaticData, DynamicData);
669 if (
const auto *CAT = dyn_cast<ConstantArrayType>(AT)) {
670 if (CAT->getSize().ugt(1))
672 }
else if (!isa<IncompleteArrayType>(AT))
678 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
681 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
684 return ++FI == FD->getParent()->field_end();
698 return CGF.
Builder.getInt32(VT->getNumElements());
703 if (
const auto *CE = dyn_cast<CastExpr>(Base)) {
706 IndexedType = CE->getSubExpr()->getType();
708 if (
const auto *CAT = dyn_cast<ConstantArrayType>(AT))
709 return CGF.
Builder.getInt(CAT->getSize());
710 else if (
const auto *VAT = dyn_cast<VariableArrayType>(AT))
721 assert(SanOpts.has(SanitizerKind::ArrayBounds) &&
722 "should not be called unless adding bounds checks");
734 llvm::Constant *StaticData[] = {
736 EmitCheckTypeDescriptor(IndexedType),
737 EmitCheckTypeDescriptor(IndexType)
740 :
Builder.CreateICmpULE(IndexVal, BoundVal);
741 EmitCheck(std::make_pair(Check, SanitizerKind::ArrayBounds),
"out_of_bounds",
748 bool isInc,
bool isPre) {
752 if (isa<llvm::IntegerType>(InVal.first->getType())) {
753 uint64_t AmountVal = isInc ? 1 : -1;
754 NextVal = llvm::ConstantInt::get(InVal.first->getType(), AmountVal,
true);
757 NextVal =
Builder.CreateAdd(InVal.first, NextVal, isInc ?
"inc" :
"dec");
760 llvm::APFloat FVal(getContext().getFloatTypeSemantics(ElemTy), 1);
763 NextVal = llvm::ConstantFP::get(getLLVMContext(), FVal);
766 NextVal =
Builder.CreateFAdd(InVal.first, NextVal, isInc ?
"inc" :
"dec");
772 EmitStoreOfComplex(IncVal, LV,
false);
776 return isPre ? IncVal : InVal;
786 DI->EmitExplicitCastType(E->
getType());
803 if (
const CastExpr *CE = dyn_cast<CastExpr>(E)) {
804 if (
const auto *ECE = dyn_cast<ExplicitCastExpr>(CE))
805 CGM.EmitExplicitCastExprType(ECE,
this);
807 switch (CE->getCastKind()) {
811 if (
auto PtrTy = CE->getSubExpr()->getType()->getAs<
PointerType>()) {
812 if (PtrTy->getPointeeType()->isVoidType())
816 Address Addr = EmitPointerWithAlignment(CE->getSubExpr(), &InnerSource);
817 if (Source) *Source = InnerSource;
821 if (isa<ExplicitCastExpr>(CE) &&
822 InnerSource != AlignmentSource::Decl) {
824 getNaturalPointeeTypeAlignment(E->getType(), Source));
827 if (SanOpts.has(SanitizerKind::CFIUnrelatedCast)) {
829 EmitVTablePtrCheckForCast(PT->getPointeeType(), Addr.
getPointer(),
831 CodeGenFunction::CFITCK_UnrelatedCast,
835 return Builder.CreateBitCast(Addr, ConvertType(E->getType()));
841 return EmitArrayToPointerDecay(CE->getSubExpr(), Source);
846 Address Addr = EmitPointerWithAlignment(CE->getSubExpr(), Source);
847 auto Derived = CE->getSubExpr()->
getType()->getPointeeCXXRecordDecl();
848 return GetAddressOfBaseClass(Addr, Derived,
849 CE->path_begin(), CE->path_end(),
850 ShouldNullCheckClassCastValue(CE),
864 LValue LV = EmitLValue(UO->getSubExpr());
873 CharUnits Align = getNaturalPointeeTypeAlignment(E->getType(), Source);
874 return Address(EmitScalarExpr(E), Align);
879 return RValue::get(
nullptr);
881 switch (getEvaluationKind(Ty)) {
886 return RValue::getComplex(std::make_pair(U, U));
893 Address DestPtr = CreateMemTemp(Ty,
"undef.agg.tmp");
894 return RValue::getAggregate(DestPtr);
898 return RValue::get(llvm::UndefValue::get(ConvertType(Ty)));
900 llvm_unreachable(
"bad evaluation kind");
905 ErrorUnsupported(E, Name);
906 return GetUndefRValue(E->
getType());
911 ErrorUnsupported(E, Name);
912 llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(E->
getType()));
919 if (SanOpts.has(SanitizerKind::ArrayBounds) && isa<ArraySubscriptExpr>(
E))
920 LV = EmitArraySubscriptExpr(cast<ArraySubscriptExpr>(E),
true);
946 switch (E->getStmtClass()) {
947 default:
return EmitUnsupportedLValue(E,
"l-value expression");
949 case Expr::ObjCPropertyRefExprClass:
950 llvm_unreachable(
"cannot emit a property reference directly");
952 case Expr::ObjCSelectorExprClass:
953 return EmitObjCSelectorLValue(cast<ObjCSelectorExpr>(E));
954 case Expr::ObjCIsaExprClass:
955 return EmitObjCIsaExpr(cast<ObjCIsaExpr>(E));
956 case Expr::BinaryOperatorClass:
957 return EmitBinaryOperatorLValue(cast<BinaryOperator>(E));
958 case Expr::CompoundAssignOperatorClass: {
961 Ty = AT->getValueType();
963 return EmitCompoundAssignmentLValue(cast<CompoundAssignOperator>(E));
964 return EmitComplexCompoundAssignmentLValue(cast<CompoundAssignOperator>(E));
966 case Expr::CallExprClass:
967 case Expr::CXXMemberCallExprClass:
968 case Expr::CXXOperatorCallExprClass:
969 case Expr::UserDefinedLiteralClass:
970 return EmitCallExprLValue(cast<CallExpr>(E));
971 case Expr::VAArgExprClass:
972 return EmitVAArgExprLValue(cast<VAArgExpr>(E));
973 case Expr::DeclRefExprClass:
974 return EmitDeclRefLValue(cast<DeclRefExpr>(E));
975 case Expr::ParenExprClass:
976 return EmitLValue(cast<ParenExpr>(E)->getSubExpr());
977 case Expr::GenericSelectionExprClass:
978 return EmitLValue(cast<GenericSelectionExpr>(E)->getResultExpr());
979 case Expr::PredefinedExprClass:
980 return EmitPredefinedLValue(cast<PredefinedExpr>(E));
981 case Expr::StringLiteralClass:
982 return EmitStringLiteralLValue(cast<StringLiteral>(E));
983 case Expr::ObjCEncodeExprClass:
984 return EmitObjCEncodeExprLValue(cast<ObjCEncodeExpr>(E));
985 case Expr::PseudoObjectExprClass:
986 return EmitPseudoObjectLValue(cast<PseudoObjectExpr>(E));
987 case Expr::InitListExprClass:
988 return EmitInitListLValue(cast<InitListExpr>(E));
989 case Expr::CXXTemporaryObjectExprClass:
990 case Expr::CXXConstructExprClass:
991 return EmitCXXConstructLValue(cast<CXXConstructExpr>(E));
992 case Expr::CXXBindTemporaryExprClass:
993 return EmitCXXBindTemporaryLValue(cast<CXXBindTemporaryExpr>(E));
994 case Expr::CXXUuidofExprClass:
995 return EmitCXXUuidofLValue(cast<CXXUuidofExpr>(E));
996 case Expr::LambdaExprClass:
997 return EmitLambdaLValue(cast<LambdaExpr>(E));
999 case Expr::ExprWithCleanupsClass: {
1000 const auto *cleanups = cast<ExprWithCleanups>(
E);
1001 enterFullExpression(cleanups);
1003 return EmitLValue(cleanups->getSubExpr());
1006 case Expr::CXXDefaultArgExprClass:
1007 return EmitLValue(cast<CXXDefaultArgExpr>(E)->getExpr());
1008 case Expr::CXXDefaultInitExprClass: {
1010 return EmitLValue(cast<CXXDefaultInitExpr>(E)->getExpr());
1012 case Expr::CXXTypeidExprClass:
1013 return EmitCXXTypeidLValue(cast<CXXTypeidExpr>(E));
1015 case Expr::ObjCMessageExprClass:
1016 return EmitObjCMessageExprLValue(cast<ObjCMessageExpr>(E));
1017 case Expr::ObjCIvarRefExprClass:
1018 return EmitObjCIvarRefLValue(cast<ObjCIvarRefExpr>(E));
1019 case Expr::StmtExprClass:
1020 return EmitStmtExprLValue(cast<StmtExpr>(E));
1021 case Expr::UnaryOperatorClass:
1022 return EmitUnaryOpLValue(cast<UnaryOperator>(E));
1023 case Expr::ArraySubscriptExprClass:
1024 return EmitArraySubscriptExpr(cast<ArraySubscriptExpr>(E));
1025 case Expr::OMPArraySectionExprClass:
1026 return EmitOMPArraySectionExpr(cast<OMPArraySectionExpr>(E));
1027 case Expr::ExtVectorElementExprClass:
1028 return EmitExtVectorElementExpr(cast<ExtVectorElementExpr>(E));
1029 case Expr::MemberExprClass:
1030 return EmitMemberExpr(cast<MemberExpr>(E));
1031 case Expr::CompoundLiteralExprClass:
1032 return EmitCompoundLiteralLValue(cast<CompoundLiteralExpr>(E));
1033 case Expr::ConditionalOperatorClass:
1034 return EmitConditionalOperatorLValue(cast<ConditionalOperator>(E));
1035 case Expr::BinaryConditionalOperatorClass:
1036 return EmitConditionalOperatorLValue(cast<BinaryConditionalOperator>(E));
1037 case Expr::ChooseExprClass:
1038 return EmitLValue(cast<ChooseExpr>(E)->getChosenSubExpr());
1039 case Expr::OpaqueValueExprClass:
1040 return EmitOpaqueValueLValue(cast<OpaqueValueExpr>(E));
1041 case Expr::SubstNonTypeTemplateParmExprClass:
1042 return EmitLValue(cast<SubstNonTypeTemplateParmExpr>(E)->getReplacement());
1043 case Expr::ImplicitCastExprClass:
1044 case Expr::CStyleCastExprClass:
1045 case Expr::CXXFunctionalCastExprClass:
1046 case Expr::CXXStaticCastExprClass:
1047 case Expr::CXXDynamicCastExprClass:
1048 case Expr::CXXReinterpretCastExprClass:
1049 case Expr::CXXConstCastExprClass:
1050 case Expr::ObjCBridgedCastExprClass:
1051 return EmitCastLValue(cast<CastExpr>(E));
1053 case Expr::MaterializeTemporaryExprClass:
1054 return EmitMaterializeTemporaryExpr(cast<MaterializeTemporaryExpr>(E));
1066 if (!qs.hasConst() || qs.hasVolatile())
return false;
1070 if (
const auto *RT = dyn_cast<RecordType>(type))
1071 if (
const auto *RD = dyn_cast<CXXRecordDecl>(RT->getDecl()))
1072 if (RD->hasMutableFields() || !RD->isTrivial())
1093 if (
const auto *ref = dyn_cast<ReferenceType>(type)) {
1114 if (isa<ParmVarDecl>(value)) {
1116 }
else if (
auto *var = dyn_cast<VarDecl>(value)) {
1118 }
else if (isa<EnumConstantDecl>(value)) {
1126 bool resultIsReference;
1132 resultIsReference =
false;
1133 resultType = refExpr->
getType();
1138 resultIsReference =
true;
1139 resultType = value->
getType();
1151 llvm::Constant *
C = CGM.EmitConstantValue(result.
Val, resultType,
this);
1155 if (isa<VarDecl>(value)) {
1156 if (!getContext().DeclMustBeEmitted(cast<VarDecl>(value)))
1157 EmitDeclRefExprDbgValue(refExpr, C);
1159 assert(isa<EnumConstantDecl>(value));
1160 EmitDeclRefExprDbgValue(refExpr, C);
1164 if (resultIsReference)
1165 return ConstantEmission::forReference(C);
1167 return ConstantEmission::forValue(C);
1184 return ET->getDecl()->getIntegerType()->isBooleanType();
1193 llvm::APInt &Min, llvm::APInt &
End,
1196 bool IsRegularCPlusPlusEnum = CGF.
getLangOpts().CPlusPlus && StrictEnums &&
1199 if (!IsBool && !IsRegularCPlusPlusEnum)
1208 unsigned Bitwidth = LTy->getScalarSizeInBits();
1212 if (NumNegativeBits) {
1213 unsigned NumBits = std::max(NumNegativeBits, NumPositiveBits + 1);
1214 assert(NumBits <= Bitwidth);
1215 End = llvm::APInt(Bitwidth, 1) << (NumBits - 1);
1218 assert(NumPositiveBits <= Bitwidth);
1219 End = llvm::APInt(Bitwidth, 1) << NumPositiveBits;
1220 Min = llvm::APInt(Bitwidth, 0);
1226 llvm::MDNode *CodeGenFunction::getRangeForLoadFromType(
QualType Ty) {
1227 llvm::APInt Min,
End;
1229 CGM.getCodeGenOpts().StrictEnums))
1232 llvm::MDBuilder MDHelper(getLLVMContext());
1233 return MDHelper.createRange(Min, End);
1240 llvm::MDNode *TBAAInfo,
1242 uint64_t TBAAOffset,
1243 bool isNontemporal) {
1248 const auto *VTy = cast<llvm::VectorType>(EltTy);
1251 if (VTy->getNumElements() == 3) {
1254 llvm::VectorType *vec4Ty = llvm::VectorType::get(VTy->getElementType(),
1256 Address Cast =
Builder.CreateElementBitCast(Addr, vec4Ty,
"castToVec4");
1261 V =
Builder.CreateShuffleVector(V, llvm::UndefValue::get(vec4Ty),
1262 {0, 1, 2},
"extractVec");
1263 return EmitFromMemory(V, Ty);
1268 if (Ty->
isAtomicType() || typeIsSuitableForInlineAtomic(Ty, Volatile)) {
1270 LValue::MakeAddr(Addr, Ty, getContext(), AlignSource, TBAAInfo);
1271 return EmitAtomicLoad(lvalue, Loc).getScalarVal();
1274 llvm::LoadInst *Load =
Builder.CreateLoad(Addr, Volatile);
1275 if (isNontemporal) {
1276 llvm::MDNode *
Node = llvm::MDNode::get(
1277 Load->getContext(), llvm::ConstantAsMetadata::get(
Builder.getInt32(1)));
1278 Load->setMetadata(CGM.getModule().getMDKindID(
"nontemporal"),
Node);
1281 llvm::MDNode *TBAAPath = CGM.getTBAAStructTagInfo(TBAABaseType, TBAAInfo,
1284 CGM.DecorateInstructionWithTBAA(Load, TBAAPath,
1288 bool NeedsBoolCheck =
1290 bool NeedsEnumCheck =
1292 if (NeedsBoolCheck || NeedsEnumCheck) {
1294 llvm::APInt Min,
End;
1299 Check =
Builder.CreateICmpULE(
1300 Load, llvm::ConstantInt::get(getLLVMContext(), End));
1303 Load, llvm::ConstantInt::get(getLLVMContext(), End));
1305 Load, llvm::ConstantInt::get(getLLVMContext(), Min));
1306 Check =
Builder.CreateAnd(Upper, Lower);
1308 llvm::Constant *StaticArgs[] = {
1309 EmitCheckSourceLocation(Loc),
1310 EmitCheckTypeDescriptor(Ty)
1312 SanitizerMask Kind = NeedsEnumCheck ? SanitizerKind::Enum : SanitizerKind::Bool;
1313 EmitCheck(std::make_pair(Check, Kind),
"load_invalid_value", StaticArgs,
1314 EmitCheckValue(Load));
1316 }
else if (CGM.getCodeGenOpts().OptimizationLevel > 0)
1317 if (llvm::MDNode *RangeInfo = getRangeForLoadFromType(Ty))
1318 Load->setMetadata(llvm::LLVMContext::MD_range, RangeInfo);
1320 return EmitFromMemory(Load, Ty);
1328 if (Value->getType()->isIntegerTy(1))
1329 return Builder.CreateZExt(Value, ConvertTypeForMem(Ty),
"frombool");
1330 assert(Value->getType()->isIntegerTy(getContext().
getTypeSize(Ty)) &&
1331 "wrong value rep of bool");
1340 assert(Value->getType()->isIntegerTy(getContext().
getTypeSize(Ty)) &&
1341 "wrong value rep of bool");
1342 return Builder.CreateTrunc(Value,
Builder.getInt1Ty(),
"tobool");
1351 llvm::MDNode *TBAAInfo,
1352 bool isInit,
QualType TBAABaseType,
1353 uint64_t TBAAOffset,
1354 bool isNontemporal) {
1358 llvm::Type *SrcTy = Value->getType();
1359 auto *VecTy = cast<llvm::VectorType>(SrcTy);
1361 if (VecTy->getNumElements() == 3) {
1363 llvm::Constant *Mask[] = {
Builder.getInt32(0),
Builder.getInt32(1),
1365 llvm::UndefValue::get(
Builder.getInt32Ty())};
1366 llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
1367 Value =
Builder.CreateShuffleVector(Value,
1368 llvm::UndefValue::get(VecTy),
1369 MaskV,
"extractVec");
1370 SrcTy = llvm::VectorType::get(VecTy->getElementType(), 4);
1373 Addr =
Builder.CreateElementBitCast(Addr, SrcTy,
"storetmp");
1377 Value = EmitToMemory(Value, Ty);
1380 (!isInit && typeIsSuitableForInlineAtomic(Ty, Volatile))) {
1381 EmitAtomicStore(RValue::get(Value),
1382 LValue::MakeAddr(Addr, Ty, getContext(),
1383 AlignSource, TBAAInfo),
1388 llvm::StoreInst *
Store =
Builder.CreateStore(Value, Addr, Volatile);
1389 if (isNontemporal) {
1390 llvm::MDNode *
Node =
1391 llvm::MDNode::get(Store->getContext(),
1392 llvm::ConstantAsMetadata::get(
Builder.getInt32(1)));
1393 Store->setMetadata(CGM.getModule().getMDKindID(
"nontemporal"),
Node);
1396 llvm::MDNode *TBAAPath = CGM.getTBAAStructTagInfo(TBAABaseType, TBAAInfo,
1399 CGM.DecorateInstructionWithTBAA(Store, TBAAPath,
1419 return RValue::get(CGM.getObjCRuntime().EmitObjCWeakRead(*
this,
1424 if (!getLangOpts().ObjCAutoRefCount) {
1425 return RValue::get(EmitARCLoadWeak(LV.
getAddress()));
1430 Object = EmitObjCConsumeObject(LV.
getType(), Object);
1431 return RValue::get(Object);
1438 return RValue::get(EmitLoadOfScalar(LV, Loc));
1451 return EmitLoadOfExtVectorElementLValue(LV);
1455 return EmitLoadOfGlobalRegLValue(LV);
1457 assert(LV.
isBitField() &&
"Unknown LValue type!");
1458 return EmitLoadOfBitfieldLValue(LV);
1465 llvm::Type *ResLTy = ConvertType(LV.
getType());
1474 Val =
Builder.CreateShl(Val, HighBits,
"bf.shl");
1475 if (Info.
Offset + HighBits)
1476 Val =
Builder.CreateAShr(Val, Info.
Offset + HighBits,
"bf.ashr");
1487 return RValue::get(Val);
1502 unsigned InIdx = getAccessedFieldNo(0, Elts);
1503 llvm::Value *Elt = llvm::ConstantInt::get(SizeTy, InIdx);
1504 return RValue::get(
Builder.CreateExtractElement(Vec, Elt));
1511 for (
unsigned i = 0; i != NumResultElts; ++i)
1512 Mask.push_back(
Builder.getInt32(getAccessedFieldNo(i, Elts)));
1514 llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
1515 Vec =
Builder.CreateShuffleVector(Vec, llvm::UndefValue::get(Vec->getType()),
1517 return RValue::get(Vec);
1525 llvm::Type *VectorElementTy = CGM.getTypes().ConvertType(EQT);
1527 Address CastToPointerElement =
1528 Builder.CreateElementBitCast(VectorAddress, VectorElementTy,
1529 "conv.ptr.element");
1532 unsigned ix = getAccessedFieldNo(0, Elts);
1535 Builder.CreateConstInBoundsGEP(CastToPointerElement, ix,
1536 getContext().getTypeSizeInChars(EQT),
1539 return VectorBasePtrPlusIx;
1545 "Bad type for register variable");
1546 llvm::MDNode *RegName = cast<llvm::MDNode>(
1547 cast<llvm::MetadataAsValue>(LV.
getGlobalReg())->getMetadata());
1550 llvm::Type *OrigTy = CGM.getTypes().ConvertType(LV.
getType());
1551 llvm::Type *Ty = OrigTy;
1552 if (OrigTy->isPointerTy())
1553 Ty = CGM.getTypes().getDataLayout().getIntPtrType(OrigTy);
1554 llvm::Type *Types[] = { Ty };
1556 llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::read_register, Types);
1558 F, llvm::MetadataAsValue::get(Ty->getContext(), RegName));
1559 if (OrigTy->isPointerTy())
1560 Call =
Builder.CreateIntToPtr(Call, OrigTy);
1561 return RValue::get(Call);
1585 return EmitStoreThroughExtVectorComponentLValue(Src, Dst);
1588 return EmitStoreThroughGlobalRegLValue(Src, Dst);
1590 assert(Dst.
isBitField() &&
"Unknown LValue type");
1591 return EmitStoreThroughBitfieldLValue(Src, Dst);
1598 llvm_unreachable(
"present but none");
1613 Src = RValue::get(EmitObjCExtendObjectLifetime(Dst.
getType(),
1624 CGM.getObjCRuntime().EmitObjCWeakAssign(*
this, src, LvalueDst);
1634 llvm::Type *ResultType = IntPtrTy;
1637 RHS =
Builder.CreatePtrToInt(RHS, ResultType,
"sub.ptr.rhs.cast");
1640 "sub.ptr.lhs.cast");
1642 CGM.getObjCRuntime().EmitObjCIvarAssign(*
this, src, dst,
1645 CGM.getObjCRuntime().EmitObjCGlobalAssign(*
this, src, LvalueDst,
1649 CGM.getObjCRuntime().EmitObjCStrongCastAssign(*
this, src, LvalueDst);
1653 assert(Src.
isScalar() &&
"Can't emit an agg store with this method");
1657 void CodeGenFunction::EmitStoreThroughBitfieldLValue(
RValue Src,
LValue Dst,
1660 llvm::Type *ResLTy = ConvertTypeForMem(Dst.
getType());
1667 SrcVal =
Builder.CreateIntCast(SrcVal, Ptr.getElementType(),
1680 SrcVal =
Builder.CreateAnd(SrcVal,
1696 SrcVal =
Builder.CreateOr(Val, SrcVal,
"bf.set");
1698 assert(Info.
Offset == 0);
1713 ResultVal =
Builder.CreateShl(ResultVal, HighBits,
"bf.result.shl");
1714 ResultVal =
Builder.CreateAShr(ResultVal, HighBits,
"bf.result.ashr");
1720 *Result = EmitFromMemory(ResultVal, Dst.
getType());
1724 void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(
RValue Src,
1735 unsigned NumSrcElts = VTy->getNumElements();
1736 unsigned NumDstElts =
1737 cast<llvm::VectorType>(Vec->getType())->getNumElements();
1738 if (NumDstElts == NumSrcElts) {
1743 for (
unsigned i = 0; i != NumSrcElts; ++i)
1744 Mask[getAccessedFieldNo(i, Elts)] =
Builder.getInt32(i);
1746 llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
1747 Vec =
Builder.CreateShuffleVector(SrcVal,
1748 llvm::UndefValue::get(Vec->getType()),
1750 }
else if (NumDstElts > NumSrcElts) {
1756 for (
unsigned i = 0; i != NumSrcElts; ++i)
1757 ExtMask.push_back(
Builder.getInt32(i));
1758 ExtMask.resize(NumDstElts, llvm::UndefValue::get(Int32Ty));
1759 llvm::Value *ExtMaskV = llvm::ConstantVector::get(ExtMask);
1761 Builder.CreateShuffleVector(SrcVal,
1762 llvm::UndefValue::get(SrcVal->getType()),
1766 for (
unsigned i = 0; i != NumDstElts; ++i)
1767 Mask.push_back(
Builder.getInt32(i));
1772 if (getAccessedFieldNo(NumSrcElts - 1, Elts) == Mask.size())
1776 for (
unsigned i = 0; i != NumSrcElts; ++i)
1777 Mask[getAccessedFieldNo(i, Elts)] =
Builder.getInt32(i+NumDstElts);
1778 llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
1779 Vec =
Builder.CreateShuffleVector(Vec, ExtSrcVal, MaskV);
1782 llvm_unreachable(
"unexpected shorten vector length");
1786 unsigned InIdx = getAccessedFieldNo(0, Elts);
1787 llvm::Value *Elt = llvm::ConstantInt::get(SizeTy, InIdx);
1788 Vec =
Builder.CreateInsertElement(Vec, SrcVal, Elt);
1796 void CodeGenFunction::EmitStoreThroughGlobalRegLValue(
RValue Src,
LValue Dst) {
1798 "Bad type for register variable");
1799 llvm::MDNode *RegName = cast<llvm::MDNode>(
1800 cast<llvm::MetadataAsValue>(Dst.
getGlobalReg())->getMetadata());
1801 assert(RegName &&
"Register LValue is not metadata");
1804 llvm::Type *OrigTy = CGM.getTypes().ConvertType(Dst.
getType());
1805 llvm::Type *Ty = OrigTy;
1806 if (OrigTy->isPointerTy())
1807 Ty = CGM.getTypes().getDataLayout().getIntPtrType(OrigTy);
1808 llvm::Type *Types[] = { Ty };
1810 llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::write_register, Types);
1812 if (OrigTy->isPointerTy())
1813 Value =
Builder.CreatePtrToInt(Value, Ty);
1815 F, {llvm::MetadataAsValue::get(Ty->getContext(), RegName), Value});
1823 bool IsMemberAccess=
false) {
1827 if (isa<ObjCIvarRefExpr>(E)) {
1840 auto *Exp = cast<ObjCIvarRefExpr>(
const_cast<Expr *
>(
E));
1846 if (
const auto *Exp = dyn_cast<DeclRefExpr>(E)) {
1847 if (
const auto *VD = dyn_cast<VarDecl>(Exp->getDecl())) {
1848 if (VD->hasGlobalStorage()) {
1857 if (
const auto *Exp = dyn_cast<UnaryOperator>(E)) {
1862 if (
const auto *Exp = dyn_cast<ParenExpr>(E)) {
1876 if (
const auto *Exp = dyn_cast<GenericSelectionExpr>(E)) {
1881 if (
const auto *Exp = dyn_cast<ImplicitCastExpr>(E)) {
1886 if (
const auto *Exp = dyn_cast<CStyleCastExpr>(E)) {
1891 if (
const auto *Exp = dyn_cast<ObjCBridgedCastExpr>(E)) {
1896 if (
const auto *Exp = dyn_cast<ArraySubscriptExpr>(E)) {
1909 if (
const auto *Exp = dyn_cast<MemberExpr>(E)) {
1921 StringRef
Name = StringRef()) {
1922 unsigned AS = cast<llvm::PointerType>(V->getType())->getAddressSpace();
1946 Address Addr = EmitLoadOfReference(RefAddr, RefTy, &Source);
2013 AsmLabelAttr *Asm = VD->
getAttr<AsmLabelAttr>();
2014 assert(Asm->getLabel().size() < 64-Name.size() &&
2015 "Register name too big");
2016 Name.append(Asm->getLabel());
2017 llvm::NamedMDNode *M =
2018 CGM.
getModule().getOrInsertNamedMetadata(Name);
2019 if (M->getNumOperands() == 0) {
2022 llvm::Metadata *Ops[] = {Str};
2029 llvm::MetadataAsValue::get(CGM.
getLLVMContext(), M->getOperand(0));
2030 return LValue::MakeGlobalReg(
Address(Ptr, Alignment), VD->
getType());
2037 if (
const auto *VD = dyn_cast<VarDecl>(ND)) {
2040 VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())
2045 const Expr *Init = VD->getAnyInitializer(VD);
2047 VD->isUsableInConstantExpressions(getContext()) &&
2048 VD->checkInitIsICE() &&
2051 LocalDeclMap.count(VD))) {
2052 llvm::Constant *Val =
2053 CGM.EmitConstantValue(*VD->evaluateValue(), VD->getType(),
this);
2054 assert(Val &&
"failed to emit reference constant expression");
2061 return MakeAddrLValue(
Address(Val, Alignment), T, AlignmentSource::Decl);
2066 if (
auto *FD = LambdaCaptureFields.lookup(VD))
2068 else if (CapturedStmtInfo) {
2069 auto it = LocalDeclMap.find(VD);
2070 if (it != LocalDeclMap.end()) {
2072 return EmitLoadOfReferenceLValue(it->second, RefTy);
2074 return MakeAddrLValue(it->second, T);
2078 CapturedStmtInfo->getContextValue());
2079 return MakeAddrLValue(
2081 CapLVal.
getType(), AlignmentSource::Decl);
2084 assert(isa<BlockDecl>(CurCodeDecl));
2085 Address addr = GetAddrOfBlockDecl(VD, VD->hasAttr<BlocksAttr>());
2086 return MakeAddrLValue(addr, T, AlignmentSource::Decl);
2093 assert((ND->
isUsed(
false) || !isa<VarDecl>(ND) ||
2095 "Should not use decl without marking it used!");
2097 if (ND->
hasAttr<WeakRefAttr>()) {
2098 const auto *VD = cast<ValueDecl>(ND);
2100 return MakeAddrLValue(Aliasee, T, AlignmentSource::Decl);
2103 if (
const auto *VD = dyn_cast<VarDecl>(ND)) {
2105 if (VD->hasLinkage() || VD->isStaticDataMember())
2108 Address addr = Address::invalid();
2111 auto iter = LocalDeclMap.find(VD);
2112 if (iter != LocalDeclMap.end()) {
2113 addr = iter->second;
2117 }
else if (VD->isStaticLocal()) {
2118 addr =
Address(CGM.getOrCreateStaticVarDecl(
2119 *VD, CGM.getLLVMLinkageVarDefinition(VD,
false)),
2120 getContext().getDeclAlign(VD));
2124 llvm_unreachable(
"DeclRefExpr for Decl not entered in LocalDeclMap?");
2129 if (getLangOpts().OpenMP && VD->hasAttr<OMPThreadPrivateDeclAttr>()) {
2131 *
this, VD, T, addr, getTypes().ConvertTypeForMem(VD->getType()),
2136 bool isBlockByref = VD->hasAttr<BlocksAttr>();
2138 addr = emitBlockByrefAddress(addr, VD);
2144 LV = EmitLoadOfReferenceLValue(addr, RefTy);
2146 LV = MakeAddrLValue(addr, T, AlignmentSource::Decl);
2149 bool isLocalStorage = VD->hasLocalStorage();
2151 bool NonGCable = isLocalStorage &&
2152 !VD->getType()->isReferenceType() &&
2159 bool isImpreciseLifetime =
2160 (isLocalStorage && !VD->hasAttr<ObjCPreciseLifetimeAttr>());
2161 if (isImpreciseLifetime)
2167 if (
const auto *FD = dyn_cast<FunctionDecl>(ND))
2170 llvm_unreachable(
"Unhandled DeclRefExpr");
2180 default: llvm_unreachable(
"Unknown unary operator lvalue!");
2183 assert(!T.
isNull() &&
"CodeGenFunction::EmitUnaryOpLValue: Illegal type");
2187 LValue LV = MakeAddrLValue(Addr, T, AlignSource);
2194 if (getLangOpts().ObjC1 &&
2203 assert(LV.
isSimple() &&
"real/imag on non-ordinary l-value");
2227 EmitComplexPrePostIncDec(E, LV, isInc,
true);
2229 EmitScalarPrePostIncDec(E, LV, isInc,
true);
2236 return MakeAddrLValue(CGM.GetAddrOfConstantStringFromLiteral(E),
2237 E->
getType(), AlignmentSource::Decl);
2241 return MakeAddrLValue(CGM.GetAddrOfConstantStringFromObjCEncode(E),
2242 E->
getType(), AlignmentSource::Decl);
2247 assert(SL !=
nullptr &&
"No StringLiteral name in PredefinedExpr");
2248 StringRef FnName = CurFn->getName();
2249 if (FnName.startswith(
"\01"))
2250 FnName = FnName.substr(1);
2251 StringRef NameItems[] = {
2253 std::string GVName = llvm::join(NameItems, NameItems + 2,
".");
2254 if (CurCodeDecl && isa<BlockDecl>(CurCodeDecl)) {
2255 auto C = CGM.GetAddrOfConstantCString(FnName, GVName.c_str());
2256 return MakeAddrLValue(
C, E->
getType(), AlignmentSource::Decl);
2258 auto C = CGM.GetAddrOfConstantStringFromLiteral(SL, GVName);
2259 return MakeAddrLValue(
C, E->
getType(), AlignmentSource::Decl);
2271 llvm::Constant *CodeGenFunction::EmitCheckTypeDescriptor(
QualType T) {
2273 if (llvm::Constant *
C = CGM.getTypeDescriptorFromMap(T))
2276 uint16_t TypeKind = -1;
2281 TypeInfo = (llvm::Log2_32(getContext().
getTypeSize(T)) << 1) |
2285 TypeInfo = getContext().getTypeSize(T);
2296 llvm::Constant *Components[] = {
2298 llvm::ConstantDataArray::getString(getLLVMContext(), Buffer)
2300 llvm::Constant *Descriptor = llvm::ConstantStruct::getAnon(Components);
2302 auto *GV =
new llvm::GlobalVariable(
2303 CGM.getModule(), Descriptor->getType(),
2304 true, llvm::GlobalVariable::PrivateLinkage, Descriptor);
2305 GV->setUnnamedAddr(
true);
2306 CGM.getSanitizerMetadata()->disableSanitizerForGlobal(GV);
2309 CGM.setTypeDescriptorInMap(T, GV);
2315 llvm::Type *TargetTy = IntPtrTy;
2319 if (V->getType()->isFloatingPointTy()) {
2320 unsigned Bits = V->getType()->getPrimitiveSizeInBits();
2321 if (Bits <= TargetTy->getIntegerBitWidth())
2322 V =
Builder.CreateBitCast(V, llvm::Type::getIntNTy(getLLVMContext(),
2327 if (V->getType()->isIntegerTy() &&
2328 V->getType()->getIntegerBitWidth() <= TargetTy->getIntegerBitWidth())
2329 return Builder.CreateZExt(V, TargetTy);
2332 if (!V->getType()->isPointerTy()) {
2333 Address Ptr = CreateDefaultAlignTempAlloca(V->getType());
2337 return Builder.CreatePtrToInt(V, TargetTy);
2353 PresumedLoc PLoc = getContext().getSourceManager().getPresumedLoc(Loc);
2355 auto FilenameGV = CGM.GetAddrOfConstantCString(PLoc.
getFilename(),
".src");
2356 CGM.getSanitizerMetadata()->disableSanitizerForGlobal(
2357 cast<llvm::GlobalVariable>(FilenameGV.getPointer()));
2358 Filename = FilenameGV.getPointer();
2362 Filename = llvm::Constant::getNullValue(Int8PtrTy);
2369 return llvm::ConstantStruct::getAnon(Data);
2386 assert(llvm::countPopulation(Kind) == 1);
2388 case SanitizerKind::Vptr:
2389 return CheckRecoverableKind::AlwaysRecoverable;
2390 case SanitizerKind::Return:
2391 case SanitizerKind::Unreachable:
2394 return CheckRecoverableKind::Recoverable;
2399 llvm::FunctionType *FnType,
2401 StringRef CheckName,
2403 llvm::BasicBlock *ContBB) {
2405 bool NeedsAbortSuffix =
2407 std::string FnName = (
"__ubsan_handle_" + CheckName +
2408 (NeedsAbortSuffix ?
"_abort" :
"")).str();
2410 !IsFatal || RecoverKind == CheckRecoverableKind::AlwaysRecoverable;
2412 llvm::AttrBuilder B;
2414 B.addAttribute(llvm::Attribute::NoReturn)
2415 .addAttribute(llvm::Attribute::NoUnwind);
2417 B.addAttribute(llvm::Attribute::UWTable);
2422 llvm::AttributeSet::FunctionIndex, B));
2425 HandlerCall->setDoesNotReturn();
2426 CGF.
Builder.CreateUnreachable();
2432 void CodeGenFunction::EmitCheck(
2433 ArrayRef<std::pair<llvm::Value *, SanitizerMask>> Checked,
2436 assert(IsSanitizerScope);
2437 assert(Checked.size() > 0);
2442 for (
int i = 0, n = Checked.size(); i < n; ++i) {
2446 CGM.getCodeGenOpts().SanitizeTrap.has(Checked[i].second)
2448 : CGM.getCodeGenOpts().SanitizeRecover.has(Checked[i].second)
2451 Cond = Cond ?
Builder.CreateAnd(Cond, Check) : Check;
2455 EmitTrapCheck(TrapCond);
2456 if (!FatalCond && !RecoverableCond)
2460 if (FatalCond && RecoverableCond)
2461 JointCond =
Builder.CreateAnd(FatalCond, RecoverableCond);
2463 JointCond = FatalCond ? FatalCond : RecoverableCond;
2467 assert(SanOpts.has(Checked[0].second));
2469 for (
int i = 1, n = Checked.size(); i < n; ++i) {
2471 "All recoverable kinds in a single check must be same!");
2472 assert(SanOpts.has(Checked[i].second));
2476 llvm::BasicBlock *Cont = createBasicBlock(
"cont");
2477 llvm::BasicBlock *Handlers = createBasicBlock(
"handler." + CheckName);
2478 llvm::Instruction *Branch =
Builder.CreateCondBr(JointCond, Cont, Handlers);
2481 llvm::MDBuilder MDHelper(getLLVMContext());
2482 llvm::MDNode *
Node = MDHelper.createBranchWeights((1U << 20) - 1, 1);
2483 Branch->setMetadata(llvm::LLVMContext::MD_prof, Node);
2484 EmitBlock(Handlers);
2487 llvm::Constant *Info = llvm::ConstantStruct::getAnon(StaticArgs);
2489 new llvm::GlobalVariable(CGM.getModule(), Info->getType(),
false,
2490 llvm::GlobalVariable::PrivateLinkage, Info);
2491 InfoPtr->setUnnamedAddr(
true);
2492 CGM.getSanitizerMetadata()->disableSanitizerForGlobal(InfoPtr);
2496 Args.reserve(DynamicArgs.size() + 1);
2497 ArgTypes.reserve(DynamicArgs.size() + 1);
2502 Args.push_back(
Builder.CreateBitCast(InfoPtr, Int8PtrTy));
2503 ArgTypes.push_back(Int8PtrTy);
2504 for (
size_t i = 0, n = DynamicArgs.size(); i != n; ++i) {
2505 Args.push_back(EmitCheckValue(DynamicArgs[i]));
2506 ArgTypes.push_back(IntPtrTy);
2509 llvm::FunctionType *FnType =
2510 llvm::FunctionType::get(CGM.VoidTy, ArgTypes,
false);
2512 if (!FatalCond || !RecoverableCond) {
2516 (FatalCond !=
nullptr), Cont);
2520 llvm::BasicBlock *NonFatalHandlerBB =
2521 createBasicBlock(
"non_fatal." + CheckName);
2522 llvm::BasicBlock *FatalHandlerBB = createBasicBlock(
"fatal." + CheckName);
2523 Builder.CreateCondBr(FatalCond, NonFatalHandlerBB, FatalHandlerBB);
2524 EmitBlock(FatalHandlerBB);
2527 EmitBlock(NonFatalHandlerBB);
2536 llvm::ConstantInt *TypeId,
2538 auto &Ctx = getLLVMContext();
2539 llvm::BasicBlock *Cont = createBasicBlock(
"cfi.cont");
2541 llvm::BasicBlock *CheckBB = createBasicBlock(
"cfi.slowpath");
2542 llvm::BranchInst *BI =
Builder.CreateCondBr(Cond, Cont, CheckBB);
2544 llvm::MDBuilder MDHelper(getLLVMContext());
2545 llvm::MDNode *
Node = MDHelper.createBranchWeights((1U << 20) - 1, 1);
2546 BI->setMetadata(llvm::LLVMContext::MD_prof, Node);
2550 llvm::Constant *SlowPathFn = CGM.getModule().getOrInsertFunction(
2552 llvm::FunctionType::get(
2553 llvm::Type::getVoidTy(Ctx),
2554 {llvm::Type::getInt64Ty(Ctx),
2555 llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(Ctx))},
2557 llvm::CallInst *CheckCall =
Builder.CreateCall(SlowPathFn, {TypeId, Ptr});
2558 CheckCall->setDoesNotThrow();
2564 llvm::BasicBlock *Cont = createBasicBlock(
"cont");
2568 if (!CGM.getCodeGenOpts().OptimizationLevel || !TrapBB) {
2569 TrapBB = createBasicBlock(
"trap");
2570 Builder.CreateCondBr(Checked, Cont, TrapBB);
2572 llvm::CallInst *TrapCall = EmitTrapCall(llvm::Intrinsic::trap);
2573 TrapCall->setDoesNotReturn();
2574 TrapCall->setDoesNotThrow();
2577 Builder.CreateCondBr(Checked, Cont, TrapBB);
2584 llvm::CallInst *TrapCall =
Builder.CreateCall(CGM.getIntrinsic(IntrID));
2586 if (!CGM.getCodeGenOpts().TrapFuncName.empty())
2587 TrapCall->addAttribute(llvm::AttributeSet::FunctionIndex,
2589 CGM.getCodeGenOpts().TrapFuncName);
2597 "Array to pointer decay must have array source type!");
2600 LValue LV = EmitLValue(E);
2601 Address Addr = LV.getAddress();
2602 if (AlignSource) *AlignSource = LV.getAlignmentSource();
2606 llvm::Type *NewTy = ConvertType(E->
getType());
2607 Addr =
Builder.CreateElementBitCast(Addr, NewTy);
2612 assert(isa<llvm::ArrayType>(Addr.getElementType()) &&
2613 "Expected pointer to array");
2618 return Builder.CreateElementBitCast(Addr, ConvertTypeForMem(EltType));
2630 const Expr *SubExpr = CE->getSubExpr();
2641 const llvm::Twine &name =
"arrayidx") {
2643 return CGF.
Builder.CreateInBoundsGEP(ptr, indices, name);
2645 return CGF.
Builder.CreateGEP(ptr, indices, name);
2654 if (
auto constantIdx = dyn_cast<llvm::ConstantInt>(idx)) {
2655 CharUnits offset = constantIdx->getZExtValue() * eltSize;
2676 const llvm::Twine &name =
"arrayidx") {
2679 for (
auto idx : indices.drop_back())
2680 assert(isa<llvm::ConstantInt>(idx) &&
2681 cast<llvm::ConstantInt>(idx)->isZero());
2697 return Address(eltPtr, eltAlign);
2707 if (SanOpts.has(SanitizerKind::ArrayBounds))
2708 EmitBoundsCheck(E, E->
getBase(), Idx, IdxTy, Accessed);
2713 !isa<ExtVectorElementExpr>(E->
getBase())) {
2716 assert(LHS.
isSimple() &&
"Can only subscript lvalue vectors here!");
2717 return LValue::MakeVectorElt(LHS.
getAddress(), Idx,
2725 if (Idx->getType() != IntPtrTy)
2726 Idx =
Builder.CreateIntCast(Idx, IntPtrTy, IdxSigned,
"idxprom");
2729 if (isa<ExtVectorElementExpr>(E->
getBase())) {
2731 Address Addr = EmitExtVectorElementLValue(LV);
2739 Address Addr = Address::invalid();
2741 getContext().getAsVariableArrayType(E->
getType())) {
2745 Addr = EmitPointerWithAlignment(E->
getBase(), &AlignSource);
2754 if (getLangOpts().isSignedOverflowDefined()) {
2755 Idx =
Builder.CreateMul(Idx, numElements);
2757 Idx =
Builder.CreateNSWMul(Idx, numElements);
2761 !getLangOpts().isSignedOverflowDefined());
2765 CharUnits InterfaceSize = getContext().getTypeSizeInChars(OIT);
2767 llvm::ConstantInt::get(Idx->getType(), InterfaceSize.
getQuantity());;
2772 Addr = EmitPointerWithAlignment(E->
getBase(), &AlignSource);
2778 llvm::Type *OrigBaseTy = Addr.
getType();
2779 Addr =
Builder.CreateElementBitCast(Addr, Int8Ty);
2786 Addr =
Address(EltPtr, EltAlign);
2789 Addr =
Builder.CreateBitCast(Addr, OrigBaseTy);
2795 assert(Array->getType()->isArrayType() &&
2796 "Array to pointer decay must have array source type!");
2800 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(Array))
2801 ArrayLV = EmitArraySubscriptExpr(ASE,
true);
2803 ArrayLV = EmitLValue(Array);
2809 !getLangOpts().isSignedOverflowDefined());
2810 AlignSource = ArrayLV.getAlignmentSource();
2813 Addr = EmitPointerWithAlignment(E->
getBase(), &AlignSource);
2815 !getLangOpts().isSignedOverflowDefined());
2818 LValue LV = MakeAddrLValue(Addr, E->
getType(), AlignSource);
2822 if (getLangOpts().ObjC1 &&
2831 bool IsLowerBound) {
2835 Base = EmitOMPArraySectionExpr(ASE, IsLowerBound);
2837 Base = EmitLValue(E->
getBase());
2841 if (
auto *AT = getContext().getAsArrayType(BaseTy))
2842 ResultExprTy = AT->getElementType();
2851 EmitScalarExpr(LowerBound), IntPtrTy,
2852 LowerBound->getType()->hasSignedIntegerRepresentation());
2854 Idx = llvm::ConstantInt::getNullValue(IntPtrTy);
2859 auto &
C = CGM.getContext();
2861 llvm::APSInt ConstLength;
2864 if (
Length->isIntegerConstantExpr(ConstLength,
C)) {
2865 ConstLength = ConstLength.zextOrTrunc(PointerWidthInBits);
2869 llvm::APSInt ConstLowerBound(PointerWidthInBits,
false);
2870 if (LowerBound && LowerBound->isIntegerConstantExpr(ConstLowerBound,
C)) {
2871 ConstLowerBound = ConstLowerBound.zextOrTrunc(PointerWidthInBits);
2872 LowerBound =
nullptr;
2876 else if (!LowerBound)
2879 if (
Length || LowerBound) {
2880 auto *LowerBoundVal =
2883 EmitScalarExpr(LowerBound), IntPtrTy,
2884 LowerBound->getType()->hasSignedIntegerRepresentation())
2885 : llvm::ConstantInt::get(IntPtrTy, ConstLowerBound);
2889 EmitScalarExpr(
Length), IntPtrTy,
2890 Length->getType()->hasSignedIntegerRepresentation())
2891 : llvm::ConstantInt::get(IntPtrTy, ConstLength);
2892 Idx =
Builder.CreateAdd(LowerBoundVal, LengthVal,
"lb_add_len",
2894 !getLangOpts().isSignedOverflowDefined());
2895 if (
Length && LowerBound) {
2897 Idx, llvm::ConstantInt::get(IntPtrTy, 1),
"idx_sub_1",
2898 false, !getLangOpts().isSignedOverflowDefined());
2901 Idx = llvm::ConstantInt::get(IntPtrTy, ConstLength + ConstLowerBound);
2904 if (
auto *VAT =
C.getAsVariableArrayType(BaseTy)) {
2905 Length = VAT->getSizeExpr();
2906 if (
Length->isIntegerConstantExpr(ConstLength,
C))
2909 auto *CAT =
C.getAsConstantArrayType(BaseTy);
2910 ConstLength = CAT->getSize();
2913 auto *LengthVal =
Builder.CreateIntCast(
2914 EmitScalarExpr(
Length), IntPtrTy,
2915 Length->getType()->hasSignedIntegerRepresentation());
2917 LengthVal, llvm::ConstantInt::get(IntPtrTy, 1),
"len_sub_1",
2918 false, !getLangOpts().isSignedOverflowDefined());
2920 ConstLength = ConstLength.zextOrTrunc(PointerWidthInBits);
2922 Idx = llvm::ConstantInt::get(IntPtrTy, ConstLength);
2929 QualType FixedSizeEltType = ResultExprTy;
2930 if (
auto *VLA = getContext().getAsVariableArrayType(ResultExprTy)) {
2939 if (getLangOpts().isSignedOverflowDefined()) {
2940 Idx =
Builder.CreateMul(Idx, numElements);
2943 Idx =
Builder.CreateNSWMul(Idx, numElements);
2946 }
else if (BaseTy->isConstantArrayType()) {
2948 llvm::Value *Zero = llvm::ConstantInt::getNullValue(IntPtrTy);
2951 if (getLangOpts().isSignedOverflowDefined())
2952 EltPtr =
Builder.CreateGEP(ArrayPtr, Args,
"arrayidx");
2954 EltPtr =
Builder.CreateInBoundsGEP(ArrayPtr, Args,
"arrayidx");
2957 if (getLangOpts().isSignedOverflowDefined())
2965 getContext().getTypeSizeInChars(FixedSizeEltType));
2968 LValue LV = MakeAddrLValue(
Address(EltPtr, EltAlign), ResultExprTy,
2986 Address Ptr = EmitPointerWithAlignment(E->
getBase(), &AlignSource);
2988 Base = MakeAddrLValue(Ptr, PT->getPointeeType(), AlignSource);
2989 Base.getQuals().removeObjCGCAttr();
2994 Base = EmitLValue(E->
getBase());
2998 "Result must be a vector");
3003 Builder.CreateStore(Vec, VecMem);
3005 AlignmentSource::Decl);
3016 llvm::Constant *CV =
3017 llvm::ConstantDataVector::get(getLLVMContext(), Indices);
3021 assert(Base.
isExtVectorElt() &&
"Can only subscript lvalue vec elts here!");
3026 for (
unsigned i = 0, e = Indices.size(); i != e; ++i)
3027 CElts.push_back(BaseElts->getAggregateElement(Indices[i]));
3028 llvm::Constant *CV = llvm::ConstantVector::get(CElts);
3040 Address Addr = EmitPointerWithAlignment(BaseExpr, &AlignSource);
3043 BaseLV = MakeAddrLValue(Addr, PtrTy, AlignSource);
3045 BaseLV = EmitCheckedLValue(BaseExpr, TCK_MemberAccess);
3048 if (
auto *Field = dyn_cast<FieldDecl>(ND)) {
3049 LValue LV = EmitLValueForField(BaseLV, Field);
3054 if (
auto *VD = dyn_cast<VarDecl>(ND))
3057 if (
const auto *FD = dyn_cast<FunctionDecl>(ND))
3060 llvm_unreachable(
"Unhandled member declaration!");
3066 assert(cast<CXXMethodDecl>(CurCodeDecl)->getParent()->isLambda());
3067 assert(cast<CXXMethodDecl>(CurCodeDecl)->getParent() == Field->
getParent());
3069 getContext().getTagDeclType(Field->
getParent());
3070 LValue LambdaLV = MakeNaturalAlignAddrLValue(CXXABIThisValue, LambdaTagType);
3071 return EmitLValueForField(LambdaLV, Field);
3091 "LLVM field at index zero had non-zero offset?");
3108 CGM.getTypes().getCGRecordLayout(field->
getParent());
3117 llvm::Type *FieldIntTy =
3118 llvm::Type::getIntNTy(getLLVMContext(), Info.
StorageSize);
3120 Addr =
Builder.CreateElementBitCast(Addr, FieldIntTy);
3124 return LValue::MakeBitfield(Addr, Info, fieldType, fieldAlignSource);
3130 bool mayAlias = rec->
hasAttr<MayAliasAttr>();
3134 bool TBAAPath = CGM.getCodeGenOpts().StructPathTBAA;
3146 llvm::LoadInst *load =
Builder.CreateLoad(addr,
"ref");
3151 if (CGM.shouldUseTBAA()) {
3154 tbaa = CGM.getTBAAInfo(getContext().CharTy);
3156 tbaa = CGM.getTBAAInfo(type);
3158 CGM.DecorateInstructionWithTBAA(load, tbaa);
3165 getNaturalTypeAlignment(type, &fieldAlignSource,
true);
3166 addr =
Address(load, alignment);
3179 addr =
Builder.CreateElementBitCast(addr,
3180 CGM.getTypes().ConvertTypeForMem(type),
3183 if (field->
hasAttr<AnnotateAttr>())
3184 addr = EmitFieldAnnotations(field, addr);
3186 LValue LV = MakeAddrLValue(addr, type, fieldAlignSource);
3190 getContext().getASTRecordLayout(field->
getParent());
3196 getContext().getCharWidth());
3207 LV.
setTBAAInfo(CGM.getTBAAInfo(getContext().CharTy));
3218 return EmitLValueForField(Base, Field);
3223 llvm::Type *llvmType = ConvertTypeForMem(FieldType);
3228 return MakeAddrLValue(V, FieldType, FieldAlignSource);
3234 return MakeAddrLValue(GlobalPtr, E->
getType(), AlignmentSource::Decl);
3238 EmitVariablyModifiedType(E->
getType());
3240 Address DeclPtr = CreateMemTemp(E->
getType(),
".compoundliteral");
3253 return EmitAggExprToLValue(E);
3256 assert(E->
getNumInits() == 1 &&
"reference init with multiple values");
3257 return EmitLValue(E->
getInit(0));
3264 const Expr *Operand) {
3265 if (
auto *ThrowExpr = dyn_cast<CXXThrowExpr>(Operand->
IgnoreParens())) {
3277 assert(hasAggregateEvaluationKind(expr->
getType()) &&
3278 "Unexpected conditional operator!");
3279 return EmitAggExprToLValue(expr);
3286 if (ConstantFoldsToSimpleInteger(condExpr, CondExprBool)) {
3288 if (!CondExprBool) std::swap(live, dead);
3290 if (!ContainsLabel(dead)) {
3293 incrementProfileCounter(expr);
3294 return EmitLValue(live);
3298 llvm::BasicBlock *lhsBlock = createBasicBlock(
"cond.true");
3299 llvm::BasicBlock *rhsBlock = createBasicBlock(
"cond.false");
3300 llvm::BasicBlock *contBlock = createBasicBlock(
"cond.end");
3303 EmitBranchOnBoolExpr(condExpr, lhsBlock, rhsBlock, getProfileCount(expr));
3306 EmitBlock(lhsBlock);
3307 incrementProfileCounter(expr);
3313 if (lhs && !lhs->isSimple())
3314 return EmitUnsupportedLValue(expr,
"conditional operator");
3316 lhsBlock =
Builder.GetInsertBlock();
3321 EmitBlock(rhsBlock);
3326 if (rhs && !rhs->isSimple())
3327 return EmitUnsupportedLValue(expr,
"conditional operator");
3328 rhsBlock =
Builder.GetInsertBlock();
3330 EmitBlock(contBlock);
3333 llvm::PHINode *phi =
Builder.CreatePHI(lhs->getPointer()->getType(),
3335 phi->addIncoming(lhs->getPointer(), lhsBlock);
3336 phi->addIncoming(rhs->getPointer(), rhsBlock);
3337 Address result(phi, std::min(lhs->getAlignment(), rhs->getAlignment()));
3339 std::max(lhs->getAlignmentSource(), rhs->getAlignmentSource());
3340 return MakeAddrLValue(result, expr->
getType(), alignSource);
3342 assert((lhs || rhs) &&
3343 "both operands of glvalue conditional are throw-expressions?");
3344 return lhs ? *lhs : *rhs;
3395 return EmitUnsupportedLValue(E,
"unexpected cast lvalue");
3398 llvm_unreachable(
"dependent cast kind in IR gen!");
3401 llvm_unreachable(
"builtin functions are handled elsewhere");
3406 return EmitAggExprToLValue(E);
3411 const auto *DCE = cast<CXXDynamicCastExpr>(
E);
3412 return MakeNaturalAlignAddrLValue(EmitDynamicCast(V, DCE), E->
getType());
3427 auto *DerivedClassDecl = cast<CXXRecordDecl>(DerivedClassTy->
getDecl());
3430 Address This = LV.getAddress();
3437 return MakeAddrLValue(Base, E->
getType(), LV.getAlignmentSource());
3440 return EmitAggExprToLValue(E);
3443 auto *DerivedClassDecl = cast<CXXRecordDecl>(DerivedClassTy->
getDecl());
3449 GetAddressOfDerivedClass(LV.getAddress(), DerivedClassDecl,
3455 if (sanitizePerformTypeCheck())
3456 EmitTypeCheck(TCK_DowncastReference, E->
getExprLoc(),
3457 Derived.getPointer(), E->
getType());
3459 if (SanOpts.has(SanitizerKind::CFIDerivedCast))
3460 EmitVTablePtrCheckForCast(E->
getType(), Derived.getPointer(),
3462 CFITCK_DerivedCast, E->getLocStart());
3464 return MakeAddrLValue(Derived, E->
getType(), LV.getAlignmentSource());
3468 const auto *CE = cast<ExplicitCastExpr>(
E);
3470 CGM.EmitExplicitCastExprType(CE,
this);
3473 ConvertType(CE->getTypeAsWritten()));
3475 if (SanOpts.has(SanitizerKind::CFIUnrelatedCast))
3476 EmitVTablePtrCheckForCast(E->
getType(), V.getPointer(),
3478 CFITCK_UnrelatedCast, E->getLocStart());
3489 llvm_unreachable(
"NULL to OpenCL event lvalue cast is not valid");
3492 llvm_unreachable(
"Unhandled lvalue cast kind?");
3496 assert(OpaqueValueMappingData::shouldBindAsLValue(e));
3497 return getOpaqueLValueMapping(e);
3504 LValue FieldLV = EmitLValueForField(LV, FD);
3505 switch (getEvaluationKind(FT)) {
3507 return RValue::getComplex(EmitLoadOfComplex(FieldLV, Loc));
3511 return EmitLoadOfLValue(FieldLV, Loc);
3513 llvm_unreachable(
"bad evaluation kind");
3524 return EmitBlockCallExpr(E, ReturnValue);
3526 if (
const auto *CE = dyn_cast<CXXMemberCallExpr>(E))
3527 return EmitCXXMemberCallExpr(CE, ReturnValue);
3529 if (
const auto *CE = dyn_cast<CUDAKernelCallExpr>(E))
3530 return EmitCUDAKernelCallExpr(CE, ReturnValue);
3533 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl)) {
3534 if (
unsigned builtinID = FD->getBuiltinID())
3535 return EmitBuiltinExpr(FD, builtinID, E, ReturnValue);
3538 if (
const auto *CE = dyn_cast<CXXOperatorCallExpr>(E))
3539 if (
const CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>(TargetDecl))
3540 return EmitCXXOperatorMemberCallExpr(CE, MD, ReturnValue);
3542 if (
const auto *PseudoDtor =
3544 QualType DestroyedType = PseudoDtor->getDestroyedType();
3549 Expr *BaseExpr = PseudoDtor->getBase();
3550 Address BaseValue = Address::invalid();
3554 if (PseudoDtor->isArrow()) {
3555 BaseValue = EmitPointerWithAlignment(BaseExpr);
3559 LValue BaseLV = EmitLValue(BaseExpr);
3572 EmitARCRelease(
Builder.CreateLoad(BaseValue,
3573 PseudoDtor->getDestroyedType().isVolatileQualified()),
3578 EmitARCDestroyWeak(BaseValue);
3590 return RValue::get(
nullptr);
3601 EmitIgnoredExpr(E->
getLHS());
3602 EnsureInsertPoint();
3603 return EmitLValue(E->
getRHS());
3608 return EmitPointerToDataMemberBinaryExpr(E);
3615 switch (getEvaluationKind(E->
getType())) {
3619 return EmitARCStoreStrong(E,
false).first;
3622 return EmitARCStoreAutoreleasing(E).first;
3633 EmitStoreThroughLValue(RV, LV);
3638 return EmitComplexAssignmentLValue(E);
3641 return EmitAggExprToLValue(E);
3643 llvm_unreachable(
"bad evaluation kind");
3647 RValue RV = EmitCallExpr(E);
3651 AlignmentSource::Decl);
3654 "Can't have a scalar return unless the return type is a "
3662 return EmitAggExprToLValue(E);
3667 &&
"binding l-value to type which needs a temporary");
3669 EmitCXXConstructExpr(E, Slot);
3670 return MakeAddrLValue(Slot.getAddress(), E->
getType(),
3671 AlignmentSource::Decl);
3676 return MakeNaturalAlignAddrLValue(EmitCXXTypeidExpr(E), E->
getType());
3680 return Builder.CreateElementBitCast(CGM.GetAddrOfUuidDescriptor(E),
3685 return MakeAddrLValue(EmitCXXUuidofExpr(E), E->
getType(),
3686 AlignmentSource::Decl);
3696 AlignmentSource::Decl);
3702 EmitLambdaExpr(E, Slot);
3704 AlignmentSource::Decl);
3708 RValue RV = EmitObjCMessageExpr(E);
3712 AlignmentSource::Decl);
3715 "Can't have a scalar return unless the return type is a "
3723 CGM.getObjCRuntime().GetAddrOfSelector(*
this, E->
getSelector());
3724 return MakeAddrLValue(V, E->
getType(), AlignmentSource::Decl);
3729 return CGM.getObjCRuntime().EmitIvarOffset(*
this, Interface, Ivar);
3735 unsigned CVRQualifiers) {
3736 return CGM.getObjCRuntime().EmitObjCValueForIvar(*
this, ObjectTy, BaseValue,
3737 Ivar, CVRQualifiers);
3747 BaseValue = EmitScalarExpr(BaseExpr);
3751 LValue BaseLV = EmitLValue(BaseExpr);
3753 ObjectTy = BaseExpr->
getType();
3758 EmitLValueForIvar(ObjectTy, BaseValue, E->
getDecl(),
3766 RValue RV = EmitAnyExprToTemp(E);
3768 AlignmentSource::Decl);
3777 "Call must have function pointer type!");
3788 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl))
3795 if (TargetDecl->hasAttr<AlwaysInlineAttr>() &&
3796 TargetDecl->hasAttr<TargetAttr>())
3797 checkTargetFeatures(E, FD);
3801 const auto *FnType =
3802 cast<FunctionType>(cast<PointerType>(CalleeType)->getPointeeType());
3804 if (getLangOpts().CPlusPlus && SanOpts.has(SanitizerKind::Function) &&
3805 (!TargetDecl || !isa<FunctionDecl>(TargetDecl))) {
3806 if (llvm::Constant *PrefixSig =
3807 CGM.getTargetCodeGenInfo().getUBSanFunctionSignature(CGM)) {
3809 llvm::Constant *FTRTTIConst =
3810 CGM.GetAddrOfRTTIDescriptor(
QualType(FnType, 0),
true);
3811 llvm::Type *PrefixStructTyElems[] = {
3812 PrefixSig->getType(),
3813 FTRTTIConst->getType()
3815 llvm::StructType *PrefixStructTy = llvm::StructType::get(
3816 CGM.getLLVMContext(), PrefixStructTyElems,
true);
3819 Callee, llvm::PointerType::getUnqual(PrefixStructTy));
3821 Builder.CreateConstGEP2_32(PrefixStructTy, CalleePrefixStruct, 0, 0);
3823 Builder.CreateAlignedLoad(CalleeSigPtr, getIntAlign());
3826 llvm::BasicBlock *Cont = createBasicBlock(
"cont");
3827 llvm::BasicBlock *TypeCheck = createBasicBlock(
"typecheck");
3828 Builder.CreateCondBr(CalleeSigMatch, TypeCheck, Cont);
3830 EmitBlock(TypeCheck);
3832 Builder.CreateConstGEP2_32(PrefixStructTy, CalleePrefixStruct, 0, 1);
3834 Builder.CreateAlignedLoad(CalleeRTTIPtr, getPointerAlign());
3836 Builder.CreateICmpEQ(CalleeRTTI, FTRTTIConst);
3837 llvm::Constant *StaticData[] = {
3839 EmitCheckTypeDescriptor(CalleeType)
3841 EmitCheck(std::make_pair(CalleeRTTIMatch, SanitizerKind::Function),
3842 "function_type_mismatch", StaticData, Callee);
3851 if (SanOpts.has(SanitizerKind::CFIICall) &&
3852 (!TargetDecl || !isa<FunctionDecl>(TargetDecl))) {
3855 llvm::Metadata *MD = CGM.CreateMetadataIdentifierForType(
QualType(FnType, 0));
3856 llvm::Value *BitSetName = llvm::MetadataAsValue::get(getLLVMContext(), MD);
3860 Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::bitset_test),
3861 {CastedCallee, BitSetName});
3863 auto TypeId = CGM.CreateCfiIdForTypeMetadata(MD);
3864 if (CGM.getCodeGenOpts().SanitizeCfiCrossDso && TypeId) {
3865 EmitCfiSlowPathCheck(BitSetTest, TypeId, CastedCallee);
3867 llvm::Constant *StaticData[] = {
3869 EmitCheckTypeDescriptor(
QualType(FnType, 0)),
3871 EmitCheck(std::make_pair(BitSetTest, SanitizerKind::CFIICall),
3872 "cfi_bad_icall", StaticData, CastedCallee);
3878 Args.
add(RValue::get(
Builder.CreateBitCast(Chain, CGM.VoidPtrTy)),
3879 CGM.getContext().VoidPtrTy);
3880 EmitCallArgs(Args, dyn_cast<FunctionProtoType>(FnType), E->
arguments(),
3883 const CGFunctionInfo &FnInfo = CGM.getTypes().arrangeFreeFunctionCall(
3884 Args, FnType, Chain);
3906 if (isa<FunctionNoProtoType>(FnType) || Chain) {
3907 llvm::Type *CalleeTy = getTypes().GetFunctionType(FnInfo);
3908 CalleeTy = CalleeTy->getPointerTo();
3909 Callee =
Builder.CreateBitCast(Callee, CalleeTy,
"callee.knr.cast");
3912 return EmitCall(FnInfo, Callee, ReturnValue, Args,
3918 Address BaseAddr = Address::invalid();
3920 BaseAddr = EmitPointerWithAlignment(E->
getLHS());
3922 BaseAddr = EmitLValue(E->
getLHS()).getAddress();
3932 EmitCXXMemberDataPointerAddress(E, BaseAddr, OffsetV, MPT,
3935 return MakeAddrLValue(MemberAddr, MPT->getPointeeType(), AlignSource);
3943 LValue lvalue = MakeAddrLValue(addr, type, AlignmentSource::Decl);
3944 switch (getEvaluationKind(type)) {
3946 return RValue::getComplex(EmitLoadOfComplex(lvalue, loc));
3950 return RValue::get(EmitLoadOfScalar(lvalue, loc));
3952 llvm_unreachable(
"bad evaluation kind");
3955 void CodeGenFunction::SetFPAccuracy(
llvm::Value *Val,
float Accuracy) {
3956 assert(Val->getType()->isFPOrFPVectorTy());
3957 if (Accuracy == 0.0 || !isa<llvm::Instruction>(Val))
3960 llvm::MDBuilder MDHelper(getLLVMContext());
3961 llvm::MDNode *
Node = MDHelper.createFPMath(Accuracy);
3963 cast<llvm::Instruction>(Val)->setMetadata(llvm::LLVMContext::MD_fpmath, Node);
3967 struct LValueOrRValue {
3981 LValueOrRValue result;
3985 const Expr *semantic = *i;
3989 if (
const auto *ov = dyn_cast<OpaqueValueExpr>(semantic)) {
3995 if (ov == resultExpr && ov->
isRValue() && !forLValue &&
3996 CodeGenFunction::hasAggregateEvaluationKind(ov->getType())) {
4000 AlignmentSource::Decl);
4001 opaqueData = OVMA::bind(CGF, ov, LV);
4006 opaqueData = OVMA::bind(CGF, ov, ov->getSourceExpr());
4009 if (ov == resultExpr) {
4017 opaques.push_back(opaqueData);
4021 }
else if (semantic == resultExpr) {
4034 for (
unsigned i = 0, e = opaques.size(); i != e; ++i)
4035 opaques[i].unbind(CGF);
unsigned getNumElements() const
unsigned getAddressSpace() const
Return the address space of this type.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
ReturnValueSlot - Contains the address where the return value of a function can be stored...
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
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
CK_LValueToRValue - A conversion which causes the extraction of an r-value from the operand gl-value...
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
void end(CodeGenFunction &CGF)
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
static llvm::Value * emitArraySubscriptGEP(CodeGenFunction &CGF, llvm::Value *ptr, ArrayRef< llvm::Value * > indices, bool inbounds, const llvm::Twine &name="arrayidx")
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
llvm::Value * getPointer() const
CodeGenTypes & getTypes()
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
CGRecordLayout - This class handles struct and union layout info while lowering AST types to LLVM typ...
AlignmentSource
The source of the alignment of an l-value; an expression of confidence in the alignment actually matc...
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...
bool isArrow() const
isArrow - Return true if the base expression is a pointer to vector, return false if the base express...
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
CreateTempAlloca - This creates a alloca and inserts it into the entry block.
Expr * GetTemporaryExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
bool isRecordType() const
CK_ToUnion - The GCC cast-to-union extension.
Decl - This represents one declaration (or definition), e.g.
Address getAddress() const
static void pushTemporaryCleanup(CodeGenFunction &CGF, const MaterializeTemporaryExpr *M, const Expr *E, Address ReferenceTemporary)
void setTBAAInfo(llvm::MDNode *N)
const CastExpr * BasePath
const llvm::DataLayout & getDataLayout() const
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
static Destroyer destroyARCStrongPrecise
Expr * getLowerBound()
Get lower bound of array section.
void pushLifetimeExtendedDestroy(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
static void setObjCGCLValueClass(const ASTContext &Ctx, const Expr *E, LValue &LV, bool IsMemberAccess=false)
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
EmitStoreThroughLValue - Store the specified rvalue into the specified lvalue, where both are guarant...
void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit)
EmitComplexExprIntoLValue - Emit the given expression of complex type and place its result into the s...
CK_BaseToDerivedMemberPointer - Member pointer in base class to member pointer in derived class...
LValue EmitOpaqueValueLValue(const OpaqueValueExpr *e)
RValue asAggregateRValue() const
std::unique_ptr< llvm::MemoryBuffer > Buffer
Represents an array type, per C99 6.7.5.2 - Array Declarators.
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
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.
Represents a call to a C++ constructor.
CK_FloatingToIntegral - Floating point to integral.
static LValue EmitThreadPrivateVarDeclLValue(CodeGenFunction &CGF, const VarDecl *VD, QualType T, Address Addr, llvm::Type *RealVarTy, SourceLocation Loc)
bool isBooleanType() const
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
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.
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
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
CK_IntegralToFloating - Integral to floating point.
enum clang::SubobjectAdjustment::@37 Kind
VarDecl - An instance of this class is created to represent a variable declaration or definition...
CK_IntegralCast - A cast between integral types (other than to boolean).
llvm::Type * getElementType() const
Return the type of the values stored in this address.
static bool hasBooleanRepresentation(QualType Ty)
CompoundLiteralExpr - [C99 6.5.2.5].
RAII object to set/unset CodeGenFunction::IsSanitizerScope.
const Expr * getCallee() const
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.
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
llvm::Constant * GetAddrOfGlobalVar(const VarDecl *D, llvm::Type *Ty=nullptr)
Return the llvm::Constant for the address of the given global variable.
const CGBitFieldInfo & getBitFieldInfo(const FieldDecl *FD) const
Return the BitFieldInfo that corresponds to the field FD.
CK_Dynamic - A C++ dynamic_cast.
void EmitVariablyModifiedType(QualType Ty)
EmitVLASize - Capture all the sizes for the VLA expressions in the given variably-modified type and s...
CK_Dependent - A conversion which cannot yet be analyzed because either the expression or target type...
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
Address getVectorAddress() const
static llvm::Value * getTypeSize(CodeGenFunction &CGF, QualType Ty)
SourceLocation getLocation() const
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
The collection of all-type qualifiers we support.
RecordDecl - Represents a struct/union/class.
An object to manage conditionally-evaluated expressions.
void setTBAABaseType(QualType T)
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
bool isVolatileQualified() const
Represents a class type in Objective C.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
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.
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
bool isReferenceType() const
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
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
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
CK_FloatingCast - Casting between floating types of different size.
[ARC] Causes a value of block type to be copied to the heap, if it is not already there...
CK_VectorSplat - A conversion from an arithmetic type to a vector of that element type...
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
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)
bool hasStrongOrWeakObjCLifetime() const
void InitTempAlloca(Address Alloca, llvm::Value *Value)
InitTempAlloca - Provide an initial value for the given alloca which will be observable at all locati...
CK_NullToPointer - Null pointer constant to pointer, ObjC pointer, or block pointer.
CK_PointerToIntegral - Pointer to integral.
static Address emitAddrOfFieldStorage(CodeGenFunction &CGF, Address base, const FieldDecl *field)
Drill down to the storage of a field without walking into reference types.
CK_IntegralToPointer - Integral to pointer.
static bool isFlexibleArrayMemberExpr(const Expr *E)
Determine whether this expression refers to a flexible array member in a struct.
RValue EmitAnyExprToTemp(const Expr *E)
EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will always be accessible even if ...
const Expr *const * const_semantics_iterator
void setNonGC(bool Value)
Address CreateIRTemp(QualType T, const Twine &Name="tmp")
CreateIRTemp - Create a temporary IR object of the given type, with appropriate alignment.
Converts a floating point complex to bool by comparing against 0+0i.
RValue EmitAnyExpr(const Expr *E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
EmitAnyExpr - Emit code to compute the specified expression which can have any type.
Describes an C or C++ initializer list.
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
CK_IntegralToBoolean - Integral to boolean.
unsigned Size
The total size of the bit-field, in bits.
static LValueOrRValue emitPseudoObjectExpr(CodeGenFunction &CGF, const PseudoObjectExpr *E, bool forLValue, AggValueSlot slot)
CharUnits getAlignment() const
const LangOptions & getLangOpts() const
Expr * getTrueExpr() const
Address CreateElementBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Cast the element type of the given address to a different type, preserving information like the align...
CharUnits - This is an opaque type for sizes expressed in character units.
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()
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
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
RecordDecl * getDecl() const
static AlignmentSource getFieldAlignmentSource(AlignmentSource Source)
Given that the base address has the given alignment source, what's our confidence in the alignment of...
virtual llvm::Value * EmitMemberPointerIsNotNull(CodeGenFunction &CGF, llvm::Value *MemPtr, const MemberPointerType *MPT)
Determine if a member pointer is non-null. Returns an i1.
Scope - A scope is a transient data structure that is used while parsing the program.
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D...
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
getFieldOffset - Get the offset of the given field index, in bits.
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.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
unsigned Offset
The offset within a contiguous run of bitfields that are represented as a single "field" within the L...
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
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.
void setARCPreciseLifetime(ARCPreciseLifetime_t value)
bool isExtVectorElt() const
Represents an ObjC class declaration.
Checking the operand of a cast to a virtual base object.
detail::InMemoryDirectory::const_iterator I
static CharUnits getArrayElementAlign(CharUnits arrayAlign, llvm::Value *idx, CharUnits eltSize)
void begin(CodeGenFunction &CGF)
void setThreadLocalRef(bool Value)
This object can be modified without requiring retains or releases.
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)
isTypeConstant - Determine whether an object of this type can be emitted as a constant.
EnumDecl * getDecl() const
CK_AnyPointerToBlockPointerCast - Casting any non-block pointer to a block pointer.
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource AlignSource=AlignmentSource::Type)
OpenMP 4.0 [2.4, Array Sections].
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type...
static CharUnits One()
One - Construct a CharUnits quantity of one.
std::pair< llvm::Value *, llvm::Value * > ComplexPairTy
Represents a prototype with parameter type info, e.g.
llvm::CallInst * EmitNounwindRuntimeCall(llvm::Value *callee, const Twine &name="")
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Causes a block literal to by copied to the heap and then autoreleased.
void EmitAnyExprToMem(const Expr *E, Address Location, Qualifiers Quals, bool IsInitializer)
EmitAnyExprToMem - Emits the code necessary to evaluate an arbitrary expression into the given memory...
bool isOBJCGCCandidate(ASTContext &Ctx) const
isOBJCGCCandidate - Return true if this expression may be used in a read/ write barrier.
bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const
EvaluateAsRValue - Return true if this is a constant which we can fold to an rvalue using any crazy t...
static CheckRecoverableKind getRecoverableKind(SanitizerMask Kind)
RValue - This trivial value class is used to represent the result of an expression that is evaluated...
virtual LValue EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF, const VarDecl *VD, QualType LValType)=0
Emit a reference to a non-local thread_local variable (including triggering the initialization of all...
CleanupKind getARCCleanupKind()
Retrieves the default cleanup kind for an ARC cleanup.
Address getBitFieldAddress() const
Represents a call to the builtin function __builtin_va_arg.
ID
Defines the set of possible language-specific address spaces.
CK_FunctionToPointerDecay - Function to pointer decay.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Address CreateDefaultAlignTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
CreateDefaultAlignedTempAlloca - This creates an alloca with the default ABI alignment of the given L...
bool isFunctionPointerType() const
Converts between different floating point complex types.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
const ObjCMethodDecl * getMethodDecl() const
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
static TypeEvaluationKind getEvaluationKind(QualType T)
hasAggregateLLVMType - Return true if the specified AST type will map into an aggregate LLVM type or ...
llvm::Value * getPointer() const
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
llvm::Function * generateDestroyHelper(Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray, const VarDecl *VD)
generateDestroyHelper - Generates a helper function which, when invoked, destroys the given object...
Expr - This represents one expression.
CK_PointerToBoolean - Pointer to boolean conversion.
Converts an integral complex to an integral real of the source's element type by discarding the imagi...
CK_BitCast - A conversion which causes a bit pattern of one type to be reinterpreted as a bit pattern...
CGCXXABI & getCXXABI() const
bool isAnyComplexType() const
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited...
llvm::Value * EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, QualType DstTy, SourceLocation Loc)
Emit a conversion from the specified complex type to the specified destination type, where the destination type is an LLVM scalar type.
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.
void setAddressSpace(unsigned space)
bool isVariableArrayType() const
static LValue EmitCapturedFieldLValue(CodeGenFunction &CGF, const FieldDecl *FD, llvm::Value *ThisValue)
AggValueSlot CreateAggTemp(QualType T, const Twine &Name="tmp")
CreateAggTemp - Create a temporary memory object for the given aggregate type.
ASTContext & getContext() const
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)
Emit the operand of a glvalue conditional operator.
virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D, llvm::Constant *Dtor, llvm::Constant *Addr)=0
Emit code to force the execution of a destructor during global teardown.
Selector getSelector() const
llvm::LLVMContext & getLLVMContext()
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
Expr * getSubExpr() const
CK_ConstructorConversion - Conversion by constructor.
bool isThreadLocalRef() 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.
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
Represents a GCC generic vector type.
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)
The scope of a CXXDefaultInitExpr.
QualType getElementType() const
The result type of a method or function.
ConstantEmissionKind
Can we constant-emit a load of a reference to a variable of the given type? This is different from pr...
static AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, IsZeroed_t isZeroed=IsNotZeroed)
forAddr - Make a slot for an aggregate value.
CK_ArrayToPointerDecay - Array to pointer decay.
ConstantAddress GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E, const Expr *Inner)
Returns a pointer to a global variable representing a temporary with static or thread storage duratio...
Dynamic storage duration.
The l-value was considered opaque, so the alignment was determined from a type.
CK_CPointerToObjCPointerCast - Casting a C pointer kind to an Objective-C pointer.
bool isNontemporal() const
There is no lifetime qualification on this type.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
Address CreateBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
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.
Assigning into this object requires the old value to be released and the new value to be retained...
static LValue EmitGlobalNamedRegister(const VarDecl *VD, CodeGenModule &CGM)
Named Registers are named metadata pointing to the register name which will be read from/written to a...
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
CK_UserDefinedConversion - Conversion using a user defined type conversion function.
const char * getFilename() const
Return the presumed filename of this location.
llvm::Constant * EmitConstantExpr(const Expr *E, QualType DestType, CodeGenFunction *CGF=nullptr)
Try to emit the given expression as a constant; returns 0 if the expression cannot be emitted as a co...
ASTContext & getContext() const
void pushDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
pushDestroy - Push the standard destructor for the given type as at least a normal cleanup...
Encodes a location in the source.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
QualType getElementType() const
QualType withCVRQualifiers(unsigned CVR) const
llvm::Value * EvaluateExprAsBool(const Expr *E)
EvaluateExprAsBool - Perform the usual unary conversions on the specified expression and compare the ...
SourceLocation getExprLoc() const LLVM_READONLY
const CGBitFieldInfo & getBitFieldInfo() const
bool isValid() const
Return true if this is a valid SourceLocation object.
llvm::MDNode * getTBAAInfo() const
CK_NullToMemberPointer - Null pointer constant to member pointer.
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Checking the operand of a cast to a base object.
A scoped helper to set the current debug location to the specified location or preferred location of ...
Represents a static or instance method of a struct/union/class.
static LValue EmitGlobalVarDeclLValue(CodeGenFunction &CGF, const Expr *E, const VarDecl *VD)
CK_ReinterpretMemberPointer - Reinterpret a member pointer as a different kind of member pointer...
CK_DerivedToBase - A conversion from a C++ class pointer to a base class pointer. ...
SanitizerSet SanOpts
Sanitizers enabled for this function.
static QualType getFixedSizeElementType(const ASTContext &ctx, const VariableArrayType *vla)
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
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
Get the base element type of this type, potentially discarding type qualifiers.
StringLiteral * getFunctionName()
Converts from an integral real to an integral complex whose element type matches the source...
void setObjCIvar(bool Value)
QualType getReturnType() const
const T * castAs() const
Member-template castAs<specific type>.
unsigned getAddressSpace() const
Return the address space that this address resides in.
bool isVectorType() const
llvm::Constant * getAddrOfCXXStructor(const CXXMethodDecl *MD, StructorType Type, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, bool IsForDefinition=false)
Return the address of the constructor/destructor of the given type.
Assigning into this object requires a lifetime extension.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Address getExtVectorAddress() const
const Expr * getBase() const
llvm::Value * getGlobalReg() const
AlignmentSource getAlignmentSource() const
static Destroyer destroyARCStrongImprecise
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
QualType getPointeeType() const
void setExternallyDestructed(bool destructed=true)
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type, returning the result.
decl_iterator - Iterates through the declarations stored within this context.
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
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.
CGFunctionInfo - Class to encapsulate the information about a function definition.
CharUnits getAlignment() const
Return the alignment of this pointer.
This class organizes the cross-function state that is used while generating LLVM code.
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.
Converts an integral complex to bool by comparing against 0+0i.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return 0.
Address CreateMemTemp(QualType T, const Twine &Name="tmp")
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignment...
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()
ignored - Returns an aggregate value slot indicating that the aggregate value is being ignored...
Address CreateStructGEP(Address Addr, unsigned Index, CharUnits Offset, const llvm::Twine &Name="")
CK_BaseToDerived - A conversion from a C++ class pointer/reference to a derived class pointer/referen...
Checking the bound value in a reference binding.
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)
Return the result of value-initializing the given type, i.e.
unsigned StorageSize
The storage size in bits which should be used when accessing this bitfield.
EnumDecl - Represents an enum.
CK_BlockPointerToObjCPointerCast - Casting a block pointer to an ObjC pointer.
detail::InMemoryDirectory::const_iterator E
A pointer to member type per C++ 8.3.3 - Pointers to members.
semantics_iterator semantics_begin()
A conversion of a floating point real to a floating point complex of the original type...
CK_MemberPointerToBoolean - Member pointer to boolean.
ExplicitCastExpr - An explicit cast written in the source code.
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
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)
EmitAggExpr - Emit the computation of the specified expression of aggregate type. ...
[ARC] Reclaim a retainable object pointer object that may have been produced and autoreleased as part...
Expr * IgnoreParenImpCasts() LLVM_READONLY
IgnoreParenImpCasts - Ignore parentheses and implicit casts.
const VariableArrayType * getAsVariableArrayType(QualType T) const
static Address createReferenceTemporary(CodeGenFunction &CGF, const MaterializeTemporaryExpr *M, const Expr *Inner)
static bool hasAggregateEvaluationKind(QualType T)
llvm::Constant * getExtVectorElts() const
bool HasSideEffects
Whether the evaluated expression has side effects.
llvm::PointerType * getType() const
Return the type of the pointer value.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Complex values, per C99 6.2.5p11.
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
const T * getAs() const
Member-template getAs<specific type>'.
Checking the operand of a static_cast to a derived pointer type.
Expr * getFalseExpr() const
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
QualType getCanonicalType() const
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
static StringRef getIdentTypeName(IdentType IT)
ObjCEncodeExpr, used for @encode in Objective-C.
virtual bool usesThreadWrapperFunction() const =0
Address EmitCXXMemberDataPointerAddress(const Expr *E, Address base, llvm::Value *memberPtr, const MemberPointerType *memberPtrType, AlignmentSource *AlignSource=nullptr)
Emit the address of a field using a member data pointer.
[ARC] Produces a retainable object pointer so that it may be consumed, e.g.
QualType getIntegerType() const
getIntegerType - Return the integer type this enum decl corresponds to.
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
AllocaInsertPoint - This is an instruction in the entry block before which we prefer to insert alloca...
bool isFunctionType() const
QualType getTBAABaseType() const
LValue EmitLoadOfReferenceLValue(Address Ref, const ReferenceType *RefTy)
static llvm::Value * emitHash16Bytes(CGBuilderTy &Builder, llvm::Value *Low, llvm::Value *High)
Emit the hash_16_bytes function from include/llvm/ADT/Hashing.h.
CK_LValueBitCast - A conversion which reinterprets the address of an l-value as an l-value of a diffe...
Address getAddress() const
Converts from T to _Atomic(T).
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
Base for LValueReferenceType and RValueReferenceType.
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.
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
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)
EmitComplexExpr - Emit the computation of the specified expression of complex type, returning the result.
const Expr * getInitializer() const
unsigned getFieldIndex() const
getFieldIndex - Returns the index of this field within its record, as appropriate for passing to ASTR...
CK_UncheckedDerivedToBase - A conversion from a C++ class pointer/reference to a base class that can ...
QualType getPointeeType() const
ObjCIvarRefExpr - A reference to an ObjC instance variable.
const Decl * getCalleeDecl()
llvm::Value * getVectorIdx() const
Reading or writing from this object requires a barrier call.
void setCurrentStmt(const Stmt *S)
If the execution count for the current statement is known, record that as the current count...
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
static bool isConstantEmittableObjectType(QualType type)
Given an object of the given canonical type, can we safely copy a value out of it based on its initia...
A non-RAII class containing all the information about a bound opaque value.
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
CharUnits alignmentAtOffset(CharUnits offset) const
Given that this is a non-zero alignment value, what is the alignment at the given offset...
bool isObjCObjectPointerType() const
llvm::Type * ConvertType(QualType T)
static Destroyer destroyCXXObject
A specialization of Address that requires the address to be an LLVM Constant.
ObjCIvarDecl - Represents an ObjC instance variable.
LValue EmitLValue(const Expr *E)
EmitLValue - Emit code to compute a designator that specifies the location of the expression...
static llvm::Value * getArrayIndexingBound(CodeGenFunction &CGF, const Expr *Base, QualType &IndexedType)
If Base is known to point to the start of an array, return the length of that array.
Address getAggregateAddress() const
getAggregateAddr() - Return the Value* of the address of the aggregate.
Converts from _Atomic(T) to T.
std::pair< llvm::Value *, QualType > getVLASize(const VariableArrayType *vla)
getVLASize - Returns an LLVM value that corresponds to the size, in non-variably-sized elements...
StringLiteral - This represents a string literal expression, e.g.
Full-expression storage duration (for temporaries).
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
const MemberPointerType * MPT
llvm::Value * EmitScalarConversion(llvm::Value *Src, QualType SrcTy, QualType DstTy, SourceLocation Loc)
Emit a conversion from the specified type to the specified destination type, both of which are LLVM s...
CK_NoOp - A conversion which does not affect the type other than (possibly) adding qualifiers...
A reference to a declared variable, function, enum, etc.
static RValue get(llvm::Value *V)
static ConstantEmissionKind checkVarTypeForConstantEmission(QualType type)
CK_DerivedToBaseMemberPointer - Member pointer in derived class to member pointer in base class...
QualType getElementType() const
SourceLocation getColonLoc() const
const Expr * getInit(unsigned Init) const
const Expr * getSubExpr() const
CodeGenTypes & getTypes() const
LValue - This represents an lvalue references.
bool isGlobalObjCRef() const
NamedDecl - This represents a decl with a name.
Represents a C array with a specified size that is not an integer-constant-expression.
bool isArithmeticType() const
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
Automatic storage duration (most local variables).
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], or an enum decl which has a signed representation.
bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const
EvaluateAsLValue - Evaluate an expression to see if we can fold it to an lvalue with link time known ...
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const CXXRecordDecl * DerivedClass
CK_ToVoid - Cast to void, discarding the computed value.
llvm::Constant * GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty=nullptr, bool ForVTable=false, bool DontDefer=false, bool IsForDefinition=false)
Return the address of the given function.
const CGRecordLayout & getCGRecordLayout(const RecordDecl *)
getCGRecordLayout - Return record layout info for the given record decl.
Address GetAddressOfBaseClass(Address Value, const CXXRecordDecl *Derived, CastExpr::path_const_iterator PathBegin, CastExpr::path_const_iterator PathEnd, bool NullCheckValue, SourceLocation Loc)
GetAddressOfBaseClass - This function will add the necessary delta to the load of 'this' and returns ...
CallArgList - Type for representing both the value and type of arguments in a call.
uint64_t getTBAAOffset() const
CGCalleeInfo - Class to encapsulate the information about a callee to be used during the generation o...
void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint=true)
Expr * getLength()
Get length of array section.
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Structure with information about how a bitfield should be accessed.
const RecordDecl * getParent() const
getParent - Returns the parent of this field declaration, which is the struct in which this method is...
CheckRecoverableKind
Specify under what conditions this check can be recovered.
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
void Destroyer(CodeGenFunction &CGF, Address addr, QualType ty)
Expr * getBase()
An array section can be written only as Base[LowerBound:Length].
bool isPointerType() const
CK_FloatingToBoolean - Floating point to boolean.
static const Expr * isSimpleArrayDecayOperand(const Expr *E)
isSimpleArrayDecayOperand - If the specified expr is a simple decay from an array to pointer...
static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts)
getAccessedFieldNo - Given an encoded value and a result number, return the input field number being ...