30 #include "llvm/ADT/Hashing.h" 31 #include "llvm/ADT/StringExtras.h" 32 #include "llvm/IR/DataLayout.h" 33 #include "llvm/IR/Intrinsics.h" 34 #include "llvm/IR/LLVMContext.h" 35 #include "llvm/IR/MDBuilder.h" 36 #include "llvm/Support/ConvertUTF.h" 37 #include "llvm/Support/MathExtras.h" 38 #include "llvm/Support/Path.h" 39 #include "llvm/Transforms/Utils/SanitizerStats.h" 43 using namespace clang;
44 using namespace CodeGen;
51 unsigned addressSpace =
52 cast<llvm::PointerType>(value->getType())->getAddressSpace();
56 destType = llvm::Type::getInt8PtrTy(
getLLVMContext(), addressSpace);
58 if (value->getType() == destType)
return value;
89 llvm::IRBuilderBase::InsertPointGuard IPG(
Builder);
97 Ty->getPointerTo(DestAddrSpace),
true);
110 return Builder.CreateAlloca(Ty, ArraySize, Name);
127 assert(isa<llvm::AllocaInst>(Var.
getPointer()));
146 const Twine &Name,
Address *Alloca) {
203 if (!ignoreResult && aggSlot.
isIgnored())
208 llvm_unreachable(
"bad evaluation kind");
250 llvm_unreachable(
"bad evaluation kind");
291 VD && isa<VarDecl>(VD) && VD->
hasAttr<ObjCPreciseLifetimeAttr>();
312 llvm_unreachable(
"temporary cannot have dynamic storage duration");
314 llvm_unreachable(
"unknown storage duration");
322 auto *ClassDecl = cast<CXXRecordDecl>(RT->getDecl());
323 if (!ClassDecl->hasTrivialDestructor())
324 ReferenceTemporaryDtor = ClassDecl->getDestructor();
327 if (!ReferenceTemporaryDtor)
334 llvm::FunctionCallee CleanupFn;
335 llvm::Constant *CleanupArg;
338 ReferenceTemporary, E->
getType(),
341 CleanupArg = llvm::Constant::getNullValue(CGF.
Int8PtrTy);
345 CleanupArg = cast<llvm::Constant>(ReferenceTemporary.
getPointer());
360 ReferenceTemporary, E->
getType(),
366 llvm_unreachable(
"temporary cannot have dynamic storage duration");
388 auto AS = AddrSpace.getValue();
389 auto *GV =
new llvm::GlobalVariable(
391 llvm::GlobalValue::PrivateLinkage, Init,
".ref.tmp",
nullptr,
392 llvm::GlobalValue::NotThreadLocal,
395 GV->setAlignment(alignment.getQuantity());
396 llvm::Constant *C = GV;
398 C = TCG.performAddrSpaceCast(
400 GV->getValueType()->getPointerTo(
413 llvm_unreachable(
"temporary can't have dynamic storage duration");
415 llvm_unreachable(
"unknown storage duration");
424 "Reference should never be pseudo-strong!");
432 if (
auto *Var = dyn_cast<llvm::GlobalVariable>(Object.
getPointer())) {
433 Object =
Address(llvm::ConstantExpr::getBitCast(Var,
444 if (Var->hasInitializer())
453 default: llvm_unreachable(
"expected scalar or aggregate expression");
476 for (
const auto &Ignored : CommaLHSs)
479 if (
const auto *opaque = dyn_cast<OpaqueValueExpr>(E)) {
480 if (opaque->getType()->isRecordType()) {
481 assert(Adjustments.empty());
489 if (
auto *Var = dyn_cast<llvm::GlobalVariable>(
491 Object =
Address(llvm::ConstantExpr::getBitCast(
498 if (!Var->hasInitializer()) {
514 if (!ShouldEmitLifetimeMarkers)
524 CGBuilderTy::InsertPoint OldIP;
527 OldConditional = OutermostConditional;
528 OutermostConditional =
nullptr;
532 Builder.restoreIP(CGBuilderTy::InsertPoint(
533 Block, llvm::BasicBlock::iterator(Block->back())));
543 if (OldConditional) {
544 OutermostConditional = OldConditional;
560 for (
unsigned I = Adjustments.size(); I != 0; --I) {
562 switch (Adjustment.
Kind) {
574 assert(LV.isSimple() &&
575 "materialized temporary field is not a simple lvalue");
576 Object = LV.getAddress();
616 const llvm::Constant *Elts) {
617 return cast<llvm::ConstantInt>(Elts->getAggregateElement(Idx))
624 llvm::Value *KMul = Builder.getInt64(0x9ddfea08eb382d69ULL);
626 llvm::Value *A0 = Builder.CreateMul(Builder.CreateXor(Low, High), KMul);
627 llvm::Value *A1 = Builder.CreateXor(Builder.CreateLShr(A0, K47), A0);
628 llvm::Value *B0 = Builder.CreateMul(Builder.CreateXor(High, A1), KMul);
629 llvm::Value *B1 = Builder.CreateXor(Builder.CreateLShr(B0, K47), B0);
630 return Builder.CreateMul(B1, KMul);
664 if (Ptr->getType()->getPointerAddressSpace())
675 llvm::BasicBlock *Done =
nullptr;
681 dyn_cast<llvm::AllocaInst>(Ptr->stripPointerCastsNoFollowAliases());
685 bool IsGuaranteedNonNull =
686 SkippedChecks.
has(SanitizerKind::Null) || PtrToAlloca;
688 if ((
SanOpts.
has(SanitizerKind::Null) || AllowNullPointers) &&
689 !IsGuaranteedNonNull) {
691 IsNonNull =
Builder.CreateIsNotNull(Ptr);
695 IsGuaranteedNonNull = IsNonNull == True;
698 if (!IsGuaranteedNonNull) {
699 if (AllowNullPointers) {
704 Builder.CreateCondBr(IsNonNull, Rest, Done);
707 Checks.push_back(std::make_pair(IsNonNull, SanitizerKind::Null));
713 !SkippedChecks.
has(SanitizerKind::ObjectSize) &&
718 Size =
Builder.CreateMul(Size, ArraySize);
721 llvm::Constant *ConstantSize = dyn_cast<llvm::Constant>(Size);
722 if (!ConstantSize || !ConstantSize->isNullValue()) {
728 llvm::Function *F =
CGM.
getIntrinsic(llvm::Intrinsic::objectsize, Tys);
734 Builder.CreateCall(F, {CastAddr, Min, NullIsUnknown, Dynamic}), Size);
735 Checks.push_back(std::make_pair(LargeEnough, SanitizerKind::ObjectSize));
739 uint64_t AlignVal = 0;
743 !SkippedChecks.
has(SanitizerKind::Alignment)) {
750 (!PtrToAlloca || PtrToAlloca->getAlignment() < AlignVal)) {
753 PtrAsInt, llvm::ConstantInt::get(
IntPtrTy, AlignVal - 1));
757 Checks.push_back(std::make_pair(Aligned, SanitizerKind::Alignment));
761 if (Checks.size() > 0) {
764 assert(!AlignVal || (uint64_t)1 << llvm::Log2_64(AlignVal) == AlignVal);
765 llvm::Constant *StaticData[] = {
767 llvm::ConstantInt::get(
Int8Ty, AlignVal ? llvm::Log2_64(AlignVal) : 1),
768 llvm::ConstantInt::get(
Int8Ty, TCK)};
769 EmitCheck(Checks, SanitizerHandler::TypeMismatch, StaticData,
770 PtrAsInt ? PtrAsInt : Ptr);
785 if (!IsGuaranteedNonNull) {
787 IsNonNull =
Builder.CreateIsNotNull(Ptr);
791 Builder.CreateCondBr(IsNonNull, VptrNotNull, Done);
801 llvm::raw_svector_ostream Out(MangledName);
807 SanitizerKind::Vptr, Out.str())) {
808 llvm::hash_code TypeHash =
hash_value(Out.str());
821 const int CacheSize = 128;
824 "__ubsan_vptr_type_cache");
838 llvm::Constant *StaticData[] = {
842 llvm::ConstantInt::get(
Int8Ty, TCK)
845 EmitCheck(std::make_pair(EqualHash, SanitizerKind::Vptr),
846 SanitizerHandler::DynamicTypeCacheMiss, StaticData,
863 if (
const auto *CAT = dyn_cast<ConstantArrayType>(AT)) {
864 if (CAT->getSize().ugt(1))
866 }
else if (!isa<IncompleteArrayType>(AT))
872 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
875 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
878 return ++FI == FD->getParent()->field_end();
880 }
else if (
const auto *IRE = dyn_cast<ObjCIvarRefExpr>(E)) {
881 return IRE->getDecl()->getNextIvar() ==
nullptr;
898 auto *ParamDecl = dyn_cast<
ParmVarDecl>(ArrayDeclRef->getDecl());
902 auto *POSAttr = ParamDecl->
getAttr<PassObjectSizeAttr>();
907 int POSType = POSAttr->getType();
908 if (POSType != 0 && POSType != 1)
912 auto PassedSizeIt = SizeArguments.find(ParamDecl);
913 if (PassedSizeIt == SizeArguments.end())
917 assert(LocalDeclMap.count(PassedSizeDecl) &&
"Passed size not loadable");
918 Address AddrOfSize = LocalDeclMap.find(PassedSizeDecl)->second;
922 llvm::ConstantInt::get(SizeInBytes->getType(), EltSize);
923 return Builder.CreateUDiv(SizeInBytes, SizeOfElement);
933 return CGF.
Builder.getInt32(VT->getNumElements());
938 if (
const auto *CE = dyn_cast<CastExpr>(Base)) {
939 if (CE->getCastKind() == CK_ArrayToPointerDecay &&
941 IndexedType = CE->getSubExpr()->getType();
943 if (
const auto *CAT = dyn_cast<ConstantArrayType>(AT))
944 return CGF.
Builder.getInt(CAT->getSize());
945 else if (
const auto *VAT = dyn_cast<VariableArrayType>(AT))
963 assert(
SanOpts.
has(SanitizerKind::ArrayBounds) &&
964 "should not be called unless adding bounds checks");
976 llvm::Constant *StaticData[] = {
982 :
Builder.CreateICmpULE(IndexVal, BoundVal);
983 EmitCheck(std::make_pair(Check, SanitizerKind::ArrayBounds),
984 SanitizerHandler::OutOfBounds, StaticData, Index);
990 bool isInc,
bool isPre) {
994 if (isa<llvm::IntegerType>(InVal.first->getType())) {
995 uint64_t AmountVal = isInc ? 1 : -1;
996 NextVal = llvm::ConstantInt::get(InVal.first->getType(), AmountVal,
true);
999 NextVal =
Builder.CreateAdd(InVal.first, NextVal, isInc ?
"inc" :
"dec");
1002 llvm::APFloat FVal(
getContext().getFloatTypeSemantics(ElemTy), 1);
1008 NextVal =
Builder.CreateFAdd(InVal.first, NextVal, isInc ?
"inc" :
"dec");
1018 return isPre ? IncVal : InVal;
1028 DI->EmitExplicitCastType(E->
getType());
1046 if (
const CastExpr *CE = dyn_cast<CastExpr>(E)) {
1047 if (
const auto *ECE = dyn_cast<ExplicitCastExpr>(CE))
1050 switch (CE->getCastKind()) {
1054 case CK_AddressSpaceConversion:
1055 if (
auto PtrTy = CE->getSubExpr()->getType()->getAs<
PointerType>()) {
1056 if (PtrTy->getPointeeType()->isVoidType())
1064 if (BaseInfo) *BaseInfo = InnerBaseInfo;
1065 if (TBAAInfo) *TBAAInfo = InnerTBAAInfo;
1067 if (isa<ExplicitCastExpr>(CE)) {
1071 &TargetTypeBaseInfo,
1072 &TargetTypeTBAAInfo);
1075 TargetTypeTBAAInfo);
1085 if (
SanOpts.
has(SanitizerKind::CFIUnrelatedCast) &&
1086 CE->getCastKind() == CK_BitCast) {
1093 return CE->getCastKind() != CK_AddressSpaceConversion
1101 case CK_ArrayToPointerDecay:
1105 case CK_UncheckedDerivedToBase:
1106 case CK_DerivedToBase: {
1113 auto Derived = CE->getSubExpr()->
getType()->getPointeeCXXRecordDecl();
1115 CE->path_begin(), CE->path_end(),
1129 if (UO->getOpcode() == UO_AddrOf) {
1168 llvm_unreachable(
"bad evaluation kind");
1187 while (!isa<CXXThisExpr>(Base)) {
1189 if (isa<CXXDynamicCastExpr>(Base))
1192 if (
const auto *CE = dyn_cast<CastExpr>(Base)) {
1193 Base = CE->getSubExpr();
1194 }
else if (
const auto *PE = dyn_cast<ParenExpr>(Base)) {
1195 Base = PE->getSubExpr();
1196 }
else if (
const auto *UO = dyn_cast<UnaryOperator>(Base)) {
1197 if (UO->getOpcode() == UO_Extension)
1198 Base = UO->getSubExpr();
1210 if (
SanOpts.
has(SanitizerKind::ArrayBounds) && isa<ArraySubscriptExpr>(E))
1216 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
1219 SkippedChecks.
set(SanitizerKind::Alignment,
true);
1220 if (IsBaseCXXThis || isa<DeclRefExpr>(ME->getBase()))
1221 SkippedChecks.
set(SanitizerKind::Null,
true);
1249 case Expr::ObjCPropertyRefExprClass:
1250 llvm_unreachable(
"cannot emit a property reference directly");
1252 case Expr::ObjCSelectorExprClass:
1254 case Expr::ObjCIsaExprClass:
1256 case Expr::BinaryOperatorClass:
1258 case Expr::CompoundAssignOperatorClass: {
1261 Ty = AT->getValueType();
1266 case Expr::CallExprClass:
1267 case Expr::CXXMemberCallExprClass:
1268 case Expr::CXXOperatorCallExprClass:
1269 case Expr::UserDefinedLiteralClass:
1271 case Expr::VAArgExprClass:
1273 case Expr::DeclRefExprClass:
1275 case Expr::ConstantExprClass:
1276 return EmitLValue(cast<ConstantExpr>(E)->getSubExpr());
1277 case Expr::ParenExprClass:
1278 return EmitLValue(cast<ParenExpr>(E)->getSubExpr());
1279 case Expr::GenericSelectionExprClass:
1280 return EmitLValue(cast<GenericSelectionExpr>(E)->getResultExpr());
1281 case Expr::PredefinedExprClass:
1283 case Expr::StringLiteralClass:
1285 case Expr::ObjCEncodeExprClass:
1287 case Expr::PseudoObjectExprClass:
1289 case Expr::InitListExprClass:
1291 case Expr::CXXTemporaryObjectExprClass:
1292 case Expr::CXXConstructExprClass:
1294 case Expr::CXXBindTemporaryExprClass:
1296 case Expr::CXXUuidofExprClass:
1298 case Expr::LambdaExprClass:
1301 case Expr::ExprWithCleanupsClass: {
1302 const auto *cleanups = cast<ExprWithCleanups>(E);
1319 case Expr::CXXDefaultArgExprClass: {
1320 auto *DAE = cast<CXXDefaultArgExpr>(E);
1324 case Expr::CXXDefaultInitExprClass: {
1325 auto *DIE = cast<CXXDefaultInitExpr>(E);
1329 case Expr::CXXTypeidExprClass:
1332 case Expr::ObjCMessageExprClass:
1334 case Expr::ObjCIvarRefExprClass:
1336 case Expr::StmtExprClass:
1338 case Expr::UnaryOperatorClass:
1340 case Expr::ArraySubscriptExprClass:
1342 case Expr::OMPArraySectionExprClass:
1344 case Expr::ExtVectorElementExprClass:
1346 case Expr::MemberExprClass:
1348 case Expr::CompoundLiteralExprClass:
1350 case Expr::ConditionalOperatorClass:
1352 case Expr::BinaryConditionalOperatorClass:
1354 case Expr::ChooseExprClass:
1355 return EmitLValue(cast<ChooseExpr>(E)->getChosenSubExpr());
1356 case Expr::OpaqueValueExprClass:
1358 case Expr::SubstNonTypeTemplateParmExprClass:
1359 return EmitLValue(cast<SubstNonTypeTemplateParmExpr>(E)->getReplacement());
1360 case Expr::ImplicitCastExprClass:
1361 case Expr::CStyleCastExprClass:
1362 case Expr::CXXFunctionalCastExprClass:
1363 case Expr::CXXStaticCastExprClass:
1364 case Expr::CXXDynamicCastExprClass:
1365 case Expr::CXXReinterpretCastExprClass:
1366 case Expr::CXXConstCastExprClass:
1367 case Expr::ObjCBridgedCastExprClass:
1370 case Expr::MaterializeTemporaryExprClass:
1373 case Expr::CoawaitExprClass:
1375 case Expr::CoyieldExprClass:
1388 if (!qs.hasConst() || qs.hasVolatile())
return false;
1392 if (
const auto *RT = dyn_cast<RecordType>(type))
1393 if (
const auto *RD = dyn_cast<CXXRecordDecl>(RT->getDecl()))
1394 if (RD->hasMutableFields() || !RD->isTrivial())
1415 if (
const auto *ref = dyn_cast<ReferenceType>(type)) {
1437 if (isa<ParmVarDecl>(value)) {
1439 }
else if (
auto *var = dyn_cast<VarDecl>(value)) {
1441 }
else if (isa<EnumConstantDecl>(value)) {
1449 bool resultIsReference;
1455 resultIsReference =
false;
1456 resultType = refExpr->
getType();
1461 resultIsReference =
true;
1462 resultType = value->
getType();
1475 result.
Val, resultType);
1479 if (isa<VarDecl>(value)) {
1483 assert(isa<EnumConstantDecl>(value));
1488 if (resultIsReference)
1515 assert(Constant &&
"not a constant");
1535 return ET->getDecl()->getIntegerType()->isBooleanType();
1544 llvm::APInt &Min, llvm::APInt &
End,
1545 bool StrictEnums,
bool IsBool) {
1547 bool IsRegularCPlusPlusEnum = CGF.
getLangOpts().CPlusPlus && StrictEnums &&
1549 if (!IsBool && !IsRegularCPlusPlusEnum)
1558 unsigned Bitwidth = LTy->getScalarSizeInBits();
1562 if (NumNegativeBits) {
1563 unsigned NumBits =
std::max(NumNegativeBits, NumPositiveBits + 1);
1564 assert(NumBits <= Bitwidth);
1565 End = llvm::APInt(Bitwidth, 1) << (NumBits - 1);
1568 assert(NumPositiveBits <= Bitwidth);
1569 End = llvm::APInt(Bitwidth, 1) << NumPositiveBits;
1570 Min = llvm::APInt(Bitwidth, 0);
1576 llvm::MDNode *CodeGenFunction::getRangeForLoadFromType(
QualType Ty) {
1577 llvm::APInt Min,
End;
1583 return MDHelper.createRange(Min, End);
1588 bool HasBoolCheck =
SanOpts.
has(SanitizerKind::Bool);
1589 bool HasEnumCheck =
SanOpts.
has(SanitizerKind::Enum);
1590 if (!HasBoolCheck && !HasEnumCheck)
1595 bool NeedsBoolCheck = HasBoolCheck && IsBool;
1596 bool NeedsEnumCheck = HasEnumCheck && Ty->
getAs<
EnumType>();
1597 if (!NeedsBoolCheck && !NeedsEnumCheck)
1604 cast<llvm::IntegerType>(Value->getType())->getBitWidth() == 1)
1607 llvm::APInt Min,
End;
1616 Check =
Builder.CreateICmpULE(Value, llvm::ConstantInt::get(Ctx, End));
1619 Builder.CreateICmpSLE(Value, llvm::ConstantInt::get(Ctx, End));
1621 Builder.CreateICmpSGE(Value, llvm::ConstantInt::get(Ctx, Min));
1622 Check =
Builder.CreateAnd(Upper, Lower);
1627 NeedsEnumCheck ? SanitizerKind::Enum : SanitizerKind::Bool;
1628 EmitCheck(std::make_pair(Check, Kind), SanitizerHandler::LoadInvalidValue,
1638 bool isNontemporal) {
1644 const auto *VTy = cast<llvm::VectorType>(EltTy);
1647 if (VTy->getNumElements() == 3) {
1650 llvm::VectorType *vec4Ty =
1651 llvm::VectorType::get(VTy->getElementType(), 4);
1657 V =
Builder.CreateShuffleVector(V, llvm::UndefValue::get(vec4Ty),
1658 {0, 1, 2},
"extractVec");
1672 if (isNontemporal) {
1673 llvm::MDNode *
Node = llvm::MDNode::get(
1674 Load->getContext(), llvm::ConstantAsMetadata::get(
Builder.getInt32(1)));
1684 if (llvm::MDNode *RangeInfo = getRangeForLoadFromType(Ty))
1685 Load->setMetadata(llvm::LLVMContext::MD_range, RangeInfo);
1695 if (Value->getType()->isIntegerTy(1))
1698 "wrong value rep of bool");
1708 "wrong value rep of bool");
1709 return Builder.CreateTrunc(Value,
Builder.getInt1Ty(),
"tobool");
1719 bool isInit,
bool isNontemporal) {
1724 auto *VecTy = dyn_cast<llvm::VectorType>(SrcTy);
1726 if (VecTy && VecTy->getNumElements() == 3) {
1728 llvm::Constant *Mask[] = {
Builder.getInt32(0),
Builder.getInt32(1),
1730 llvm::UndefValue::get(
Builder.getInt32Ty())};
1731 llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
1732 Value =
Builder.CreateShuffleVector(Value, llvm::UndefValue::get(VecTy),
1733 MaskV,
"extractVec");
1734 SrcTy = llvm::VectorType::get(VecTy->getElementType(), 4);
1753 if (isNontemporal) {
1754 llvm::MDNode *
Node =
1755 llvm::MDNode::get(Store->getContext(),
1756 llvm::ConstantAsMetadata::get(
Builder.getInt32(1)));
1815 assert(LV.
isBitField() &&
"Unknown LValue type!");
1833 Val =
Builder.CreateShl(Val, HighBits,
"bf.shl");
1834 if (Info.
Offset + HighBits)
1835 Val =
Builder.CreateAShr(Val, Info.
Offset + HighBits,
"bf.ashr");
1870 for (
unsigned i = 0;
i != NumResultElts; ++
i)
1873 llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
1874 Vec =
Builder.CreateShuffleVector(Vec, llvm::UndefValue::get(Vec->getType()),
1886 Address CastToPointerElement =
1888 "conv.ptr.element");
1897 return VectorBasePtrPlusIx;
1903 "Bad type for register variable");
1904 llvm::MDNode *RegName = cast<llvm::MDNode>(
1905 cast<llvm::MetadataAsValue>(LV.
getGlobalReg())->getMetadata());
1910 if (OrigTy->isPointerTy())
1914 llvm::Function *F =
CGM.
getIntrinsic(llvm::Intrinsic::read_register, Types);
1916 F, llvm::MetadataAsValue::get(Ty->getContext(), RegName));
1917 if (OrigTy->isPointerTy())
1918 Call =
Builder.CreateIntToPtr(Call, OrigTy);
1948 assert(Dst.
isBitField() &&
"Unknown LValue type");
1956 llvm_unreachable(
"present but none");
2003 RHS =
Builder.CreatePtrToInt(RHS, ResultType,
"sub.ptr.rhs.cast");
2006 "sub.ptr.lhs.cast");
2019 assert(Src.
isScalar() &&
"Can't emit an agg store with this method");
2033 SrcVal =
Builder.CreateIntCast(SrcVal, Ptr.getElementType(),
2046 SrcVal =
Builder.CreateAnd(SrcVal,
2062 SrcVal =
Builder.CreateOr(Val, SrcVal,
"bf.set");
2064 assert(Info.
Offset == 0);
2079 ResultVal =
Builder.CreateShl(ResultVal, HighBits,
"bf.result.shl");
2080 ResultVal =
Builder.CreateAShr(ResultVal, HighBits,
"bf.result.ashr");
2101 unsigned NumSrcElts = VTy->getNumElements();
2102 unsigned NumDstElts = Vec->getType()->getVectorNumElements();
2103 if (NumDstElts == NumSrcElts) {
2108 for (
unsigned i = 0;
i != NumSrcElts; ++
i)
2111 llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
2112 Vec =
Builder.CreateShuffleVector(SrcVal,
2113 llvm::UndefValue::get(Vec->getType()),
2115 }
else if (NumDstElts > NumSrcElts) {
2121 for (
unsigned i = 0;
i != NumSrcElts; ++
i)
2122 ExtMask.push_back(
Builder.getInt32(
i));
2123 ExtMask.resize(NumDstElts, llvm::UndefValue::get(
Int32Ty));
2124 llvm::Value *ExtMaskV = llvm::ConstantVector::get(ExtMask);
2126 Builder.CreateShuffleVector(SrcVal,
2127 llvm::UndefValue::get(SrcVal->getType()),
2131 for (
unsigned i = 0;
i != NumDstElts; ++
i)
2132 Mask.push_back(
Builder.getInt32(
i));
2141 for (
unsigned i = 0;
i != NumSrcElts; ++
i)
2143 llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
2144 Vec =
Builder.CreateShuffleVector(Vec, ExtSrcVal, MaskV);
2147 llvm_unreachable(
"unexpected shorten vector length");
2153 Vec =
Builder.CreateInsertElement(Vec, SrcVal, Elt);
2163 "Bad type for register variable");
2164 llvm::MDNode *RegName = cast<llvm::MDNode>(
2165 cast<llvm::MetadataAsValue>(Dst.
getGlobalReg())->getMetadata());
2166 assert(RegName &&
"Register LValue is not metadata");
2171 if (OrigTy->isPointerTy())
2175 llvm::Function *F =
CGM.
getIntrinsic(llvm::Intrinsic::write_register, Types);
2177 if (OrigTy->isPointerTy())
2178 Value =
Builder.CreatePtrToInt(Value, Ty);
2180 F, {llvm::MetadataAsValue::get(Ty->getContext(), RegName), Value});
2188 bool IsMemberAccess=
false) {
2192 if (isa<ObjCIvarRefExpr>(E)) {
2205 auto *Exp = cast<ObjCIvarRefExpr>(
const_cast<Expr *
>(E));
2211 if (
const auto *Exp = dyn_cast<DeclRefExpr>(E)) {
2212 if (
const auto *VD = dyn_cast<VarDecl>(Exp->getDecl())) {
2213 if (VD->hasGlobalStorage()) {
2222 if (
const auto *Exp = dyn_cast<UnaryOperator>(E)) {
2227 if (
const auto *Exp = dyn_cast<ParenExpr>(E)) {
2241 if (
const auto *Exp = dyn_cast<GenericSelectionExpr>(E)) {
2246 if (
const auto *Exp = dyn_cast<ImplicitCastExpr>(E)) {
2251 if (
const auto *Exp = dyn_cast<CStyleCastExpr>(E)) {
2256 if (
const auto *Exp = dyn_cast<ObjCBridgedCastExpr>(E)) {
2261 if (
const auto *Exp = dyn_cast<ArraySubscriptExpr>(E)) {
2274 if (
const auto *Exp = dyn_cast<MemberExpr>(E)) {
2286 StringRef Name = StringRef()) {
2287 unsigned AS = cast<llvm::PointerType>(V->getType())->getAddressSpace();
2302 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD);
2306 if (!Res || (*Res == OMPDeclareTargetDeclAttr::MT_To &&
2309 assert(((*Res == OMPDeclareTargetDeclAttr::MT_Link) ||
2310 (*Res == OMPDeclareTargetDeclAttr::MT_To &&
2312 "Expected link clause OR to clause with unified memory enabled.");
2327 PointeeBaseInfo, PointeeTBAAInfo,
2338 PointeeBaseInfo, PointeeTBAAInfo);
2383 VD->
hasAttr<OMPThreadPrivateDeclAttr>()) {
2397 if (FD->
hasAttr<WeakRefAttr>()) {
2412 V = llvm::ConstantExpr::getBitCast(V,
2442 AsmLabelAttr *Asm = VD->
getAttr<AsmLabelAttr>();
2443 assert(Asm->getLabel().size() < 64-Name.size() &&
2444 "Register name too big");
2445 Name.append(Asm->getLabel());
2446 llvm::NamedMDNode *M =
2447 CGM.
getModule().getOrInsertNamedMetadata(Name);
2448 if (M->getNumOperands() == 0) {
2451 llvm::Metadata *Ops[] = {Str};
2458 llvm::MetadataAsValue::get(CGM.
getLLVMContext(), M->getOperand(0));
2503 case llvm::GlobalValue::LinkOnceODRLinkage:
2504 case llvm::GlobalValue::WeakODRLinkage:
2506 case llvm::GlobalValue::PrivateLinkage:
2518 "should not emit an unevaluated operand");
2520 if (
const auto *VD = dyn_cast<VarDecl>(ND)) {
2523 VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())
2531 (VD->getType()->isReferenceType() ||
2533 VD->getAnyInitializer(VD);
2535 E->
getLocation(), *VD->evaluateValue(), VD->getType());
2536 assert(Val &&
"failed to emit constant expression");
2539 if (!VD->getType()->isReferenceType()) {
2550 Addr =
Address(Val, Alignment);
2559 VD = VD->getCanonicalDecl();
2563 auto I = LocalDeclMap.find(VD);
2564 if (I != LocalDeclMap.end()) {
2565 if (VD->getType()->isReferenceType())
2590 "Should not use decl without marking it used!");
2592 if (ND->
hasAttr<WeakRefAttr>()) {
2593 const auto *VD = cast<ValueDecl>(ND);
2598 if (
const auto *VD = dyn_cast<VarDecl>(ND)) {
2600 if (VD->hasLinkage() || VD->isStaticDataMember())
2606 auto iter = LocalDeclMap.find(VD);
2607 if (iter != LocalDeclMap.end()) {
2608 addr = iter->second;
2612 }
else if (VD->isStaticLocal()) {
2619 llvm_unreachable(
"DeclRefExpr for Decl not entered in LocalDeclMap?");
2625 VD->hasAttr<OMPThreadPrivateDeclAttr>()) {
2632 bool isBlockByref = VD->isEscapingByref();
2642 bool isLocalStorage = VD->hasLocalStorage();
2644 bool NonGCable = isLocalStorage &&
2645 !VD->getType()->isReferenceType() &&
2652 bool isImpreciseLifetime =
2653 (isLocalStorage && !VD->hasAttr<ObjCPreciseLifetimeAttr>());
2654 if (isImpreciseLifetime)
2660 if (
const auto *FD = dyn_cast<FunctionDecl>(ND))
2666 if (
const auto *BD = dyn_cast<BindingDecl>(ND))
2669 llvm_unreachable(
"Unhandled DeclRefExpr");
2679 default: llvm_unreachable(
"Unknown unary operator lvalue!");
2682 assert(!T.
isNull() &&
"CodeGenFunction::EmitUnaryOpLValue: Illegal type");
2704 assert(LV.
isSimple() &&
"real/imag on non-ordinary l-value");
2728 bool isInc = E->
getOpcode() == UO_PreInc;
2751 assert(SL !=
nullptr &&
"No StringLiteral name in PredefinedExpr");
2752 StringRef FnName =
CurFn->getName();
2753 if (FnName.startswith(
"\01"))
2754 FnName = FnName.substr(1);
2755 StringRef NameItems[] = {
2757 std::string GVName = llvm::join(NameItems, NameItems + 2,
".");
2758 if (
auto *BD = dyn_cast_or_null<BlockDecl>(
CurCodeDecl)) {
2759 std::string Name = SL->getString();
2760 if (!Name.empty()) {
2761 unsigned Discriminator =
2764 Name +=
"_" + Twine(Discriminator + 1).str();
2790 uint16_t TypeKind = -1;
2807 StringRef(), StringRef(), None, Buffer,
2810 llvm::Constant *Components[] = {
2814 llvm::Constant *Descriptor = llvm::ConstantStruct::getAnon(Components);
2816 auto *GV =
new llvm::GlobalVariable(
2818 true, llvm::GlobalVariable::PrivateLinkage, Descriptor);
2819 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
2831 if (V->getType() == TargetTy)
2836 if (V->getType()->isFloatingPointTy()) {
2837 unsigned Bits = V->getType()->getPrimitiveSizeInBits();
2838 if (Bits <= TargetTy->getIntegerBitWidth())
2844 if (V->getType()->isIntegerTy() &&
2845 V->getType()->getIntegerBitWidth() <= TargetTy->getIntegerBitWidth())
2846 return Builder.CreateZExt(V, TargetTy);
2849 if (!V->getType()->isPointerTy()) {
2854 return Builder.CreatePtrToInt(V, TargetTy);
2874 int PathComponentsToStrip =
2876 if (PathComponentsToStrip < 0) {
2877 assert(PathComponentsToStrip !=
INT_MIN);
2878 int PathComponentsToKeep = -PathComponentsToStrip;
2879 auto I = llvm::sys::path::rbegin(FilenameString);
2880 auto E = llvm::sys::path::rend(FilenameString);
2881 while (I != E && --PathComponentsToKeep)
2884 FilenameString = FilenameString.substr(I - E);
2885 }
else if (PathComponentsToStrip > 0) {
2886 auto I = llvm::sys::path::begin(FilenameString);
2887 auto E = llvm::sys::path::end(FilenameString);
2888 while (I != E && PathComponentsToStrip--)
2893 FilenameString.substr(I - llvm::sys::path::begin(FilenameString));
2895 FilenameString = llvm::sys::path::filename(FilenameString);
2900 cast<llvm::GlobalVariable>(FilenameGV.getPointer()));
2901 Filename = FilenameGV.getPointer();
2905 Filename = llvm::Constant::getNullValue(
Int8PtrTy);
2912 return llvm::ConstantStruct::getAnon(Data);
2932 else if (Kind == SanitizerKind::Return || Kind == SanitizerKind::Unreachable)
2935 return CheckRecoverableKind::Recoverable;
2939 struct SanitizerHandlerInfo {
2940 char const *
const Name;
2946 #define SANITIZER_CHECK(Enum, Name, Version) {#Name, Version}, 2948 #undef SANITIZER_CHECK 2952 llvm::FunctionType *FnType,
2956 llvm::BasicBlock *ContBB) {
2959 if (!CGF.
Builder.getCurrentDebugLocation()) {
2963 bool NeedsAbortSuffix =
2966 const SanitizerHandlerInfo &CheckInfo = SanitizerHandlers[CheckHandler];
2967 const StringRef CheckName = CheckInfo.Name;
2968 std::string FnName =
"__ubsan_handle_" + CheckName.str();
2969 if (CheckInfo.Version && !MinimalRuntime)
2970 FnName +=
"_v" + llvm::utostr(CheckInfo.Version);
2972 FnName +=
"_minimal";
2973 if (NeedsAbortSuffix)
2978 llvm::AttrBuilder B;
2980 B.addAttribute(llvm::Attribute::NoReturn)
2981 .addAttribute(llvm::Attribute::NoUnwind);
2983 B.addAttribute(llvm::Attribute::UWTable);
2988 llvm::AttributeList::FunctionIndex, B),
2992 HandlerCall->setDoesNotReturn();
2993 CGF.
Builder.CreateUnreachable();
3000 ArrayRef<std::pair<llvm::Value *, SanitizerMask>> Checked,
3004 assert(Checked.size() > 0);
3005 assert(CheckHandler >= 0 &&
3006 size_t(CheckHandler) < llvm::array_lengthof(SanitizerHandlers));
3007 const StringRef CheckName = SanitizerHandlers[CheckHandler].Name;
3012 for (
int i = 0, n = Checked.size();
i < n; ++
i) {
3021 Cond = Cond ?
Builder.CreateAnd(Cond, Check) : Check;
3026 if (!FatalCond && !RecoverableCond)
3030 if (FatalCond && RecoverableCond)
3031 JointCond =
Builder.CreateAnd(FatalCond, RecoverableCond);
3033 JointCond = FatalCond ? FatalCond : RecoverableCond;
3039 for (
int i = 1, n = Checked.size();
i < n; ++
i) {
3041 "All recoverable kinds in a single check must be same!");
3048 llvm::Instruction *Branch =
Builder.CreateCondBr(JointCond, Cont, Handlers);
3052 llvm::MDNode *
Node = MDHelper.createBranchWeights((1U << 20) - 1, 1);
3053 Branch->setMetadata(llvm::LLVMContext::MD_prof, Node);
3062 Args.reserve(DynamicArgs.size() + 1);
3063 ArgTypes.reserve(DynamicArgs.size() + 1);
3066 if (!StaticArgs.empty()) {
3067 llvm::Constant *Info = llvm::ConstantStruct::getAnon(StaticArgs);
3069 new llvm::GlobalVariable(
CGM.
getModule(), Info->getType(),
false,
3070 llvm::GlobalVariable::PrivateLinkage, Info);
3071 InfoPtr->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
3077 for (
size_t i = 0, n = DynamicArgs.size();
i != n; ++
i) {
3083 llvm::FunctionType *FnType =
3084 llvm::FunctionType::get(
CGM.
VoidTy, ArgTypes,
false);
3086 if (!FatalCond || !RecoverableCond) {
3090 (FatalCond !=
nullptr), Cont);
3094 llvm::BasicBlock *NonFatalHandlerBB =
3097 Builder.CreateCondBr(FatalCond, NonFatalHandlerBB, FatalHandlerBB);
3115 llvm::BranchInst *BI =
Builder.CreateCondBr(Cond, Cont, CheckBB);
3118 llvm::MDNode *
Node = MDHelper.createBranchWeights((1U << 20) - 1, 1);
3119 BI->setMetadata(llvm::LLVMContext::MD_prof, Node);
3125 llvm::CallInst *CheckCall;
3126 llvm::FunctionCallee SlowPathFn;
3128 llvm::Constant *Info = llvm::ConstantStruct::getAnon(StaticArgs);
3130 new llvm::GlobalVariable(
CGM.
getModule(), Info->getType(),
false,
3131 llvm::GlobalVariable::PrivateLinkage, Info);
3132 InfoPtr->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
3136 "__cfi_slowpath_diag",
3139 CheckCall =
Builder.CreateCall(
3145 CheckCall =
Builder.CreateCall(SlowPathFn, {TypeId, Ptr});
3149 cast<llvm::GlobalValue>(SlowPathFn.getCallee()->stripPointerCasts()));
3150 CheckCall->setDoesNotThrow();
3159 auto &Ctx = M->getContext();
3162 llvm::GlobalValue::WeakAnyLinkage,
"__cfi_check", M);
3170 llvm::Intrinsic::getDeclaration(M, llvm::Intrinsic::trap),
"", BB);
3188 Args.push_back(&ArgData);
3189 Args.push_back(&ArgAddr);
3196 llvm::GlobalValue::WeakODRLinkage,
"__cfi_check_fail", &
CGM.
getModule());
3219 llvm::StructType *SourceLocationTy =
3221 llvm::StructType *CfiCheckFailDataTy =
3222 llvm::StructType::get(
Int8Ty, SourceLocationTy, VoidPtrTy);
3226 Builder.CreatePointerCast(Data, CfiCheckFailDataTy->getPointerTo(0)), 0,
3231 llvm::Value *AllVtables = llvm::MetadataAsValue::get(
3236 {Addr, AllVtables}),
3239 const std::pair<int, SanitizerMask> CheckKinds[] = {
3247 for (
auto CheckKindMaskPair : CheckKinds) {
3248 int Kind = CheckKindMaskPair.first;
3251 Builder.CreateICmpNE(CheckKind, llvm::ConstantInt::get(
Int8Ty, Kind));
3253 EmitCheck(std::make_pair(Cond, Mask), SanitizerHandler::CFICheckFail, {},
3254 {Data, Addr, ValidVtable});
3266 if (
SanOpts.
has(SanitizerKind::Unreachable)) {
3269 SanitizerKind::Unreachable),
3270 SanitizerHandler::BuiltinUnreachable,
3283 Builder.CreateCondBr(Checked, Cont, TrapBB);
3285 llvm::CallInst *TrapCall =
EmitTrapCall(llvm::Intrinsic::trap);
3286 TrapCall->setDoesNotReturn();
3287 TrapCall->setDoesNotThrow();
3290 Builder.CreateCondBr(Checked, Cont, TrapBB);
3300 auto A = llvm::Attribute::get(
getLLVMContext(),
"trap-func-name",
3302 TrapCall->addAttribute(llvm::AttributeList::FunctionIndex, A);
3312 "Array to pointer decay must have array source type!");
3316 Address Addr = LV.getAddress();
3326 assert(isa<llvm::ArrayType>(Addr.getElementType()) &&
3327 "Expected pointer to array");
3337 if (BaseInfo) *BaseInfo = LV.getBaseInfo();
3347 const auto *CE = dyn_cast<
CastExpr>(E);
3348 if (!CE || CE->getCastKind() != CK_ArrayToPointerDecay)
3352 const Expr *SubExpr = CE->getSubExpr();
3365 const llvm::Twine &
name =
"arrayidx") {
3380 if (
auto constantIdx = dyn_cast<llvm::ConstantInt>(idx)) {
3381 CharUnits offset = constantIdx->getZExtValue() * eltSize;
3403 const llvm::Twine &
name =
"arrayidx") {
3406 for (
auto idx : indices.drop_back())
3407 assert(isa<llvm::ConstantInt>(idx) &&
3408 cast<llvm::ConstantInt>(idx)->isZero());
3423 auto LastIndex = dyn_cast<llvm::ConstantInt>(indices.back());
3426 CGF, addr.
getPointer(), indices, inbounds, signedIndices,
3430 unsigned idx = LastIndex->getZExtValue();
3436 return Address(eltPtr, eltAlign);
3445 bool SignedIndices =
false;
3446 auto EmitIdxAfterBase = [&, IdxPre](
bool Promote) ->
llvm::Value * {
3449 assert(E->
getRHS() == E->
getIdx() &&
"index was neither LHS nor RHS");
3455 SignedIndices |= IdxSigned;
3461 if (Promote && Idx->getType() !=
IntPtrTy)
3471 !isa<ExtVectorElementExpr>(E->
getBase())) {
3474 auto *Idx = EmitIdxAfterBase(
false);
3475 assert(LHS.
isSimple() &&
"Can only subscript lvalue vectors here!");
3483 if (isa<ExtVectorElementExpr>(E->
getBase())) {
3485 auto *Idx = EmitIdxAfterBase(
true);
3504 auto *Idx = EmitIdxAfterBase(
true);
3514 Idx =
Builder.CreateMul(Idx, numElements);
3516 Idx =
Builder.CreateNSWMul(Idx, numElements);
3528 auto *Idx = EmitIdxAfterBase(
true);
3532 llvm::ConstantInt::get(Idx->getType(), InterfaceSize.
getQuantity());
3549 Addr =
Address(EltPtr, EltAlign);
3558 assert(Array->getType()->isArrayType() &&
3559 "Array to pointer decay must have array source type!");
3563 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(Array))
3567 auto *Idx = EmitIdxAfterBase(
true);
3574 EltBaseInfo = ArrayLV.getBaseInfo();
3579 auto *Idx = EmitIdxAfterBase(
true);
3599 bool IsLowerBound) {
3616 "Expected pointer to array");
3635 bool IsLowerBound) {
3639 ResultExprTy = AT->getElementType();
3650 LowerBound->getType()->hasSignedIntegerRepresentation());
3652 Idx = llvm::ConstantInt::getNullValue(
IntPtrTy);
3659 llvm::APSInt ConstLength;
3662 if (Length->isIntegerConstantExpr(ConstLength, C)) {
3668 if (LowerBound && LowerBound->isIntegerConstantExpr(ConstLowerBound, C)) {
3670 LowerBound =
nullptr;
3674 else if (!LowerBound)
3677 if (Length || LowerBound) {
3678 auto *LowerBoundVal =
3682 LowerBound->getType()->hasSignedIntegerRepresentation())
3683 : llvm::ConstantInt::get(
IntPtrTy, ConstLowerBound);
3688 Length->getType()->hasSignedIntegerRepresentation())
3689 : llvm::ConstantInt::get(
IntPtrTy, ConstLength);
3690 Idx =
Builder.CreateAdd(LowerBoundVal, LengthVal,
"lb_add_len",
3693 if (Length && LowerBound) {
3695 Idx, llvm::ConstantInt::get(
IntPtrTy, 1),
"idx_sub_1",
3699 Idx = llvm::ConstantInt::get(
IntPtrTy, ConstLength + ConstLowerBound);
3705 if (
auto *VAT = C.getAsVariableArrayType(ArrayTy)) {
3706 Length = VAT->getSizeExpr();
3707 if (Length->isIntegerConstantExpr(ConstLength, C))
3710 auto *CAT = C.getAsConstantArrayType(ArrayTy);
3711 ConstLength = CAT->getSize();
3714 auto *LengthVal =
Builder.CreateIntCast(
3716 Length->getType()->hasSignedIntegerRepresentation());
3718 LengthVal, llvm::ConstantInt::get(
IntPtrTy, 1),
"len_sub_1",
3723 Idx = llvm::ConstantInt::get(
IntPtrTy, ConstLength);
3732 if (
auto *VLA =
getContext().getAsVariableArrayType(ResultExprTy)) {
3738 BaseTy, VLA->getElementType(), IsLowerBound);
3747 Idx =
Builder.CreateMul(Idx, NumElements);
3749 Idx =
Builder.CreateNSWMul(Idx, NumElements);
3758 assert(Array->getType()->isArrayType() &&
3759 "Array to pointer decay must have array source type!");
3763 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(Array))
3773 BaseInfo = ArrayLV.getBaseInfo();
3777 TBAAInfo, BaseTy, ResultExprTy,
3800 Base =
MakeAddrLValue(Ptr, PT->getPointeeType(), BaseInfo, TBAAInfo);
3801 Base.getQuals().removeObjCGCAttr();
3810 "Result must be a vector");
3828 llvm::Constant *CV =
3833 assert(Base.
isExtVectorElt() &&
"Can only subscript lvalue vec elts here!");
3838 for (
unsigned i = 0, e = Indices.size();
i != e; ++
i)
3839 CElts.push_back(BaseElts->getAggregateElement(Indices[
i]));
3840 llvm::Constant *CV = llvm::ConstantVector::get(CElts);
3862 SkippedChecks.
set(SanitizerKind::Alignment,
true);
3863 if (IsBaseCXXThis || isa<DeclRefExpr>(BaseExpr))
3864 SkippedChecks.
set(SanitizerKind::Null,
true);
3872 if (
auto *Field = dyn_cast<FieldDecl>(ND)) {
3878 if (
const auto *FD = dyn_cast<FunctionDecl>(ND))
3881 llvm_unreachable(
"Unhandled member declaration!");
3887 assert(cast<CXXMethodDecl>(
CurCodeDecl)->getParent()->isLambda());
3898 unsigned FieldIndex) {
3899 unsigned I = 0, Skipped = 0;
3902 if (I == FieldIndex)
3904 if (F->isUnnamedBitfield())
3909 return FieldIndex - Skipped;
3959 if (RD->isDynamicClass())
3962 for (
const auto &
Base : RD->bases())
3966 for (
const FieldDecl *Field : RD->fields())
4020 assert(!FieldTBAAInfo.
Offset &&
4021 "Nonzero offset for an access with no base type!");
4034 FieldTBAAInfo.
Size =
4039 if (
auto *ClassDef = dyn_cast<CXXRecordDecl>(rec)) {
4041 ClassDef->isDynamicClass()) {
4054 assert(!FieldType->
isReferenceType() &&
"union has reference member");
4067 Builder.CreatePreserveUnionAccessIndex(
4101 if (field->
hasAttr<AnnotateAttr>())
4163 assert(E->
isTransparent() &&
"non-transparent glvalue init list");
4171 const Expr *Operand) {
4172 if (
auto *ThrowExpr = dyn_cast<CXXThrowExpr>(Operand->
IgnoreParens())) {
4185 "Unexpected conditional operator!");
4195 if (!CondExprBool) std::swap(live, dead);
4220 if (lhs && !lhs->isSimple())
4223 lhsBlock =
Builder.GetInsertBlock();
4233 if (rhs && !rhs->isSimple())
4235 rhsBlock =
Builder.GetInsertBlock();
4240 llvm::PHINode *phi =
Builder.CreatePHI(lhs->getPointer()->getType(),
4242 phi->addIncoming(lhs->getPointer(), lhsBlock);
4243 phi->addIncoming(rhs->getPointer(), rhsBlock);
4246 std::max(lhs->getBaseInfo().getAlignmentSource(),
4247 rhs->getBaseInfo().getAlignmentSource());
4249 lhs->getTBAAInfo(), rhs->getTBAAInfo());
4253 assert((lhs || rhs) &&
4254 "both operands of glvalue conditional are throw-expressions?");
4255 return lhs ? *lhs : *rhs;
4270 case CK_LValueToRValueBitCast:
4271 case CK_ArrayToPointerDecay:
4272 case CK_FunctionToPointerDecay:
4273 case CK_NullToMemberPointer:
4274 case CK_NullToPointer:
4275 case CK_IntegralToPointer:
4276 case CK_PointerToIntegral:
4277 case CK_PointerToBoolean:
4278 case CK_VectorSplat:
4279 case CK_IntegralCast:
4280 case CK_BooleanToSignedIntegral:
4281 case CK_IntegralToBoolean:
4282 case CK_IntegralToFloating:
4283 case CK_FloatingToIntegral:
4284 case CK_FloatingToBoolean:
4285 case CK_FloatingCast:
4286 case CK_FloatingRealToComplex:
4287 case CK_FloatingComplexToReal:
4288 case CK_FloatingComplexToBoolean:
4289 case CK_FloatingComplexCast:
4290 case CK_FloatingComplexToIntegralComplex:
4291 case CK_IntegralRealToComplex:
4292 case CK_IntegralComplexToReal:
4293 case CK_IntegralComplexToBoolean:
4294 case CK_IntegralComplexCast:
4295 case CK_IntegralComplexToFloatingComplex:
4296 case CK_DerivedToBaseMemberPointer:
4297 case CK_BaseToDerivedMemberPointer:
4298 case CK_MemberPointerToBoolean:
4299 case CK_ReinterpretMemberPointer:
4300 case CK_AnyPointerToBlockPointerCast:
4301 case CK_ARCProduceObject:
4302 case CK_ARCConsumeObject:
4303 case CK_ARCReclaimReturnedObject:
4304 case CK_ARCExtendBlockObject:
4305 case CK_CopyAndAutoreleaseBlockObject:
4306 case CK_IntToOCLSampler:
4307 case CK_FixedPointCast:
4308 case CK_FixedPointToBoolean:
4309 case CK_FixedPointToIntegral:
4310 case CK_IntegralToFixedPoint:
4314 llvm_unreachable(
"dependent cast kind in IR gen!");
4316 case CK_BuiltinFnToFnPtr:
4317 llvm_unreachable(
"builtin functions are handled elsewhere");
4320 case CK_NonAtomicToAtomic:
4321 case CK_AtomicToNonAtomic:
4327 const auto *DCE = cast<CXXDynamicCastExpr>(E);
4331 case CK_ConstructorConversion:
4332 case CK_UserDefinedConversion:
4333 case CK_CPointerToObjCPointerCast:
4334 case CK_BlockPointerToObjCPointerCast:
4336 case CK_LValueToRValue:
4339 case CK_UncheckedDerivedToBase:
4340 case CK_DerivedToBase: {
4343 auto *DerivedClassDecl = cast<CXXRecordDecl>(DerivedClassTy->
getDecl());
4346 Address This = LV.getAddress();
4361 case CK_BaseToDerived: {
4363 auto *DerivedClassDecl = cast<CXXRecordDecl>(DerivedClassTy->
getDecl());
4377 Derived.getPointer(), E->
getType());
4379 if (
SanOpts.
has(SanitizerKind::CFIDerivedCast))
4387 case CK_LValueBitCast: {
4389 const auto *CE = cast<ExplicitCastExpr>(E);
4396 if (
SanOpts.
has(SanitizerKind::CFIUnrelatedCast))
4404 case CK_AddressSpaceConversion: {
4413 case CK_ObjCObjectLValueCast: {
4420 case CK_ZeroToOCLOpaqueType:
4421 llvm_unreachable(
"NULL to OpenCL opaque type lvalue cast is not valid");
4424 llvm_unreachable(
"Unhandled lvalue cast kind?");
4436 llvm::DenseMap<const OpaqueValueExpr*,LValue>::iterator
4437 it = OpaqueLValues.find(e);
4439 if (it != OpaqueLValues.end())
4442 assert(e->
isUnique() &&
"LValue for a nonunique OVE hasn't been emitted");
4450 llvm::DenseMap<const OpaqueValueExpr*,RValue>::iterator
4451 it = OpaqueRValues.find(e);
4453 if (it != OpaqueRValues.end())
4456 assert(e->
isUnique() &&
"RValue for a nonunique OVE hasn't been emitted");
4477 llvm_unreachable(
"bad evaluation kind");
4490 if (
const auto *CE = dyn_cast<CXXMemberCallExpr>(E))
4493 if (
const auto *CE = dyn_cast<CUDAKernelCallExpr>(E))
4496 if (
const auto *CE = dyn_cast<CXXOperatorCallExpr>(E))
4498 dyn_cast_or_null<CXXMethodDecl>(CE->getCalleeDecl()))
4535 if (
auto ICE = dyn_cast<ImplicitCastExpr>(E)) {
4536 if (ICE->getCastKind() == CK_FunctionToPointerDecay ||
4537 ICE->getCastKind() == CK_BuiltinFnToFnPtr) {
4542 }
else if (
auto DRE = dyn_cast<DeclRefExpr>(E)) {
4543 if (
auto FD = dyn_cast<FunctionDecl>(DRE->getDecl())) {
4546 }
else if (
auto ME = dyn_cast<MemberExpr>(E)) {
4547 if (
auto FD = dyn_cast<FunctionDecl>(ME->getMemberDecl())) {
4553 }
else if (
auto NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) {
4557 }
else if (
auto PDE = dyn_cast<CXXPseudoDestructorExpr>(E)) {
4574 if (
const auto *VD =
4579 CGCallee callee(calleeInfo, calleePtr);
4595 assert(E->
getOpcode() == BO_Assign &&
"unexpected binary l-value");
4630 llvm_unreachable(
"bad evaluation kind");
4641 "Can't have a scalar return unless the return type is a " 4654 &&
"binding l-value to type which needs a temporary");
4692 "Can't have a scalar return unless the return type is a " 4712 unsigned CVRQualifiers) {
4714 Ivar, CVRQualifiers);
4730 ObjectTy = BaseExpr->
getType();
4754 "Call must have function pointer type!");
4756 const Decl *TargetDecl =
4761 auto PointeeType = cast<PointerType>(CalleeType)->getPointeeType();
4766 (!TargetDecl || !isa<FunctionDecl>(TargetDecl))) {
4767 if (llvm::Constant *PrefixSig =
4774 llvm::Constant *FTRTTIConst =
4777 llvm::StructType *PrefixStructTy = llvm::StructType::get(
4783 CalleePtr, llvm::PointerType::getUnqual(PrefixStructTy));
4785 Builder.CreateConstGEP2_32(PrefixStructTy, CalleePrefixStruct, 0, 0);
4792 Builder.CreateCondBr(CalleeSigMatch, TypeCheck, Cont);
4796 Builder.CreateConstGEP2_32(PrefixStructTy, CalleePrefixStruct, 0, 1);
4802 Builder.CreateICmpEQ(CalleeRTTI, FTRTTIConst);
4806 SanitizerHandler::FunctionTypeMismatch, StaticData,
4807 {CalleePtr, CalleeRTTI, FTRTTIConst});
4814 const auto *FnType = cast<FunctionType>(PointeeType);
4819 (!TargetDecl || !isa<FunctionDecl>(TargetDecl))) {
4834 CGM.
getIntrinsic(llvm::Intrinsic::type_test), {CastedCallee, TypeId});
4837 llvm::Constant *StaticData[] = {
4844 CastedCallee, StaticData);
4846 EmitCheck(std::make_pair(TypeTest, SanitizerKind::CFIICall),
4847 SanitizerHandler::CFICheckFail, StaticData,
4848 {CastedCallee, llvm::UndefValue::get(
IntPtrTy)});
4864 if (
auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
4865 if (OCE->isAssignmentOp())
4868 switch (OCE->getOperator()) {
4870 case OO_GreaterGreater:
4887 Args, FnType, Chain);
4909 if (isa<FunctionNoProtoType>(FnType) || Chain) {
4911 CalleeTy = CalleeTy->getPointerTo();
4918 llvm::CallBase *CallOrInvoke =
nullptr;
4919 RValue Call =
EmitCall(FnInfo, Callee, ReturnValue, Args, &CallOrInvoke,
4925 if (
auto *CalleeDecl = dyn_cast_or_null<FunctionDecl>(TargetDecl))
4926 DI->EmitFuncDeclForCallSite(CallOrInvoke,
QualType(FnType, 0),
4953 return MakeAddrLValue(MemberAddr, MPT->getPointeeType(), BaseInfo, TBAAInfo);
4970 llvm_unreachable(
"bad evaluation kind");
4974 assert(Val->getType()->isFPOrFPVectorTy());
4975 if (Accuracy == 0.0 || !isa<llvm::Instruction>(Val))
4979 llvm::MDNode *
Node = MDHelper.createFPMath(Accuracy);
4981 cast<llvm::Instruction>(Val)->setMetadata(llvm::LLVMContext::MD_fpmath, Node);
4985 struct LValueOrRValue {
5003 const Expr *semantic = *
i;
5007 if (
const auto *ov = dyn_cast<OpaqueValueExpr>(semantic)) {
5009 if (ov->isUnique()) {
5010 assert(ov != resultExpr &&
5011 "A unique OVE cannot be used as the result expression");
5019 if (ov == resultExpr && ov->
isRValue() && !forLValue &&
5024 opaqueData = OVMA::bind(CGF, ov, LV);
5029 opaqueData = OVMA::bind(CGF, ov, ov->getSourceExpr());
5032 if (ov == resultExpr) {
5040 opaques.push_back(opaqueData);
5044 }
else if (semantic == resultExpr) {
5057 for (
unsigned i = 0, e = opaques.size();
i != e; ++
i)
5058 opaques[
i].unbind(CGF);
const CGFunctionInfo & arrangeBuiltinFunctionDeclaration(QualType resultType, const FunctionArgList &args)
A builtin function is a freestanding function using the default C conventions.
const llvm::DataLayout & getDataLayout() const
TBAAAccessInfo getTBAAInfoForSubobject(LValue Base, QualType AccessType)
getTBAAInfoForSubobject - Get TBAA information for an access with a given base lvalue.
ReturnValueSlot - Contains the address where the return value of a function can be stored...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
SourceLocation getExprLoc() const LLVM_READONLY
bool EmitScalarRangeCheck(llvm::Value *Value, QualType Ty, SourceLocation Loc)
Check if the scalar Value is within the valid range for the given type Ty.
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name="")
Defines the clang::ASTContext interface.
Address CreateConstInBoundsGEP(Address Addr, uint64_t Index, const llvm::Twine &Name="")
Given addr = T* ...
Represents a function declaration or definition.
llvm::Value * EmitARCStoreStrong(LValue lvalue, llvm::Value *value, bool resultIgnored)
Store into a strong object.
LValue MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T)
Given a value of type T* that may not be to a complete object, construct an l-value with the natural ...
Address getAddress() const
CharUnits getIntAlign() const
void end(CodeGenFunction &CGF)
External linkage, which indicates that the entity can be referred to from other translation units...
Other implicit parameter.
LValue getReferenceLValue(CodeGenFunction &CGF, Expr *refExpr) const
bool isSignedOverflowDefined() const
no exception specification
LValue EmitComplexCompoundAssignmentLValue(const CompoundAssignOperator *E)
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
llvm::Constant * getValue() const
void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C)
A (possibly-)qualified type.
unsigned countPopulation() const
const CGBitFieldInfo & getBitFieldInfo(const FieldDecl *FD) const
Return the BitFieldInfo that corresponds to the field FD.
bool isBlockPointerType() const
Address EmitCXXMemberDataPointerAddress(const Expr *E, Address base, llvm::Value *memberPtr, const MemberPointerType *memberPtrType, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
Emit the address of a field using a member data pointer.
CodeGenTypes & getTypes()
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Address CreateAddrSpaceCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
bool sanitizePerformTypeCheck() const
Whether any type-checking sanitizers are enabled.
llvm::Type * ConvertTypeForMem(QualType T)
void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, llvm::BasicBlock *FalseBlock, uint64_t TrueCount)
EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g.
const CodeGenOptions & getCodeGenOpts() const
SourceLocation getExprLoc() const
LValue EmitStmtExprLValue(const StmtExpr *E)
Address CreatePreserveStructAccessIndex(Address Addr, unsigned Index, unsigned FieldIndex, llvm::MDNode *DbgInfo)
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...
Address CreateMemTemp(QualType T, const Twine &Name="tmp", Address *Alloca=nullptr)
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen and cas...
llvm::Value * getGlobalReg() const
llvm::Constant * EmitCheckTypeDescriptor(QualType T)
Emit a description of a type in a format suitable for passing to a runtime sanitizer handler...
void enterFullExpression(const FullExpr *E)
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...
bool isBlacklistedType(SanitizerMask Mask, StringRef MangledTypeName, StringRef Category=StringRef()) const
llvm::LLVMContext & getLLVMContext()
LValue EmitObjCIsaExpr(const ObjCIsaExpr *E)
const Expr * getInit(unsigned Init) const
ConstantAddress GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *)
Return a pointer to a constant array for the given ObjCEncodeExpr node.
LValue EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D...
bool isArithmeticType() const
llvm::DIType * getOrCreateRecordType(QualType Ty, SourceLocation L)
Emit record type's standalone debug info.
SanitizerSet Sanitize
Set of enabled sanitizers.
void EmitStoreThroughGlobalRegLValue(RValue Src, LValue Dst)
Store of global named registers are always calls to intrinsics.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Address GetAddressOfDerivedClass(Address Value, const CXXRecordDecl *Derived, CastExpr::path_const_iterator PathBegin, CastExpr::path_const_iterator PathEnd, bool NullCheckValue)
Address EmitPointerWithAlignment(const Expr *Addr, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
EmitPointerWithAlignment - Given an expression with a pointer type, emit the value and compute our be...
bool isRecordType() const
static const SanitizerMask AlwaysRecoverable
RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, AggValueSlot slot=AggValueSlot::ignored())
Decl - This represents one declaration (or definition), e.g.
static void pushTemporaryCleanup(CodeGenFunction &CGF, const MaterializeTemporaryExpr *M, const Expr *E, Address ReferenceTemporary)
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
llvm::MDNode * AccessType
AccessType - The final access type.
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
llvm::Value * getTypeSize(QualType Ty)
Returns calculated size of the specified type.
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
const llvm::DataLayout & getDataLayout() const
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic, and whose semantics are that of the sole contained initializer)?
const CastExpr * BasePath
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
void EmitCheck(ArrayRef< std::pair< llvm::Value *, SanitizerMask >> Checked, SanitizerHandler Check, ArrayRef< llvm::Constant *> StaticArgs, ArrayRef< llvm::Value *> DynamicArgs)
Create a basic block that will either trap or call a handler function in the UBSan runtime with the p...
const AstTypeMatcher< FunctionType > functionType
Matches FunctionType nodes.
Expr * getFalseExpr() const
static Destroyer destroyARCStrongPrecise
Expr * getLowerBound()
Get lower bound of array section.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined...
The base class of the type hierarchy.
void pushLifetimeExtendedDestroy(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
LValue EmitBinaryOperatorLValue(const BinaryOperator *E)
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...
LValue EmitOpaqueValueLValue(const OpaqueValueExpr *e)
Represents an array type, per C99 6.7.5.2 - Array Declarators.
static llvm::Value * EmitBitCastOfLValueToProperType(CodeGenFunction &CGF, llvm::Value *V, llvm::Type *IRType, StringRef Name=StringRef())
virtual const FieldDecl * lookup(const VarDecl *VD) const
Lookup the captured field decl for a variable.
Represents a call to a C++ constructor.
RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E, ReturnValueSlot ReturnValue)
bool isZero() const
isZero - Test whether the quantity equals zero.
static LValue EmitThreadPrivateVarDeclLValue(CodeGenFunction &CGF, const VarDecl *VD, QualType T, Address Addr, llvm::Type *RealVarTy, SourceLocation Loc)
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
void EmitCfiCheckFail()
Emit a cross-DSO CFI failure handling function.
StorageDuration
The storage duration for an object (per C++ [basic.stc]).
Address EmitLoadOfPointer(Address Ptr, const PointerType *PtrTy, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
constexpr XRayInstrMask Function
llvm::Value * LoadPassedObjectSize(const Expr *E, QualType EltTy)
If E references a parameter with pass_object_size info or a constant array size modifier, emit the object size divided by the size of EltTy.
IdentKind getIdentKind() const
LValue EmitLValueForFieldInitialization(LValue Base, const FieldDecl *Field)
EmitLValueForFieldInitialization - Like EmitLValueForField, except that if the Field is a reference...
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit)
Address CreateMemTempWithoutCast(QualType T, const Twine &Name="tmp")
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen without...
bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result, bool AllowLabels=false)
ConstantFoldsToSimpleInteger - If the specified expression does not fold to a constant, or if it does but contains a label, return false.
This name appears in an unevaluated operand.
QualType getElementType() const
static Destroyer destroyARCWeak
! Language semantics require left-to-right evaluation.
LValue EmitCXXUuidofLValue(const CXXUuidofExpr *E)
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
Represents a variable declaration or definition.
LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E)
Objects with "hidden" visibility are not seen by the dynamic linker.
static bool hasBooleanRepresentation(QualType Ty)
CompoundLiteralExpr - [C99 6.5.2.5].
RAII object to set/unset CodeGenFunction::IsSanitizerScope.
llvm::Value * getFunctionPointer() const
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
const T * getAs() const
Member-template getAs<specific type>'.
LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E)
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
uint64_t getProfileCount(const Stmt *S)
Get the profiler's count for the given statement.
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type...
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
static LValue MakeVectorElt(Address vecAddress, llvm::Value *Idx, QualType type, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
Address CreateConstInBoundsByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")
Given a pointer to i8, adjust it by a given constant offset.
DiagnosticsEngine & getDiags() const
llvm::CallInst * EmitTrapCall(llvm::Intrinsic::ID IntrID)
Emit a call to trap or debugtrap and attach function attribute "trap-func-name" if specified...
void EmitVariablyModifiedType(QualType Ty)
EmitVLASize - Capture all the sizes for the VLA expressions in the given variably-modified type and s...
LValue EmitComplexAssignmentLValue(const BinaryOperator *E)
Emit an l-value for an assignment (simple or compound) of complex type.
llvm::Value * getPointer() const
virtual llvm::Constant * getUBSanFunctionSignature(CodeGen::CodeGenModule &CGM) const
Return a constant used by UBSan as a signature to identify functions possessing type information...
static ConstantEmission forValue(llvm::Constant *C)
bool IsSanitizerScope
True if CodeGen currently emits code implementing sanitizer checks.
static Address createReferenceTemporary(CodeGenFunction &CGF, const MaterializeTemporaryExpr *M, const Expr *Inner, Address *Alloca=nullptr)
static DeclRefExpr * tryToConvertMemberExprToDeclRefExpr(CodeGenFunction &CGF, const MemberExpr *ME)
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
RValue EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E, ReturnValueSlot ReturnValue)
bool hasDefinition() const
Represents a parameter to a function.
SanitizerSet SanitizeRecover
Set of sanitizer checks that are non-fatal (i.e.
void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, llvm::Value **Result=nullptr)
EmitStoreThroughBitfieldLValue - Store Src into Dst with same constraints as EmitStoreThroughLValue.
unsigned getAddressSpace() const
Return the address space that this address resides in.
Address emitAddrOfImagComponent(Address complex, QualType complexType)
The collection of all-type qualifiers we support.
void add(RValue rvalue, QualType type)
bool isVariableArrayType() const
void EmitBoundsCheck(const Expr *E, const Expr *Base, llvm::Value *Index, QualType IndexType, bool Accessed)
Emit a check that Base points into an array object, which we can access at index Index.
Represents a struct/union/class.
llvm::DenseMap< const VarDecl *, FieldDecl * > LambdaCaptureFields
const TargetInfo & getTarget() const
An object to manage conditionally-evaluated expressions.
TBAAAccessInfo mergeTBAAInfoForCast(TBAAAccessInfo SourceInfo, TBAAAccessInfo TargetInfo)
mergeTBAAInfoForCast - Get merged TBAA information for the purposes of type casts.
Expr * GetTemporaryExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
llvm::Value * EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, bool isInc, bool isPre)
Address getAddress() const
Represents a class type in Objective C.
CGDebugInfo * getDebugInfo()
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
LValue EmitLValueForLambdaField(const FieldDecl *Field)
Given that we are currently emitting a lambda, emit an l-value for one of its members.
A C++ nested-name-specifier augmented with source location information.
std::pair< LValue, llvm::Value * > EmitARCStoreAutoreleasing(const BinaryOperator *e)
llvm::IntegerType * Int64Ty
llvm::Value * EmitDynamicCast(Address V, const CXXDynamicCastExpr *DCE)
SourceLocation getExprLoc() const LLVM_READONLY
llvm::Value * EmitObjCExtendObjectLifetime(QualType T, llvm::Value *Ptr)
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
field_range fields() const
LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E)
SourceLocation getBeginLoc() const LLVM_READONLY
Address EmitLoadOfReference(LValue RefLVal, LValueBaseInfo *PointeeBaseInfo=nullptr, TBAAAccessInfo *PointeeTBAAInfo=nullptr)
bool isVolatileQualified() const
Represents a member of a struct/union/class.
static llvm::Value * emitArraySubscriptGEP(CodeGenFunction &CGF, llvm::Value *ptr, ArrayRef< llvm::Value *> indices, bool inbounds, bool signedIndices, SourceLocation loc, const llvm::Twine &name="arrayidx")
CharUnits getAlignment() const
llvm::IntegerType * SizeTy
An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
LValue EmitCoyieldLValue(const CoyieldExpr *E)
virtual void EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dest, llvm::Value *ivarOffset)=0
LValue EmitOMPArraySectionExpr(const OMPArraySectionExpr *E, bool IsLowerBound=true)
SourceLocation getExprLoc() const LLVM_READONLY
bool isReferenceType() const
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
llvm::BasicBlock * getStartingBlock() const
Returns a block which will be executed prior to each evaluation of the conditional code...
static bool getRangeForType(CodeGenFunction &CGF, QualType Ty, llvm::APInt &Min, llvm::APInt &End, bool StrictEnums, bool IsBool)
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
static AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
forAddr - Make a slot for an aggregate value.
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 ...
__DEVICE__ int max(int __a, int __b)
void setBaseIvarExp(Expr *V)
bool isArrow() const
isArrow - Return true if the base expression is a pointer to vector, return false if the base express...
void InitTempAlloca(Address Alloca, llvm::Value *Value)
InitTempAlloca - Provide an initial value for the given alloca which will be observable at all locati...
RValue EmitLoadOfExtVectorElementLValue(LValue V)
static Address emitAddrOfFieldStorage(CodeGenFunction &CGF, Address base, const FieldDecl *field)
Drill down to the storage of a field without walking into reference types.
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
static bool isFlexibleArrayMemberExpr(const Expr *E)
Determine whether this expression refers to a flexible array member in a struct.
Selector getSelector() const
RValue EmitAnyExprToTemp(const Expr *E)
EmitAnyExprToTemp - Similarly to EmitAnyExpr(), however, the result will always be accessible even if...
void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, QualType Ty, AlignmentSource Source=AlignmentSource::Type, bool isInit=false, bool isNontemporal=false)
EmitStoreOfScalar - Store a scalar value to an address, taking care to appropriately convert from the...
ComplexPairTy EmitLoadOfComplex(LValue src, SourceLocation loc)
EmitLoadOfComplex - Load a complex number from the specified l-value.
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.
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.
const CXXPseudoDestructorExpr * getPseudoDestructorExpr() const
Describes an C or C++ initializer list.
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Address emitAddrOfRealComponent(Address complex, QualType complexType)
virtual llvm::Value * EmitIvarOffset(CodeGen::CodeGenFunction &CGF, const ObjCInterfaceDecl *Interface, const ObjCIvarDecl *Ivar)=0
unsigned Size
The total size of the bit-field, in bits.
bool isBitField() const
Determines whether this field is a bitfield.
static LValueOrRValue emitPseudoObjectExpr(CodeGenFunction &CGF, const PseudoObjectExpr *E, bool forLValue, AggValueSlot slot)
enum clang::SubobjectAdjustment::@47 Kind
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.
static LValue EmitFunctionDeclLValue(CodeGenFunction &CGF, const Expr *E, const FunctionDecl *FD)
void setDSOLocal(llvm::GlobalValue *GV) const
const FunctionDecl * getBuiltinDecl() const
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
bool isGlobalObjCRef() const
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
TBAAAccessInfo getTBAAAccessInfo(QualType AccessType)
getTBAAAccessInfo - Get TBAA information that describes an access to an object of the given type...
path_iterator path_begin()
unsigned char PointerWidthInBits
The width of a pointer into the generic address space.
CharUnits getAlignment() const
Return the alignment of this pointer.
static LValue MakeExtVectorElt(Address vecAddress, llvm::Constant *Elts, QualType type, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
llvm::PointerType * VoidPtrTy
void setFunctionPointer(llvm::Value *functionPtr)
void addCVRQualifiers(unsigned mask)
semantics_iterator semantics_end()
A builtin binary operation expression such as "x + y" or "x <= y".
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Checking the operand of a dynamic_cast or a typeid expression.
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum...
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.
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
llvm::Value * EmitARCLoadWeak(Address addr)
i8* @objc_loadWeak(i8** addr) Essentially objc_autorelease(objc_loadWeakRetained(addr)).
Scope - A scope is a transient data structure that is used while parsing the program.
LValue EmitCXXConstructLValue(const CXXConstructExpr *E)
RValue EmitSimpleCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue)
Emit a CallExpr without considering whether it might be a subclass.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
LValue EmitUnaryOpLValue(const UnaryOperator *E)
void addQualifiers(Qualifiers Q)
Add the qualifiers from the given set to this set.
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
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...
LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E)
unsigned Offset
The offset within a contiguous run of bitfields that are represented as a single "field" within the L...
void ForceCleanup(std::initializer_list< llvm::Value **> ValuesToReload={})
Force the emission of cleanups now, instead of waiting until this object is destroyed.
Represents binding an expression to a temporary.
llvm::Constant * CreateRuntimeVariable(llvm::Type *Ty, StringRef Name)
Create a new runtime global variable with the specified type and name.
CXXTemporary * getTemporary()
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
CharUnits getPointerAlign() const
static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts=false)
ContainsLabel - Return true if the statement contains a label in it.
void * getAsOpaquePtr() const
void incrementProfileCounter(const Stmt *S, llvm::Value *StepV=nullptr)
Increment the profiler's counter for the given statement by StepV.
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
CreateTempAlloca - This creates an alloca and inserts it into the entry block if ArraySize is nullptr...
void setARCPreciseLifetime(ARCPreciseLifetime_t value)
Represents an ObjC class declaration.
QualType getReturnType() const
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
RValue convertTempToRValue(Address addr, QualType type, SourceLocation Loc)
Given the address of a temporary variable, produce an r-value of its type.
Checking the operand of a cast to a virtual base object.
Address getAggregateAddress() const
getAggregateAddr() - Return the Value* of the address of the aggregate.
static CharUnits getArrayElementAlign(CharUnits arrayAlign, llvm::Value *idx, CharUnits eltSize)
virtual void mangleCXXRTTI(QualType T, raw_ostream &)=0
static bool ShouldNullCheckClassCastValue(const CastExpr *Cast)
llvm::Value * EmitCheckValue(llvm::Value *V)
Convert a value into a format suitable for passing to a runtime sanitizer handler.
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)
virtual llvm::Value * performAddrSpaceCast(CodeGen::CodeGenFunction &CGF, llvm::Value *V, LangAS SrcAddr, LangAS DestAddr, llvm::Type *DestTy, bool IsNonNull=false) const
Perform address space cast of an expression of pointer type.
Checking the 'this' pointer for a call to a non-static member function.
virtual void EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dest, bool threadlocal=false)=0
bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor)
isTypeConstant - Determine whether an object of this type can be emitted as a constant.
llvm::Value * EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty, SourceLocation Loc, AlignmentSource Source=AlignmentSource::Type, bool isNontemporal=false)
EmitLoadOfScalar - Load a scalar value from an address, taking care to appropriately convert from the...
LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E)
OpenMP 4.0 [2.4, Array Sections].
RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, ReturnValueSlot Return=ReturnValueSlot())
const ValueDecl * getExtendingDecl() const
Get the declaration which triggered the lifetime-extension of this temporary, if any.
void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest)
static CharUnits One()
One - Construct a CharUnits quantity of one.
std::pair< llvm::Value *, llvm::Value * > ComplexPairTy
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
ASTContext & getContext() const
Represents a prototype with parameter type info, e.g.
bool isDynamicClass() const
static bool canEmitSpuriousReferenceToVariable(CodeGenFunction &CGF, const DeclRefExpr *E, const VarDecl *VD, bool IsConstant)
Determine whether we can emit a reference to VD from the current context, despite not necessarily hav...
const TargetCodeGenInfo & getTargetCodeGenInfo()
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...
LValueBaseInfo getBaseInfo() const
static CheckRecoverableKind getRecoverableKind(SanitizerMask Kind)
RValue - This trivial value class is used to represent the result of an expression that is evaluated...
void EmitSanitizerStatReport(llvm::SanitizerStatKind SSK)
RValue EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue)
Address getExtVectorAddress() const
bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsLValue - Evaluate an expression to see if we can fold it to an lvalue with link time known ...
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.
const Type * getPointeeOrArrayElementType() const
If this is a pointer type, return the pointee type.
bool isPseudoDestructor() const
SourceLocation getLocation() const
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
llvm::Value * DecodeAddrUsedInPrologue(llvm::Value *F, llvm::Value *EncodedAddr)
Decode an address used in a function prologue, encoded by EncodeAddrForUseInPrologue.
Represents a call to the builtin function __builtin_va_arg.
Address CreateDefaultAlignTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
CreateDefaultAlignedTempAlloca - This creates an alloca with the default ABI alignment of the given L...
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
llvm::Value * emitScalarConstant(const ConstantEmission &Constant, Expr *E)
llvm::Value * EmitARCStoreWeak(Address addr, llvm::Value *value, bool ignored)
i8* @objc_storeWeak(i8** addr, i8* value) Returns value.
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
LValue EmitInitListLValue(const InitListExpr *E)
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst)
QualType getElementType() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
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...
This represents one expression.
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
const AnnotatedLine * Line
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited...
LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E)
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.
RValue EmitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *E)
void EmitCallArgs(CallArgList &Args, const T *CallArgTypeInfo, llvm::iterator_range< CallExpr::const_arg_iterator > ArgRange, AbstractCallee AC=AbstractCallee(), unsigned ParamsToSkip=0, EvaluationOrder Order=EvaluationOrder::Default)
EmitCallArgs - Emit call arguments for a function.
llvm::Constant * GetAddrOfGlobalVar(const VarDecl *D, llvm::Type *Ty=nullptr, ForDefinition_t IsForDefinition=NotForDefinition)
Return the llvm::Constant for the address of the given global variable.
const T * castAs() const
Member-template castAs<specific type>.
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why? This is only meaningful if the named memb...
void setObjCArray(bool Value)
unsigned getLine() const
Return the presumed line number of this location.
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
This name appears as a potential result of an lvalue-to-rvalue conversion that is a constant expressi...
Represents a C++ destructor within a class.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
static LValue EmitCapturedFieldLValue(CodeGenFunction &CGF, const FieldDecl *FD, llvm::Value *ThisValue)
llvm::hash_code hash_value(const clang::SanitizerMask &Arg)
void SetFPAccuracy(llvm::Value *Val, float Accuracy)
SetFPAccuracy - Set the minimum required accuracy of the given floating point operation, expressed as the maximum relative error in ulp.
AggValueSlot CreateAggTemp(QualType T, const Twine &Name="tmp")
CreateAggTemp - Create a temporary memory object for the given aggregate type.
VlaSizePair getVLASize(const VariableArrayType *vla)
Returns an LLVM value that corresponds to the size, in non-variably-sized elements, of a variable length array type, plus that largest non-variably-sized element type.
static bool isVptrCheckRequired(TypeCheckKind TCK, QualType Ty)
Determine whether the pointer type check TCK requires a vptr check.
llvm::PointerType * getType() const
Return the type of the pointer value.
ObjCLifetime getObjCLifetime() const
static Address emitDeclTargetVarDeclLValue(CodeGenFunction &CGF, const VarDecl *VD, QualType T)
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
DeclContext * getDeclContext()
llvm::Value * EmitToMemory(llvm::Value *Value, QualType Ty)
EmitToMemory - Change a scalar value from its value representation to its in-memory representation...
bool isAnyComplexType() const
ObjCSelectorExpr used for @selector in Objective-C.
TLSKind getTLSKind() const
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
static Optional< LValue > EmitLValueOrThrowExpression(CodeGenFunction &CGF, const Expr *Operand)
Emit the operand of a glvalue conditional operator.
static LValue MakeBitfield(Address Addr, const CGBitFieldInfo &Info, QualType type, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
Create a new object to represent a bit-field access.
llvm::LLVMContext & getLLVMContext()
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.
llvm::IntegerType * Int32Ty
void EmitNullabilityCheck(LValue LHS, llvm::Value *RHS, SourceLocation Loc)
Given an assignment *LHS = RHS, emit a test that checks if RHS is nonnull, if LHS is marked _Nonnull...
llvm::GlobalValue::LinkageTypes getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant)
Returns LLVM linkage for a declarator.
TBAAAccessInfo getTBAAInfo() const
void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *V, QualType Type, CharUnits Alignment=CharUnits::Zero(), SanitizerSet SkippedChecks=SanitizerSet(), llvm::Value *ArraySize=nullptr)
Emit a check that V is the address of storage of the appropriate size and alignment for an object of ...
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T)
An expression that sends a message to the given Objective-C object or class.
ConstantAddress GetAddrOfUuidDescriptor(const CXXUuidofExpr *E)
Get the address of a uuid descriptor .
ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV, bool isInc, bool isPre)
QualType getRecordType(const RecordDecl *Decl) const
Represents an unpacked "presumed" location which can be presented to the user.
QualType getFunctionTypeWithExceptionSpec(QualType Orig, const FunctionProtoType::ExceptionSpecInfo &ESI)
Get a function type and produce the equivalent function type with the specified exception specificati...
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.
ConstantEmission tryEmitAsConstant(DeclRefExpr *refExpr)
Try to emit a reference to the given value without producing it as an l-value.
The scope of a CXXDefaultInitExpr.
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
RValue EmitLoadOfGlobalRegLValue(LValue LV)
Load of global gamed gegisters are always calls to intrinsics.
Expr * getTrueExpr() const
const Qualifiers & getQuals() const
const LangOptions & getLangOpts() const
bool isObjCStrong() const
const Expr * getSubExpr() const
ASTContext & getContext() const
bool isNull() const
Return true if this QualType doesn't point to a type yet.
RValue EmitLoadOfBitfieldLValue(LValue LV, SourceLocation Loc)
ConstantEmissionKind
Can we constant-emit a load of a reference to a variable of the given type? This is different from pr...
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
RValue EmitAtomicLoad(LValue LV, SourceLocation SL, AggValueSlot Slot=AggValueSlot::ignored())
Address GetAddrOfBlockDecl(const VarDecl *var)
static bool shouldBindAsLValue(const Expr *expr)
const SanitizerBlacklist & getSanitizerBlacklist() const
GlobalDecl - represents a global declaration.
TBAAAccessInfo mergeTBAAInfoForConditionalOperator(TBAAAccessInfo InfoA, TBAAAccessInfo InfoB)
mergeTBAAInfoForConditionalOperator - Get merged TBAA information for the purposes of conditional ope...
bool isThreadLocalRef() const
ConstantAddress GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E, const Expr *Inner)
Returns a pointer to a global variable representing a temporary with static or thread storage duratio...
LValue EmitLoadOfPointerLValue(Address Ptr, const PointerType *PtrTy)
Dynamic storage duration.
The l-value was considered opaque, so the alignment was determined from a type.
RecordDecl * getDecl() const
const char * getFilename() const
Return the presumed filename of this location.
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
CGCallee EmitCallee(const Expr *E)
llvm::Constant * getOrCreateStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsRValue - Return true if this is a constant which we can fold to an rvalue using any crazy t...
There is no lifetime qualification on this type.
const SanitizerHandlerInfo SanitizerHandlers[]
virtual llvm::Value * getContextValue() const
unsigned getDebugInfoFIndex(const RecordDecl *Rec, unsigned FieldIndex)
Get the record field index as represented in debug info.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
void set(SanitizerMask K, bool Value)
Enable or disable a certain (single) sanitizer.
Address CreateBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
__INTPTR_TYPE__ intptr_t
A signed integer type with the property that any valid pointer to void can be converted to this type...
static StringRef getIdentKindName(IdentKind IK)
Assigning into this object requires the old value to be released and the new value to be retained...
QualType getCanonicalType() const
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.
LValue EmitVAArgExprLValue(const VAArgExpr *E)
llvm::Value * EmitCXXTypeidExpr(const CXXTypeidExpr *E)
unsigned getColumn() const
Return the presumed column number of this location.
StringLiteral * getFunctionName()
void pushDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
pushDestroy - Push the standard destructor for the given type as at least a normal cleanup...
static llvm::Constant * EmitFunctionDeclPointer(CodeGenModule &CGM, const FunctionDecl *FD)
Encodes a location in the source.
bool LValueIsSuitableForInlineAtomic(LValue Src)
An LValue is a candidate for having its loads and stores be made atomic if we are operating under /vo...
void EnsureInsertPoint()
EnsureInsertPoint - Ensure that an insertion point is defined so that emitted IR has a place to go...
virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, QualType ObjectTy, llvm::Value *BaseValue, const ObjCIvarDecl *Ivar, unsigned CVRQualifiers)=0
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
llvm::Constant * getTypeDescriptorFromMap(QualType Ty)
LValue EmitDeclRefLValue(const DeclRefExpr *E)
LangAS getAddressSpace() const
Return the address space of this type.
llvm::MDNode * BaseType
BaseType - The base/leading access type.
Expr * getSubExpr() const
llvm::Value * EvaluateExprAsBool(const Expr *E)
EvaluateExprAsBool - Perform the usual unary conversions on the specified expression and compare the ...
LValue EmitCheckedLValue(const Expr *E, TypeCheckKind TCK)
Same as EmitLValue but additionally we generate checking code to guard against undefined behavior...
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
llvm::Value * EmitFromMemory(llvm::Value *Value, QualType Ty)
EmitFromMemory - Change a scalar value from its memory representation to its value representation...
unsigned getBlockId(const BlockDecl *BD, bool Local)
CastKind getCastKind() const
Expr * getBaseIvarExp() const
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **callOrInvoke, SourceLocation Loc)
EmitCall - Generate a call of the given function, expecting the given result type, and using the given argument list which specifies both the LLVM arguments and the types they were derived from.
bool IsInPreservedAIRegion
True if CodeGen currently emits code inside presereved access index region.
CharUnits getNaturalPointeeTypeAlignment(QualType T, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
const CGBitFieldInfo & getBitFieldInfo() const
LValue EmitAggExprToLValue(const Expr *E)
EmitAggExprToLValue - Emit the computation of the specified expression of aggregate type into a tempo...
llvm::Metadata * CreateMetadataIdentifierForType(QualType T)
Create a metadata identifier for the given type.
QualType getElementType() const
const Decl * getDecl() const
Checking the operand of a cast to a base object.
Address CreateConstArrayGEP(Address Addr, uint64_t Index, const llvm::Twine &Name="")
Given addr = [n x T]* ...
void ConvertArgToString(ArgumentKind Kind, intptr_t Val, StringRef Modifier, StringRef Argument, ArrayRef< ArgumentValue > PrevArgs, SmallVectorImpl< char > &Output, ArrayRef< intptr_t > QualTypeVals) const
Converts a diagnostic argument (as an intptr_t) into the string that represents it.
A scoped helper to set the current debug location to the specified location or preferred location of ...
llvm::Value * EmitLifetimeStart(uint64_t Size, llvm::Value *Addr)
Emit a lifetime.begin marker if some criteria are satisfied.
LValue EmitUnsupportedLValue(const Expr *E, const char *Name)
EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue an ErrorUnsupported style ...
Represents a static or instance method of a struct/union/class.
static bool hasAnyVptr(const QualType Type, const ASTContext &Context)
ConstantAddress GetAddrOfConstantStringFromLiteral(const StringLiteral *S, StringRef Name=".str")
Return a pointer to a constant array for the given string literal.
static LValue EmitGlobalVarDeclLValue(CodeGenFunction &CGF, const Expr *E, const VarDecl *VD)
SourceLocation getColonLoc() const
llvm::Metadata * CreateMetadataIdentifierGeneralized(QualType T)
Create a metadata identifier for the generalization of the given type.
virtual Address GetAddrOfSelector(CodeGenFunction &CGF, Selector Sel)=0
Get the address of a selector for the specified name and type values.
SanitizerSet SanOpts
Sanitizers enabled for this function.
static QualType getFixedSizeElementType(const ASTContext &ctx, const VariableArrayType *vla)
llvm::Constant * GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH=false)
Get the address of the RTTI descriptor for the given type.
bool isNontemporal() const
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType, Address Ptr)
Emits all the code to cause the given temporary to be cleaned up.
llvm::Constant * emitAbstract(const Expr *E, QualType T)
Emit the result of the given expression as an abstract constant, asserting that it succeeded...
SanitizerSet SanitizeTrap
Set of sanitizer checks that trap rather than diagnose.
bool isObjCObjectPointerType() const
TypeCheckKind
Situations in which we might emit a check for the suitability of a pointer or glvalue.
llvm::MDNode * getTBAATypeInfo(QualType QTy)
getTBAATypeInfo - Get metadata used to describe accesses to objects of the given type.
ConstantAddress GetWeakRefReference(const ValueDecl *VD)
Get a reference to the target of VD.
Address createUnnamedGlobalFrom(const VarDecl &D, llvm::Constant *Constant, CharUnits Align)
void StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn, const CGFunctionInfo &FnInfo, const FunctionArgList &Args, SourceLocation Loc=SourceLocation(), SourceLocation StartLoc=SourceLocation())
Emit code for the start of a function.
void setObjCIvar(bool Value)
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after...
uint64_t Size
Size - The size of access, in bytes.
All available information about a concrete callee.
Address getVectorAddress() const
MangleContext & getMangleContext()
Gets the mangle context.
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required...
Address EmitArrayToPointerDecay(const Expr *Array, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E)
EnumDecl * getDecl() const
const ObjCMethodDecl * getMethodDecl() const
bool isVectorType() const
Checking the object expression in a non-static data member access.
Assigning into this object requires a lifetime extension.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
CharUnits getNaturalTypeAlignment(QualType T, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr, bool forPointeeType=false)
RValue EmitCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue=ReturnValueSlot())
llvm::Value * EmitARCRetain(QualType type, llvm::Value *value)
Produce the code to do a retain.
static ConstantEmission forReference(llvm::Constant *C)
const TargetCodeGenInfo & getTargetHooks() const
static Destroyer destroyARCStrongImprecise
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
const Expr * getInitializer() const
ConstantAddress GetAddrOfConstantCString(const std::string &Str, const char *GlobalName=nullptr)
Returns a pointer to a character array containing the literal and a terminating '\0' character...
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.
const Expr * getBase() const
decl_iterator - Iterates through the declarations stored within this context.
! Language semantics require right-to-left evaluation.
void addUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.used metadata.
FunctionArgList - Type for representing both the decl and type of parameters to a function...
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
ast_type_traits::DynTypedNode Node
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
TLS with a dynamic initializer.
CGFunctionInfo - Class to encapsulate the information about a function definition.
This class organizes the cross-function state that is used while generating LLVM code.
CharUnits alignmentAtOffset(CharUnits offset) const
Given that this is a non-zero alignment value, what is the alignment at the given offset...
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
void EmitDeclRefExprDbgValue(const DeclRefExpr *E, const APValue &Init)
Dataflow Directional Tag Classes.
LValue EmitLoadOfReferenceLValue(LValue RefLVal)
bool isValid() const
Return true if this is a valid SourceLocation object.
void EmitVTablePtrCheckForCast(QualType T, llvm::Value *Derived, bool MayBeNull, CFITypeCheckKind TCK, SourceLocation Loc)
Derived is the presumed address of an object of type T after a cast.
[C99 6.4.2.2] - A predefined identifier such as func.
Address EmitFieldAnnotations(const FieldDecl *D, Address V)
Emit field annotations for the given field & value.
RValue EmitUnsupportedRValue(const Expr *E, const char *Name)
EmitUnsupportedRValue - Emit a dummy r-value using the type of E and issue an ErrorUnsupported style ...
static bool shouldBindAsLValue(const Expr *expr)
static RValue getComplex(llvm::Value *V1, llvm::Value *V2)
EvalResult is a struct with detailed info about an evaluated expression.
Decl * getReferencedDeclOfCallee()
llvm::MDNode * getTBAABaseTypeInfo(QualType QTy)
getTBAABaseTypeInfo - Get metadata that describes the given base access type.
static AggValueSlot ignored()
ignored - Returns an aggregate value slot indicating that the aggregate value is being ignored...
llvm::Value * EmitARCLoadWeakRetained(Address addr)
i8* @objc_loadWeakRetained(i8** addr)
static CGCallee forBuiltin(unsigned builtinID, const FunctionDecl *builtinDecl)
LValue getOrCreateOpaqueLValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its LValue mapping if it exists, otherwise create one...
llvm::LoadInst * CreateAlignedLoad(llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
Checking the bound value in a reference binding.
LValue EmitCallExprLValue(const CallExpr *E)
bool isInConditionalBranch() const
isInConditionalBranch - Return true if we're currently emitting one branch or the other of a conditio...
LValue EmitPseudoObjectLValue(const PseudoObjectExpr *e)
unsigned IsSigned
Whether the bit-field is signed.
llvm::Constant * getPointer() const
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
llvm::IntegerType * IntPtrTy
StmtClass getStmtClass() const
virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D, llvm::FunctionCallee Dtor, llvm::Constant *Addr)=0
Emit code to force the execution of a destructor during global teardown.
bool isBooleanType() const
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
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.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
Checking the destination of a store. Must be suitably sized and aligned.
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type *> Tys=None)
A pointer to member type per C++ 8.3.3 - Pointers to members.
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
semantics_iterator semantics_begin()
llvm::Module & getModule() const
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
ExplicitCastExpr - An explicit cast written in the source code.
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
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 EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type. ...
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
unsigned getBuiltinID() const
static Address emitAddrOfZeroSizeField(CodeGenFunction &CGF, Address Base, const FieldDecl *Field)
Get the address of a zero-sized field within a record.
Checking the operand of a static_cast to a derived reference type.
static bool hasAggregateEvaluationKind(QualType T)
virtual void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dest)=0
void EmitExplicitCastExprType(const ExplicitCastExpr *E, CodeGenFunction *CGF=nullptr)
Emit type info if type of an expression is a variably modified type.
bool HasSideEffects
Whether the evaluated expression has side effects.
virtual llvm::Optional< LangAS > getConstantAddressSpace() const
Return an AST address space which can be used opportunistically for constant global memory...
AlignmentSource getAlignmentSource() const
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.
Checking the operand of a static_cast to a derived pointer type.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
void DecorateInstructionWithTBAA(llvm::Instruction *Inst, TBAAAccessInfo TBAAInfo)
DecorateInstructionWithTBAA - Decorate the instruction with a TBAA tag.
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
CodeGenTypes & getTypes() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
RValue GetUndefRValue(QualType Ty)
GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
Address getBitFieldAddress() const
ObjCEncodeExpr, used for @encode in Objective-C.
virtual bool usesThreadWrapperFunction() const =0
LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E, bool Accessed=false)
llvm::Type * getElementType() const
Return the type of the values stored in this address.
uint64_t getCharWidth() const
Return the size of the character type, in bits.
bool isAtomicType() const
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
static Address emitOMPArraySectionBase(CodeGenFunction &CGF, const Expr *Base, LValueBaseInfo &BaseInfo, TBAAAccessInfo &TBAAInfo, QualType BaseTy, QualType ElTy, bool IsLowerBound)
bool isFunctionType() const
llvm::Value * EmitCheckedInBoundsGEP(llvm::Value *Ptr, ArrayRef< llvm::Value *> IdxList, bool SignedIndices, bool IsSubtraction, SourceLocation Loc, const Twine &Name="")
Same as IRBuilder::CreateInBoundsGEP, but additionally emits a check to detect undefined behavior whe...
RValue EmitRValueForField(LValue LV, const FieldDecl *FD, SourceLocation Loc)
llvm::PointerType * Int8PtrTy
llvm::AssertingVH< llvm::Instruction > AllocaInsertPt
AllocaInsertPoint - This is an instruction in the entry block before which we prefer to insert alloca...
static CGCallee forPseudoDestructor(const CXXPseudoDestructorExpr *E)
LValue EmitLValueForIvar(QualType ObjectTy, llvm::Value *Base, const ObjCIvarDecl *Ivar, unsigned CVRQualifiers)
static llvm::Value * emitHash16Bytes(CGBuilderTy &Builder, llvm::Value *Low, llvm::Value *High)
Emit the hash_16_bytes function from include/llvm/ADT/Hashing.h.
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
llvm::Constant * GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty=nullptr, bool ForVTable=false, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the given function.
llvm::Value * EmitIvarOffset(const ObjCInterfaceDecl *Interface, const ObjCIvarDecl *Ivar)
static void emitCheckHandlerCall(CodeGenFunction &CGF, llvm::FunctionType *FnType, ArrayRef< llvm::Value *> FnArgs, SanitizerHandler CheckHandler, CheckRecoverableKind RecoverKind, bool IsFatal, llvm::BasicBlock *ContBB)
LValue EmitCastLValue(const CastExpr *E)
EmitCastLValue - Casts are never lvalues unless that cast is to a reference type. ...
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
llvm::FunctionCallee CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList(), bool Local=false)
Create or return a runtime function declaration with the specified type and name. ...
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
void setGlobalObjCRef(bool Value)
void EmitARCInitWeak(Address addr, llvm::Value *value)
i8* @objc_initWeak(i8** addr, i8* value) Returns value.
void EmitCfiSlowPathCheck(SanitizerMask Kind, llvm::Value *Cond, llvm::ConstantInt *TypeId, llvm::Value *Ptr, ArrayRef< llvm::Constant *> StaticArgs)
Emit a slow path cross-DSO CFI check which calls __cfi_slowpath if Cond if false. ...
const Expr * getBase() const
ConstantAddress GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr *E)
Returns a pointer to a constant global variable for the given file-scope compound literal expression...
void EmitUnreachable(SourceLocation Loc)
Emit a reached-unreachable diagnostic if Loc is valid and runtime checking is enabled.
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.
RValue asAggregateRValue() const
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
ObjCIvarRefExpr - A reference to an ObjC instance variable.
SourceManager & getSourceManager()
LValue EmitConditionalOperatorLValue(const AbstractConditionalOperator *E)
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
llvm::ConstantInt * getSize(CharUnits numChars)
Emit the given number of characters as a value of type size_t.
RValue getOrCreateOpaqueRValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its RValue mapping if it exists, otherwise create one...
QualType withCVRQualifiers(unsigned CVR) const
virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dest)=0
Address CreateTempAllocaWithoutCast(llvm::Type *Ty, CharUnits align, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
CreateTempAlloca - This creates a alloca and inserts it into the entry block.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
uint64_t getFieldOffset(const ValueDecl *FD) const
Get the offset of a FieldDecl or IndirectFieldDecl, in bits.
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
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...
llvm::FunctionCallee getAddrAndTypeOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
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.
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
void ErrorUnsupported(const Stmt *S, const char *Type)
ErrorUnsupported - Print out an error that codegen doesn't support the specified stmt yet...
Represents a C++ struct/union/class.
static const SanitizerMask Unrecoverable
LValue EmitCoawaitLValue(const CoawaitExpr *E)
static bool isNullPointerAllowed(TypeCheckKind TCK)
Determine whether the pointer type check TCK permits null pointers.
static QualType getBaseOriginalType(const Expr *Base)
Return original type of the base expression for array section.
llvm::Type * ConvertType(QualType T)
static Destroyer destroyCXXObject
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
A specialization of Address that requires the address to be an LLVM Constant.
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
ObjCIvarDecl - Represents an ObjC instance variable.
! No language constraints on evaluation order.
static CGCallee EmitDirectCallee(CodeGenFunction &CGF, const FunctionDecl *FD)
const GlobalDecl getCalleeDecl() const
LValue EmitLValue(const Expr *E)
EmitLValue - Emit code to compute a designator that specifies the location of the expression...
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
void EmitTrapCheck(llvm::Value *Checked)
Create a basic block that will call the trap intrinsic, and emit a conditional branch to it...
static Address emitPreserveStructAccess(CodeGenFunction &CGF, Address base, const FieldDecl *field)
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.
unsigned getVRQualifiers() const
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
llvm::ConstantInt * CreateCrossDsoCfiTypeId(llvm::Metadata *MD)
Generate a cross-DSO type identifier for MD.
LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E)
__DEVICE__ int min(int __a, int __b)
RValue EmitLoadOfLValue(LValue V, SourceLocation Loc)
EmitLoadOfLValue - Given an expression that represents a value lvalue, this method emits the address ...
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
LValue EmitPredefinedLValue(const PredefinedExpr *E)
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]).
static bool IsWrappedCXXThis(const Expr *E)
Check if E is a C++ "this" pointer wrapped in value-preserving casts.
Address EmitCXXUuidofExpr(const CXXUuidofExpr *E)
const MemberPointerType * MPT
LangAS getASTAllocaAddressSpace() const
Address EmitExtVectorElementLValue(LValue V)
Generates lvalue for partial ext_vector access.
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
llvm::Constant * tryEmitAbstract(const Expr *E, QualType T)
Try to emit the result of the given expression as an abstract constant.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
unsigned getCVRQualifiers() const
LValue EmitCompoundAssignmentLValue(const CompoundAssignOperator *E)
CGCapturedStmtInfo * CapturedStmtInfo
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...
CGCXXABI & getCXXABI() const
const VariableArrayType * getAsVariableArrayType(QualType T) const
std::string TrapFuncName
If not an empty string, trap intrinsics are lowered to calls to this function instead of to trap inst...
static LValue MakeGlobalReg(Address Reg, QualType type)
unsigned getNumElements() const
LValue EmitMemberExpr(const MemberExpr *E)
A reference to a declared variable, function, enum, etc.
static RValue get(llvm::Value *V)
RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue)
static ConstantEmissionKind checkVarTypeForConstantEmission(QualType type)
bool isPointerType() const
bool isExtVectorElt() const
const CGFunctionInfo & arrangeFreeFunctionCall(const CallArgList &Args, const FunctionType *Ty, bool ChainCall)
Figure out the rules for calling a function with the given formal type using the given arguments...
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
llvm::Constant * EmitCheckSourceLocation(SourceLocation Loc)
Emit a description of a source location in a format suitable for passing to a runtime sanitizer handl...
uint64_t Offset
Offset - The byte offset of the final access within the base one.
bool isOBJCGCCandidate(ASTContext &Ctx) const
isOBJCGCCandidate - Return true if this expression may be used in a read/ write barrier.
bool isFloatingType() const
static RValue getAggregate(Address addr, bool isVolatile=false)
LValue - This represents an lvalue references.
SourceLocation getBeginLoc() const LLVM_READONLY
This represents a decl that may have a name.
llvm::Value * EmitObjCConsumeObject(QualType T, llvm::Value *Ptr)
Produce the code for a CK_ARCConsumeObject.
CGCalleeInfo getAbstractInfo() const
Represents a C array with a specified size that is not an integer-constant-expression.
bool DeclMustBeEmitted(const Decl *D)
Determines if the decl can be CodeGen'ed or deserialized from PCH lazily, only when used; this is onl...
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
Automatic storage duration (most local variables).
SanitizerMetadata * getSanitizerMetadata()
const LangOptions & getLangOpts() const
unsigned getTargetAddressSpace(QualType T) const
void EmitCfiCheckStub()
Emit a stub for the cross-DSO CFI check function.
llvm::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
const CXXRecordDecl * DerivedClass
bool isFunctionPointerType() const
RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, const CXXMethodDecl *MD, ReturnValueSlot ReturnValue)
static LValue MakeAddr(Address address, QualType type, ASTContext &Context, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
llvm::Value * getVectorIdx() const
bool isZeroSize(const ASTContext &Ctx) const
Determine if this field is a subobject of zero size, that is, either a zero-length bit-field or a fie...
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.
const LangOptions & getLangOpts() const
static TBAAAccessInfo getMayAliasInfo()
llvm::Value * getPointer() const
LValue EmitStringLiteralLValue(const StringLiteral *E)
Defines enum values for all the target-independent builtin functions.
Address emitBlockByrefAddress(Address baseAddr, const VarDecl *V, bool followForward=true)
BuildBlockByrefAddress - Computes the location of the data in a variable which is declared as __block...
Abstract information about a function or function prototype.
void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint=true)
SourceLocation getLocation() const
void mergeForCast(const LValueBaseInfo &Info)
llvm::Constant * getExtVectorElts() const
Expr * getLength()
Get length of array section.
Structure with information about how a bitfield should be accessed.
CheckRecoverableKind
Specify under what conditions this check can be recovered.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point...
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> PL, ArrayRef< Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
void Destroyer(CodeGenFunction &CGF, Address addr, QualType ty)
static CharUnits getDeclAlign(Expr *E, CharUnits TypeAlign, ASTContext &Context)
A helper function to get the alignment of a Decl referred to by DeclRefExpr or MemberExpr.
Expr * getBase()
An array section can be written only as Base[LowerBound:Length].
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
unsigned getLLVMFieldNo(const FieldDecl *FD) const
Return llvm::StructType element number that corresponds to the field FD.
virtual llvm::Value * EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF, Address AddrWeakObj)=0
SourceLocation getExprLoc() const
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
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 ...