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.getAsAlign());
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)
522 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(*
this);
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;
680 auto PtrToAlloca = dyn_cast<llvm::AllocaInst>(Ptr->stripPointerCasts());
684 bool IsGuaranteedNonNull =
688 !IsGuaranteedNonNull) {
690 IsNonNull =
Builder.CreateIsNotNull(Ptr);
694 IsGuaranteedNonNull = IsNonNull == True;
697 if (!IsGuaranteedNonNull) {
698 if (AllowNullPointers) {
703 Builder.CreateCondBr(IsNonNull, Rest, Done);
712 !SkippedChecks.
has(SanitizerKind::ObjectSize) &&
717 Size =
Builder.CreateMul(Size, ArraySize);
720 llvm::Constant *ConstantSize = dyn_cast<llvm::Constant>(Size);
721 if (!ConstantSize || !ConstantSize->isNullValue()) {
727 llvm::Function *F =
CGM.
getIntrinsic(llvm::Intrinsic::objectsize, Tys);
733 Builder.CreateCall(F, {CastAddr, Min, NullIsUnknown, Dynamic}), Size);
734 Checks.push_back(std::make_pair(LargeEnough, SanitizerKind::ObjectSize));
738 uint64_t AlignVal = 0;
742 !SkippedChecks.
has(SanitizerKind::Alignment)) {
749 (!PtrToAlloca || PtrToAlloca->getAlignment() < AlignVal)) {
752 PtrAsInt, llvm::ConstantInt::get(
IntPtrTy, AlignVal - 1));
756 Checks.push_back(std::make_pair(Aligned, SanitizerKind::Alignment));
760 if (Checks.size() > 0) {
763 assert(!AlignVal || (uint64_t)1 << llvm::Log2_64(AlignVal) == AlignVal);
764 llvm::Constant *StaticData[] = {
766 llvm::ConstantInt::get(
Int8Ty, AlignVal ? llvm::Log2_64(AlignVal) : 1),
767 llvm::ConstantInt::get(
Int8Ty, TCK)};
768 EmitCheck(Checks, SanitizerHandler::TypeMismatch, StaticData,
769 PtrAsInt ? PtrAsInt : Ptr);
784 if (!IsGuaranteedNonNull) {
786 IsNonNull =
Builder.CreateIsNotNull(Ptr);
790 Builder.CreateCondBr(IsNonNull, VptrNotNull, Done);
800 llvm::raw_svector_ostream Out(MangledName);
806 SanitizerKind::Vptr, Out.str())) {
807 llvm::hash_code TypeHash =
hash_value(Out.str());
820 const int CacheSize = 128;
823 "__ubsan_vptr_type_cache");
837 llvm::Constant *StaticData[] = {
841 llvm::ConstantInt::get(
Int8Ty, TCK)
844 EmitCheck(std::make_pair(EqualHash, SanitizerKind::Vptr),
845 SanitizerHandler::DynamicTypeCacheMiss, StaticData,
862 if (
const auto *CAT = dyn_cast<ConstantArrayType>(AT)) {
863 if (CAT->getSize().ugt(1))
865 }
else if (!isa<IncompleteArrayType>(AT))
871 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
874 if (
const auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
877 return ++FI == FD->getParent()->field_end();
879 }
else if (
const auto *IRE = dyn_cast<ObjCIvarRefExpr>(E)) {
880 return IRE->getDecl()->getNextIvar() ==
nullptr;
897 auto *ParamDecl = dyn_cast<
ParmVarDecl>(ArrayDeclRef->getDecl());
901 auto *POSAttr = ParamDecl->
getAttr<PassObjectSizeAttr>();
906 int POSType = POSAttr->getType();
907 if (POSType != 0 && POSType != 1)
911 auto PassedSizeIt = SizeArguments.find(ParamDecl);
912 if (PassedSizeIt == SizeArguments.end())
916 assert(LocalDeclMap.count(PassedSizeDecl) &&
"Passed size not loadable");
917 Address AddrOfSize = LocalDeclMap.find(PassedSizeDecl)->second;
921 llvm::ConstantInt::get(SizeInBytes->getType(), EltSize);
922 return Builder.CreateUDiv(SizeInBytes, SizeOfElement);
932 return CGF.
Builder.getInt32(VT->getNumElements());
937 if (
const auto *CE = dyn_cast<CastExpr>(Base)) {
938 if (CE->getCastKind() == CK_ArrayToPointerDecay &&
940 IndexedType = CE->getSubExpr()->getType();
942 if (
const auto *CAT = dyn_cast<ConstantArrayType>(AT))
943 return CGF.
Builder.getInt(CAT->getSize());
944 else if (
const auto *VAT = dyn_cast<VariableArrayType>(AT))
962 assert(
SanOpts.
has(SanitizerKind::ArrayBounds) &&
963 "should not be called unless adding bounds checks");
975 llvm::Constant *StaticData[] = {
981 :
Builder.CreateICmpULE(IndexVal, BoundVal);
982 EmitCheck(std::make_pair(Check, SanitizerKind::ArrayBounds),
983 SanitizerHandler::OutOfBounds, StaticData, Index);
989 bool isInc,
bool isPre) {
993 if (isa<llvm::IntegerType>(InVal.first->getType())) {
994 uint64_t AmountVal = isInc ? 1 : -1;
995 NextVal = llvm::ConstantInt::get(InVal.first->getType(), AmountVal,
true);
998 NextVal =
Builder.CreateAdd(InVal.first, NextVal, isInc ?
"inc" :
"dec");
1001 llvm::APFloat FVal(
getContext().getFloatTypeSemantics(ElemTy), 1);
1007 NextVal =
Builder.CreateFAdd(InVal.first, NextVal, isInc ?
"inc" :
"dec");
1020 return isPre ? IncVal : InVal;
1030 DI->EmitExplicitCastType(E->
getType());
1048 if (
const CastExpr *CE = dyn_cast<CastExpr>(E)) {
1049 if (
const auto *ECE = dyn_cast<ExplicitCastExpr>(CE))
1052 switch (CE->getCastKind()) {
1056 case CK_AddressSpaceConversion:
1057 if (
auto PtrTy = CE->getSubExpr()->getType()->getAs<
PointerType>()) {
1058 if (PtrTy->getPointeeType()->isVoidType())
1066 if (BaseInfo) *BaseInfo = InnerBaseInfo;
1067 if (TBAAInfo) *TBAAInfo = InnerTBAAInfo;
1069 if (isa<ExplicitCastExpr>(CE)) {
1073 &TargetTypeBaseInfo,
1074 &TargetTypeTBAAInfo);
1077 TargetTypeTBAAInfo);
1087 if (
SanOpts.
has(SanitizerKind::CFIUnrelatedCast) &&
1088 CE->getCastKind() == CK_BitCast) {
1095 return CE->getCastKind() != CK_AddressSpaceConversion
1103 case CK_ArrayToPointerDecay:
1107 case CK_UncheckedDerivedToBase:
1108 case CK_DerivedToBase: {
1115 auto Derived = CE->getSubExpr()->
getType()->getPointeeCXXRecordDecl();
1117 CE->path_begin(), CE->path_end(),
1131 if (UO->getOpcode() == UO_AddrOf) {
1170 llvm_unreachable(
"bad evaluation kind");
1189 while (!isa<CXXThisExpr>(Base)) {
1191 if (isa<CXXDynamicCastExpr>(Base))
1194 if (
const auto *CE = dyn_cast<CastExpr>(Base)) {
1195 Base = CE->getSubExpr();
1196 }
else if (
const auto *PE = dyn_cast<ParenExpr>(Base)) {
1197 Base = PE->getSubExpr();
1198 }
else if (
const auto *UO = dyn_cast<UnaryOperator>(Base)) {
1199 if (UO->getOpcode() == UO_Extension)
1200 Base = UO->getSubExpr();
1212 if (
SanOpts.
has(SanitizerKind::ArrayBounds) && isa<ArraySubscriptExpr>(E))
1218 if (
const auto *ME = dyn_cast<MemberExpr>(E)) {
1221 SkippedChecks.
set(SanitizerKind::Alignment,
true);
1222 if (IsBaseCXXThis || isa<DeclRefExpr>(ME->getBase()))
1251 case Expr::ObjCPropertyRefExprClass:
1252 llvm_unreachable(
"cannot emit a property reference directly");
1254 case Expr::ObjCSelectorExprClass:
1256 case Expr::ObjCIsaExprClass:
1258 case Expr::BinaryOperatorClass:
1260 case Expr::CompoundAssignOperatorClass: {
1263 Ty = AT->getValueType();
1268 case Expr::CallExprClass:
1269 case Expr::CXXMemberCallExprClass:
1270 case Expr::CXXOperatorCallExprClass:
1271 case Expr::UserDefinedLiteralClass:
1273 case Expr::CXXRewrittenBinaryOperatorClass:
1274 return EmitLValue(cast<CXXRewrittenBinaryOperator>(E)->getSemanticForm());
1275 case Expr::VAArgExprClass:
1277 case Expr::DeclRefExprClass:
1279 case Expr::ConstantExprClass:
1280 return EmitLValue(cast<ConstantExpr>(E)->getSubExpr());
1281 case Expr::ParenExprClass:
1282 return EmitLValue(cast<ParenExpr>(E)->getSubExpr());
1283 case Expr::GenericSelectionExprClass:
1284 return EmitLValue(cast<GenericSelectionExpr>(E)->getResultExpr());
1285 case Expr::PredefinedExprClass:
1287 case Expr::StringLiteralClass:
1289 case Expr::ObjCEncodeExprClass:
1291 case Expr::PseudoObjectExprClass:
1293 case Expr::InitListExprClass:
1295 case Expr::CXXTemporaryObjectExprClass:
1296 case Expr::CXXConstructExprClass:
1298 case Expr::CXXBindTemporaryExprClass:
1300 case Expr::CXXUuidofExprClass:
1302 case Expr::LambdaExprClass:
1305 case Expr::ExprWithCleanupsClass: {
1306 const auto *cleanups = cast<ExprWithCleanups>(E);
1323 case Expr::CXXDefaultArgExprClass: {
1324 auto *DAE = cast<CXXDefaultArgExpr>(E);
1328 case Expr::CXXDefaultInitExprClass: {
1329 auto *DIE = cast<CXXDefaultInitExpr>(E);
1333 case Expr::CXXTypeidExprClass:
1336 case Expr::ObjCMessageExprClass:
1338 case Expr::ObjCIvarRefExprClass:
1340 case Expr::StmtExprClass:
1342 case Expr::UnaryOperatorClass:
1344 case Expr::ArraySubscriptExprClass:
1346 case Expr::OMPArraySectionExprClass:
1348 case Expr::ExtVectorElementExprClass:
1350 case Expr::MemberExprClass:
1352 case Expr::CompoundLiteralExprClass:
1354 case Expr::ConditionalOperatorClass:
1356 case Expr::BinaryConditionalOperatorClass:
1358 case Expr::ChooseExprClass:
1359 return EmitLValue(cast<ChooseExpr>(E)->getChosenSubExpr());
1360 case Expr::OpaqueValueExprClass:
1362 case Expr::SubstNonTypeTemplateParmExprClass:
1363 return EmitLValue(cast<SubstNonTypeTemplateParmExpr>(E)->getReplacement());
1364 case Expr::ImplicitCastExprClass:
1365 case Expr::CStyleCastExprClass:
1366 case Expr::CXXFunctionalCastExprClass:
1367 case Expr::CXXStaticCastExprClass:
1368 case Expr::CXXDynamicCastExprClass:
1369 case Expr::CXXReinterpretCastExprClass:
1370 case Expr::CXXConstCastExprClass:
1371 case Expr::ObjCBridgedCastExprClass:
1374 case Expr::MaterializeTemporaryExprClass:
1377 case Expr::CoawaitExprClass:
1379 case Expr::CoyieldExprClass:
1392 if (!qs.hasConst() || qs.hasVolatile())
return false;
1396 if (
const auto *RT = dyn_cast<RecordType>(type))
1397 if (
const auto *RD = dyn_cast<CXXRecordDecl>(RT->getDecl()))
1398 if (RD->hasMutableFields() || !RD->isTrivial())
1419 if (
const auto *ref = dyn_cast<ReferenceType>(type)) {
1441 if (isa<ParmVarDecl>(value)) {
1443 }
else if (
auto *var = dyn_cast<VarDecl>(value)) {
1445 }
else if (isa<EnumConstantDecl>(value)) {
1453 bool resultIsReference;
1459 resultIsReference =
false;
1460 resultType = refExpr->
getType();
1465 resultIsReference =
true;
1466 resultType = value->
getType();
1479 result.
Val, resultType);
1483 if (isa<VarDecl>(value)) {
1487 assert(isa<EnumConstantDecl>(value));
1492 if (resultIsReference)
1519 assert(Constant &&
"not a constant");
1539 return ET->getDecl()->getIntegerType()->isBooleanType();
1549 bool StrictEnums,
bool IsBool) {
1551 bool IsRegularCPlusPlusEnum = CGF.
getLangOpts().CPlusPlus && StrictEnums &&
1553 if (!IsBool && !IsRegularCPlusPlusEnum)
1562 unsigned Bitwidth = LTy->getScalarSizeInBits();
1566 if (NumNegativeBits) {
1567 unsigned NumBits =
std::max(NumNegativeBits, NumPositiveBits + 1);
1568 assert(NumBits <= Bitwidth);
1572 assert(NumPositiveBits <= Bitwidth);
1573 End =
llvm::APInt(Bitwidth, 1) << NumPositiveBits;
1580 llvm::MDNode *CodeGenFunction::getRangeForLoadFromType(
QualType Ty) {
1587 return MDHelper.createRange(Min, End);
1592 bool HasBoolCheck =
SanOpts.
has(SanitizerKind::Bool);
1593 bool HasEnumCheck =
SanOpts.
has(SanitizerKind::Enum);
1594 if (!HasBoolCheck && !HasEnumCheck)
1599 bool NeedsBoolCheck = HasBoolCheck && IsBool;
1600 bool NeedsEnumCheck = HasEnumCheck && Ty->
getAs<
EnumType>();
1601 if (!NeedsBoolCheck && !NeedsEnumCheck)
1608 cast<llvm::IntegerType>(Value->getType())->getBitWidth() == 1)
1620 Check =
Builder.CreateICmpULE(Value, llvm::ConstantInt::get(Ctx, End));
1623 Builder.CreateICmpSLE(Value, llvm::ConstantInt::get(Ctx, End));
1625 Builder.CreateICmpSGE(Value, llvm::ConstantInt::get(Ctx, Min));
1626 Check =
Builder.CreateAnd(Upper, Lower);
1631 NeedsEnumCheck ? SanitizerKind::Enum : SanitizerKind::Bool;
1632 EmitCheck(std::make_pair(Check, Kind), SanitizerHandler::LoadInvalidValue,
1642 bool isNontemporal) {
1648 const auto *VTy = cast<llvm::VectorType>(EltTy);
1651 if (VTy->getNumElements() == 3) {
1654 llvm::VectorType *vec4Ty =
1655 llvm::VectorType::get(VTy->getElementType(), 4);
1661 V =
Builder.CreateShuffleVector(V, llvm::UndefValue::get(vec4Ty),
1662 {0, 1, 2},
"extractVec");
1676 if (isNontemporal) {
1677 llvm::MDNode *
Node = llvm::MDNode::get(
1678 Load->getContext(), llvm::ConstantAsMetadata::get(
Builder.getInt32(1)));
1688 if (llvm::MDNode *RangeInfo = getRangeForLoadFromType(Ty))
1689 Load->setMetadata(llvm::LLVMContext::MD_range, RangeInfo);
1699 if (Value->getType()->isIntegerTy(1))
1702 "wrong value rep of bool");
1712 "wrong value rep of bool");
1713 return Builder.CreateTrunc(Value,
Builder.getInt1Ty(),
"tobool");
1723 bool isInit,
bool isNontemporal) {
1728 auto *VecTy = dyn_cast<llvm::VectorType>(SrcTy);
1730 if (VecTy && VecTy->getNumElements() == 3) {
1732 llvm::Constant *Mask[] = {
Builder.getInt32(0),
Builder.getInt32(1),
1734 llvm::UndefValue::get(
Builder.getInt32Ty())};
1735 llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
1736 Value =
Builder.CreateShuffleVector(Value, llvm::UndefValue::get(VecTy),
1737 MaskV,
"extractVec");
1738 SrcTy = llvm::VectorType::get(VecTy->getElementType(), 4);
1757 if (isNontemporal) {
1758 llvm::MDNode *
Node =
1759 llvm::MDNode::get(Store->getContext(),
1760 llvm::ConstantAsMetadata::get(
Builder.getInt32(1)));
1819 assert(LV.
isBitField() &&
"Unknown LValue type!");
1837 Val =
Builder.CreateShl(Val, HighBits,
"bf.shl");
1838 if (Info.
Offset + HighBits)
1839 Val =
Builder.CreateAShr(Val, Info.
Offset + HighBits,
"bf.ashr");
1874 for (
unsigned i = 0; i != NumResultElts; ++i)
1877 llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
1878 Vec =
Builder.CreateShuffleVector(Vec, llvm::UndefValue::get(Vec->getType()),
1889 Address CastToPointerElement =
1891 "conv.ptr.element");
1900 return VectorBasePtrPlusIx;
1906 "Bad type for register variable");
1907 llvm::MDNode *RegName = cast<llvm::MDNode>(
1908 cast<llvm::MetadataAsValue>(LV.
getGlobalReg())->getMetadata());
1913 if (OrigTy->isPointerTy())
1917 llvm::Function *F =
CGM.
getIntrinsic(llvm::Intrinsic::read_register, Types);
1919 F, llvm::MetadataAsValue::get(Ty->getContext(), RegName));
1920 if (OrigTy->isPointerTy())
1921 Call =
Builder.CreateIntToPtr(Call, OrigTy);
1951 assert(Dst.
isBitField() &&
"Unknown LValue type");
1959 llvm_unreachable(
"present but none");
2007 RHS =
Builder.CreatePtrToInt(RHS, ResultType,
"sub.ptr.rhs.cast");
2010 "sub.ptr.lhs.cast");
2023 assert(Src.
isScalar() &&
"Can't emit an agg store with this method");
2037 SrcVal =
Builder.CreateIntCast(SrcVal, Ptr.getElementType(),
2050 SrcVal =
Builder.CreateAnd(SrcVal,
2066 SrcVal =
Builder.CreateOr(Val, SrcVal,
"bf.set");
2068 assert(Info.
Offset == 0);
2083 ResultVal =
Builder.CreateShl(ResultVal, HighBits,
"bf.result.shl");
2084 ResultVal =
Builder.CreateAShr(ResultVal, HighBits,
"bf.result.ashr");
2105 unsigned NumSrcElts = VTy->getNumElements();
2106 unsigned NumDstElts = Vec->getType()->getVectorNumElements();
2107 if (NumDstElts == NumSrcElts) {
2112 for (
unsigned i = 0; i != NumSrcElts; ++i)
2115 llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
2116 Vec =
Builder.CreateShuffleVector(SrcVal,
2117 llvm::UndefValue::get(Vec->getType()),
2119 }
else if (NumDstElts > NumSrcElts) {
2125 for (
unsigned i = 0; i != NumSrcElts; ++i)
2126 ExtMask.push_back(
Builder.getInt32(i));
2127 ExtMask.resize(NumDstElts, llvm::UndefValue::get(
Int32Ty));
2128 llvm::Value *ExtMaskV = llvm::ConstantVector::get(ExtMask);
2130 Builder.CreateShuffleVector(SrcVal,
2131 llvm::UndefValue::get(SrcVal->getType()),
2135 for (
unsigned i = 0; i != NumDstElts; ++i)
2136 Mask.push_back(
Builder.getInt32(i));
2145 for (
unsigned i = 0; i != NumSrcElts; ++i)
2147 llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
2148 Vec =
Builder.CreateShuffleVector(Vec, ExtSrcVal, MaskV);
2151 llvm_unreachable(
"unexpected shorten vector length");
2157 Vec =
Builder.CreateInsertElement(Vec, SrcVal, Elt);
2167 "Bad type for register variable");
2168 llvm::MDNode *RegName = cast<llvm::MDNode>(
2169 cast<llvm::MetadataAsValue>(Dst.
getGlobalReg())->getMetadata());
2170 assert(RegName &&
"Register LValue is not metadata");
2175 if (OrigTy->isPointerTy())
2179 llvm::Function *F =
CGM.
getIntrinsic(llvm::Intrinsic::write_register, Types);
2181 if (OrigTy->isPointerTy())
2182 Value =
Builder.CreatePtrToInt(Value, Ty);
2184 F, {llvm::MetadataAsValue::get(Ty->getContext(), RegName), Value});
2192 bool IsMemberAccess=
false) {
2196 if (isa<ObjCIvarRefExpr>(E)) {
2209 auto *Exp = cast<ObjCIvarRefExpr>(
const_cast<Expr *
>(E));
2215 if (
const auto *Exp = dyn_cast<DeclRefExpr>(E)) {
2216 if (
const auto *VD = dyn_cast<VarDecl>(Exp->getDecl())) {
2217 if (VD->hasGlobalStorage()) {
2226 if (
const auto *Exp = dyn_cast<UnaryOperator>(E)) {
2231 if (
const auto *Exp = dyn_cast<ParenExpr>(E)) {
2245 if (
const auto *Exp = dyn_cast<GenericSelectionExpr>(E)) {
2250 if (
const auto *Exp = dyn_cast<ImplicitCastExpr>(E)) {
2255 if (
const auto *Exp = dyn_cast<CStyleCastExpr>(E)) {
2260 if (
const auto *Exp = dyn_cast<ObjCBridgedCastExpr>(E)) {
2265 if (
const auto *Exp = dyn_cast<ArraySubscriptExpr>(E)) {
2278 if (
const auto *Exp = dyn_cast<MemberExpr>(E)) {
2290 StringRef Name = StringRef()) {
2291 unsigned AS = cast<llvm::PointerType>(V->getType())->getAddressSpace();
2306 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD);
2310 if (!Res || (*Res == OMPDeclareTargetDeclAttr::MT_To &&
2313 assert(((*Res == OMPDeclareTargetDeclAttr::MT_Link) ||
2314 (*Res == OMPDeclareTargetDeclAttr::MT_To &&
2316 "Expected link clause OR to clause with unified memory enabled.");
2326 llvm::LoadInst *
Load =
2331 PointeeBaseInfo, PointeeTBAAInfo,
2342 PointeeBaseInfo, PointeeTBAAInfo);
2387 VD->
hasAttr<OMPThreadPrivateDeclAttr>()) {
2401 if (FD->
hasAttr<WeakRefAttr>()) {
2416 V = llvm::ConstantExpr::getBitCast(V,
2446 AsmLabelAttr *
Asm = VD->
getAttr<AsmLabelAttr>();
2447 assert(Asm->getLabel().size() < 64-Name.size() &&
2448 "Register name too big");
2449 Name.append(Asm->getLabel());
2450 llvm::NamedMDNode *M =
2451 CGM.
getModule().getOrInsertNamedMetadata(Name);
2452 if (M->getNumOperands() == 0) {
2455 llvm::Metadata *Ops[] = {Str};
2462 llvm::MetadataAsValue::get(CGM.
getLLVMContext(), M->getOperand(0));
2507 case llvm::GlobalValue::LinkOnceODRLinkage:
2508 case llvm::GlobalValue::WeakODRLinkage:
2510 case llvm::GlobalValue::PrivateLinkage:
2522 "should not emit an unevaluated operand");
2524 if (
const auto *VD = dyn_cast<VarDecl>(ND)) {
2527 VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())
2535 (VD->getType()->isReferenceType() ||
2537 VD->getAnyInitializer(VD);
2539 E->
getLocation(), *VD->evaluateValue(), VD->getType());
2540 assert(Val &&
"failed to emit constant expression");
2543 if (!VD->getType()->isReferenceType()) {
2548 auto *PTy = llvm::PointerType::get(
2549 VarTy,
getContext().getTargetAddressSpace(VD->getType()));
2559 Addr =
Address(Val, Alignment);
2568 VD = VD->getCanonicalDecl();
2572 auto I = LocalDeclMap.find(VD);
2573 if (I != LocalDeclMap.end()) {
2575 if (VD->getType()->isReferenceType())
2593 CapLVal.getTBAAInfo());
2613 "Should not use decl without marking it used!");
2615 if (ND->
hasAttr<WeakRefAttr>()) {
2616 const auto *VD = cast<ValueDecl>(ND);
2621 if (
const auto *VD = dyn_cast<VarDecl>(ND)) {
2623 if (VD->hasLinkage() || VD->isStaticDataMember())
2629 auto iter = LocalDeclMap.find(VD);
2630 if (iter != LocalDeclMap.end()) {
2631 addr = iter->second;
2635 }
else if (VD->isStaticLocal()) {
2642 llvm_unreachable(
"DeclRefExpr for Decl not entered in LocalDeclMap?");
2648 VD->hasAttr<OMPThreadPrivateDeclAttr>()) {
2655 bool isBlockByref = VD->isEscapingByref();
2665 bool isLocalStorage = VD->hasLocalStorage();
2667 bool NonGCable = isLocalStorage &&
2668 !VD->getType()->isReferenceType() &&
2675 bool isImpreciseLifetime =
2676 (isLocalStorage && !VD->hasAttr<ObjCPreciseLifetimeAttr>());
2677 if (isImpreciseLifetime)
2683 if (
const auto *FD = dyn_cast<FunctionDecl>(ND))
2689 if (
const auto *BD = dyn_cast<BindingDecl>(ND))
2692 llvm_unreachable(
"Unhandled DeclRefExpr");
2702 default: llvm_unreachable(
"Unknown unary operator lvalue!");
2705 assert(!T.
isNull() &&
"CodeGenFunction::EmitUnaryOpLValue: Illegal type");
2727 assert(LV.
isSimple() &&
"real/imag on non-ordinary l-value");
2751 bool isInc = E->
getOpcode() == UO_PreInc;
2774 assert(SL !=
nullptr &&
"No StringLiteral name in PredefinedExpr");
2775 StringRef FnName =
CurFn->getName();
2776 if (FnName.startswith(
"\01"))
2777 FnName = FnName.substr(1);
2778 StringRef NameItems[] = {
2780 std::string GVName = llvm::join(NameItems, NameItems + 2,
".");
2781 if (
auto *BD = dyn_cast_or_null<BlockDecl>(
CurCodeDecl)) {
2782 std::string Name = SL->getString();
2783 if (!Name.empty()) {
2784 unsigned Discriminator =
2787 Name +=
"_" + Twine(Discriminator + 1).str();
2813 uint16_t TypeKind = -1;
2830 StringRef(), StringRef(), None, Buffer,
2833 llvm::Constant *Components[] = {
2837 llvm::Constant *Descriptor = llvm::ConstantStruct::getAnon(Components);
2839 auto *GV =
new llvm::GlobalVariable(
2841 true, llvm::GlobalVariable::PrivateLinkage, Descriptor);
2842 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
2854 if (V->getType() == TargetTy)
2859 if (V->getType()->isFloatingPointTy()) {
2860 unsigned Bits = V->getType()->getPrimitiveSizeInBits();
2861 if (Bits <= TargetTy->getIntegerBitWidth())
2867 if (V->getType()->isIntegerTy() &&
2868 V->getType()->getIntegerBitWidth() <= TargetTy->getIntegerBitWidth())
2869 return Builder.CreateZExt(V, TargetTy);
2872 if (!V->getType()->isPointerTy()) {
2877 return Builder.CreatePtrToInt(V, TargetTy);
2897 int PathComponentsToStrip =
2899 if (PathComponentsToStrip < 0) {
2900 assert(PathComponentsToStrip !=
INT_MIN);
2901 int PathComponentsToKeep = -PathComponentsToStrip;
2902 auto I = llvm::sys::path::rbegin(FilenameString);
2903 auto E = llvm::sys::path::rend(FilenameString);
2904 while (I != E && --PathComponentsToKeep)
2907 FilenameString = FilenameString.substr(I - E);
2908 }
else if (PathComponentsToStrip > 0) {
2909 auto I = llvm::sys::path::begin(FilenameString);
2910 auto E = llvm::sys::path::end(FilenameString);
2911 while (I != E && PathComponentsToStrip--)
2916 FilenameString.substr(I - llvm::sys::path::begin(FilenameString));
2918 FilenameString = llvm::sys::path::filename(FilenameString);
2923 cast<llvm::GlobalVariable>(FilenameGV.getPointer()));
2924 Filename = FilenameGV.getPointer();
2928 Filename = llvm::Constant::getNullValue(
Int8PtrTy);
2935 return llvm::ConstantStruct::getAnon(Data);
2955 else if (Kind == SanitizerKind::Return || Kind == SanitizerKind::Unreachable)
2958 return CheckRecoverableKind::Recoverable;
2962 struct SanitizerHandlerInfo {
2963 char const *
const Name;
2969 #define SANITIZER_CHECK(Enum, Name, Version) {#Name, Version}, 2971 #undef SANITIZER_CHECK 2975 llvm::FunctionType *FnType,
2979 llvm::BasicBlock *ContBB) {
2982 if (!CGF.
Builder.getCurrentDebugLocation()) {
2986 bool NeedsAbortSuffix =
2989 const SanitizerHandlerInfo &CheckInfo = SanitizerHandlers[CheckHandler];
2990 const StringRef CheckName = CheckInfo.Name;
2991 std::string FnName =
"__ubsan_handle_" + CheckName.str();
2992 if (CheckInfo.Version && !MinimalRuntime)
2993 FnName +=
"_v" + llvm::utostr(CheckInfo.Version);
2995 FnName +=
"_minimal";
2996 if (NeedsAbortSuffix)
3001 llvm::AttrBuilder B;
3003 B.addAttribute(llvm::Attribute::NoReturn)
3004 .addAttribute(llvm::Attribute::NoUnwind);
3006 B.addAttribute(llvm::Attribute::UWTable);
3011 llvm::AttributeList::FunctionIndex, B),
3015 HandlerCall->setDoesNotReturn();
3016 CGF.
Builder.CreateUnreachable();
3023 ArrayRef<std::pair<llvm::Value *, SanitizerMask>> Checked,
3027 assert(Checked.size() > 0);
3028 assert(CheckHandler >= 0 &&
3029 size_t(CheckHandler) < llvm::array_lengthof(SanitizerHandlers));
3030 const StringRef CheckName = SanitizerHandlers[CheckHandler].Name;
3035 for (
int i = 0, n = Checked.size(); i < n; ++i) {
3044 Cond = Cond ?
Builder.CreateAnd(Cond, Check) : Check;
3049 if (!FatalCond && !RecoverableCond)
3053 if (FatalCond && RecoverableCond)
3054 JointCond =
Builder.CreateAnd(FatalCond, RecoverableCond);
3056 JointCond = FatalCond ? FatalCond : RecoverableCond;
3062 for (
int i = 1, n = Checked.size(); i < n; ++i) {
3064 "All recoverable kinds in a single check must be same!");
3071 llvm::Instruction *Branch =
Builder.CreateCondBr(JointCond, Cont, Handlers);
3075 llvm::MDNode *
Node = MDHelper.createBranchWeights((1U << 20) - 1, 1);
3076 Branch->setMetadata(llvm::LLVMContext::MD_prof, Node);
3085 Args.reserve(DynamicArgs.size() + 1);
3086 ArgTypes.reserve(DynamicArgs.size() + 1);
3089 if (!StaticArgs.empty()) {
3090 llvm::Constant *Info = llvm::ConstantStruct::getAnon(StaticArgs);
3092 new llvm::GlobalVariable(
CGM.
getModule(), Info->getType(),
false,
3093 llvm::GlobalVariable::PrivateLinkage, Info);
3094 InfoPtr->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
3100 for (
size_t i = 0, n = DynamicArgs.size(); i != n; ++i) {
3106 llvm::FunctionType *FnType =
3107 llvm::FunctionType::get(
CGM.
VoidTy, ArgTypes,
false);
3109 if (!FatalCond || !RecoverableCond) {
3113 (FatalCond !=
nullptr), Cont);
3117 llvm::BasicBlock *NonFatalHandlerBB =
3120 Builder.CreateCondBr(FatalCond, NonFatalHandlerBB, FatalHandlerBB);
3138 llvm::BranchInst *BI =
Builder.CreateCondBr(Cond, Cont, CheckBB);
3141 llvm::MDNode *
Node = MDHelper.createBranchWeights((1U << 20) - 1, 1);
3142 BI->setMetadata(llvm::LLVMContext::MD_prof, Node);
3148 llvm::CallInst *CheckCall;
3149 llvm::FunctionCallee SlowPathFn;
3151 llvm::Constant *Info = llvm::ConstantStruct::getAnon(StaticArgs);
3153 new llvm::GlobalVariable(
CGM.
getModule(), Info->getType(),
false,
3154 llvm::GlobalVariable::PrivateLinkage, Info);
3155 InfoPtr->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
3159 "__cfi_slowpath_diag",
3162 CheckCall =
Builder.CreateCall(
3168 CheckCall =
Builder.CreateCall(SlowPathFn, {TypeId, Ptr});
3172 cast<llvm::GlobalValue>(SlowPathFn.getCallee()->stripPointerCasts()));
3173 CheckCall->setDoesNotThrow();
3182 auto &Ctx = M->getContext();
3185 llvm::GlobalValue::WeakAnyLinkage,
"__cfi_check", M);
3193 llvm::Intrinsic::getDeclaration(M, llvm::Intrinsic::trap),
"", BB);
3211 Args.push_back(&ArgData);
3212 Args.push_back(&ArgAddr);
3219 llvm::GlobalValue::WeakODRLinkage,
"__cfi_check_fail", &
CGM.
getModule());
3245 llvm::StructType *SourceLocationTy =
3247 llvm::StructType *CfiCheckFailDataTy =
3248 llvm::StructType::get(
Int8Ty, SourceLocationTy, VoidPtrTy);
3252 Builder.CreatePointerCast(Data, CfiCheckFailDataTy->getPointerTo(0)), 0,
3257 llvm::Value *AllVtables = llvm::MetadataAsValue::get(
3262 {Addr, AllVtables}),
3265 const std::pair<int, SanitizerMask> CheckKinds[] = {
3273 for (
auto CheckKindMaskPair : CheckKinds) {
3274 int Kind = CheckKindMaskPair.first;
3277 Builder.CreateICmpNE(CheckKind, llvm::ConstantInt::get(
Int8Ty, Kind));
3279 EmitCheck(std::make_pair(Cond, Mask), SanitizerHandler::CFICheckFail, {},
3280 {Data, Addr, ValidVtable});
3292 if (
SanOpts.
has(SanitizerKind::Unreachable)) {
3295 SanitizerKind::Unreachable),
3296 SanitizerHandler::BuiltinUnreachable,
3309 Builder.CreateCondBr(Checked, Cont, TrapBB);
3311 llvm::CallInst *TrapCall =
EmitTrapCall(llvm::Intrinsic::trap);
3312 TrapCall->setDoesNotReturn();
3313 TrapCall->setDoesNotThrow();
3316 Builder.CreateCondBr(Checked, Cont, TrapBB);
3326 auto A = llvm::Attribute::get(
getLLVMContext(),
"trap-func-name",
3328 TrapCall->addAttribute(llvm::AttributeList::FunctionIndex, A);
3338 "Array to pointer decay must have array source type!");
3342 Address Addr = LV.getAddress(*
this);
3352 assert(isa<llvm::ArrayType>(Addr.getElementType()) &&
3353 "Expected pointer to array");
3363 if (BaseInfo) *BaseInfo = LV.getBaseInfo();
3373 const auto *CE = dyn_cast<
CastExpr>(E);
3374 if (!CE || CE->getCastKind() != CK_ArrayToPointerDecay)
3378 const Expr *SubExpr = CE->getSubExpr();
3391 const llvm::Twine &
name =
"arrayidx") {
3406 if (
auto constantIdx = dyn_cast<llvm::ConstantInt>(idx)) {
3407 CharUnits offset = constantIdx->getZExtValue() * eltSize;
3439 if (
const auto *ME = dyn_cast<MemberExpr>(E))
3440 return ME->getMemberDecl()->hasAttr<BPFPreserveAccessIndexAttr>();
3442 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E)) {
3443 const auto *VarDef = dyn_cast<
VarDecl>(DRE->getDecl());
3453 if (
const auto *RecT = dyn_cast<RecordType>(PointeeT))
3454 return RecT->getDecl()->
hasAttr<BPFPreserveAccessIndexAttr>();
3467 const llvm::Twine &
name =
"arrayidx") {
3470 for (
auto idx : indices.drop_back())
3471 assert(isa<llvm::ConstantInt>(idx) &&
3472 cast<llvm::ConstantInt>(idx)->isZero());
3487 auto LastIndex = dyn_cast<llvm::ConstantInt>(indices.back());
3491 CGF, addr.
getPointer(), indices, inbounds, signedIndices,
3495 unsigned idx = LastIndex->getZExtValue();
3496 llvm::DIType *DbgInfo =
nullptr;
3505 return Address(eltPtr, eltAlign);
3514 bool SignedIndices =
false;
3515 auto EmitIdxAfterBase = [&, IdxPre](
bool Promote) ->
llvm::Value * {
3518 assert(E->
getRHS() == E->
getIdx() &&
"index was neither LHS nor RHS");
3524 SignedIndices |= IdxSigned;
3530 if (Promote && Idx->getType() !=
IntPtrTy)
3540 !isa<ExtVectorElementExpr>(E->
getBase())) {
3543 auto *Idx = EmitIdxAfterBase(
false);
3544 assert(LHS.
isSimple() &&
"Can only subscript lvalue vectors here!");
3553 if (isa<ExtVectorElementExpr>(E->
getBase())) {
3555 auto *Idx = EmitIdxAfterBase(
true);
3574 auto *Idx = EmitIdxAfterBase(
true);
3584 Idx =
Builder.CreateMul(Idx, numElements);
3586 Idx =
Builder.CreateNSWMul(Idx, numElements);
3598 auto *Idx = EmitIdxAfterBase(
true);
3602 llvm::ConstantInt::get(Idx->getType(), InterfaceSize.
getQuantity());
3619 Addr =
Address(EltPtr, EltAlign);
3628 assert(Array->getType()->isArrayType() &&
3629 "Array to pointer decay must have array source type!");
3633 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(Array))
3637 auto *Idx = EmitIdxAfterBase(
true);
3645 EltBaseInfo = ArrayLV.getBaseInfo();
3650 auto *Idx = EmitIdxAfterBase(
true);
3672 bool IsLowerBound) {
3689 "Expected pointer to array");
3708 bool IsLowerBound) {
3712 ResultExprTy = AT->getElementType();
3723 LowerBound->getType()->hasSignedIntegerRepresentation());
3725 Idx = llvm::ConstantInt::getNullValue(
IntPtrTy);
3735 if (Length->isIntegerConstantExpr(ConstLength, C)) {
3741 if (LowerBound && LowerBound->isIntegerConstantExpr(ConstLowerBound, C)) {
3743 LowerBound =
nullptr;
3747 else if (!LowerBound)
3750 if (Length || LowerBound) {
3751 auto *LowerBoundVal =
3755 LowerBound->getType()->hasSignedIntegerRepresentation())
3756 : llvm::ConstantInt::get(
IntPtrTy, ConstLowerBound);
3761 Length->getType()->hasSignedIntegerRepresentation())
3762 : llvm::ConstantInt::get(
IntPtrTy, ConstLength);
3763 Idx =
Builder.CreateAdd(LowerBoundVal, LengthVal,
"lb_add_len",
3766 if (Length && LowerBound) {
3768 Idx, llvm::ConstantInt::get(
IntPtrTy, 1),
"idx_sub_1",
3772 Idx = llvm::ConstantInt::get(
IntPtrTy, ConstLength + ConstLowerBound);
3778 if (
auto *VAT = C.getAsVariableArrayType(ArrayTy)) {
3779 Length = VAT->getSizeExpr();
3780 if (Length->isIntegerConstantExpr(ConstLength, C))
3783 auto *CAT = C.getAsConstantArrayType(ArrayTy);
3784 ConstLength = CAT->getSize();
3787 auto *LengthVal =
Builder.CreateIntCast(
3789 Length->getType()->hasSignedIntegerRepresentation());
3791 LengthVal, llvm::ConstantInt::get(
IntPtrTy, 1),
"len_sub_1",
3796 Idx = llvm::ConstantInt::get(
IntPtrTy, ConstLength);
3805 if (
auto *VLA =
getContext().getAsVariableArrayType(ResultExprTy)) {
3811 BaseTy, VLA->getElementType(), IsLowerBound);
3820 Idx =
Builder.CreateMul(Idx, NumElements);
3822 Idx =
Builder.CreateNSWMul(Idx, NumElements);
3831 assert(Array->getType()->isArrayType() &&
3832 "Array to pointer decay must have array source type!");
3836 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(Array))
3846 BaseInfo = ArrayLV.getBaseInfo();
3850 TBAAInfo, BaseTy, ResultExprTy,
3873 Base =
MakeAddrLValue(Ptr, PT->getPointeeType(), BaseInfo, TBAAInfo);
3874 Base.getQuals().removeObjCGCAttr();
3883 "Result must be a vector");
3901 llvm::Constant *CV =
3906 assert(Base.
isExtVectorElt() &&
"Can only subscript lvalue vec elts here!");
3911 for (
unsigned i = 0, e = Indices.size(); i != e; ++i)
3912 CElts.push_back(BaseElts->getAggregateElement(Indices[i]));
3913 llvm::Constant *CV = llvm::ConstantVector::get(CElts);
3935 SkippedChecks.
set(SanitizerKind::Alignment,
true);
3936 if (IsBaseCXXThis || isa<DeclRefExpr>(BaseExpr))
3945 if (
auto *Field = dyn_cast<FieldDecl>(ND)) {
3960 if (
const auto *FD = dyn_cast<FunctionDecl>(ND))
3963 llvm_unreachable(
"Unhandled member declaration!");
3969 assert(cast<CXXMethodDecl>(
CurCodeDecl)->getParent()->isLambda());
3980 unsigned FieldIndex) {
3981 unsigned I = 0, Skipped = 0;
3984 if (I == FieldIndex)
3986 if (F->isUnnamedBitfield())
3991 return FieldIndex - Skipped;
4041 if (RD->isDynamicClass())
4044 for (
const auto &
Base : RD->bases())
4048 for (
const FieldDecl *Field : RD->fields())
4113 assert(!FieldTBAAInfo.
Offset &&
4114 "Nonzero offset for an access with no base type!");
4127 FieldTBAAInfo.
Size =
4132 if (
auto *ClassDef = dyn_cast<CXXRecordDecl>(rec)) {
4134 ClassDef->isDynamicClass()) {
4160 Builder.CreatePreserveUnionAccessIndex(
4198 if (field->
hasAttr<AnnotateAttr>())
4260 assert(E->
isTransparent() &&
"non-transparent glvalue init list");
4268 const Expr *Operand) {
4269 if (
auto *ThrowExpr = dyn_cast<CXXThrowExpr>(Operand->
IgnoreParens())) {
4282 "Unexpected conditional operator!");
4292 if (!CondExprBool) std::swap(live, dead);
4317 if (lhs && !lhs->isSimple())
4320 lhsBlock =
Builder.GetInsertBlock();
4330 if (rhs && !rhs->isSimple())
4332 rhsBlock =
Builder.GetInsertBlock();
4337 llvm::PHINode *phi =
4338 Builder.CreatePHI(lhs->getPointer(*this)->getType(), 2,
"cond-lvalue");
4339 phi->addIncoming(lhs->getPointer(*
this), lhsBlock);
4340 phi->addIncoming(rhs->getPointer(*
this), rhsBlock);
4341 Address result(phi,
std::min(lhs->getAlignment(), rhs->getAlignment()));
4343 std::max(lhs->getBaseInfo().getAlignmentSource(),
4344 rhs->getBaseInfo().getAlignmentSource());
4346 lhs->getTBAAInfo(), rhs->getTBAAInfo());
4350 assert((lhs || rhs) &&
4351 "both operands of glvalue conditional are throw-expressions?");
4352 return lhs ? *lhs : *rhs;
4367 case CK_LValueToRValueBitCast:
4368 case CK_ArrayToPointerDecay:
4369 case CK_FunctionToPointerDecay:
4370 case CK_NullToMemberPointer:
4371 case CK_NullToPointer:
4372 case CK_IntegralToPointer:
4373 case CK_PointerToIntegral:
4374 case CK_PointerToBoolean:
4375 case CK_VectorSplat:
4376 case CK_IntegralCast:
4377 case CK_BooleanToSignedIntegral:
4378 case CK_IntegralToBoolean:
4379 case CK_IntegralToFloating:
4380 case CK_FloatingToIntegral:
4381 case CK_FloatingToBoolean:
4382 case CK_FloatingCast:
4383 case CK_FloatingRealToComplex:
4384 case CK_FloatingComplexToReal:
4385 case CK_FloatingComplexToBoolean:
4386 case CK_FloatingComplexCast:
4387 case CK_FloatingComplexToIntegralComplex:
4388 case CK_IntegralRealToComplex:
4389 case CK_IntegralComplexToReal:
4390 case CK_IntegralComplexToBoolean:
4391 case CK_IntegralComplexCast:
4392 case CK_IntegralComplexToFloatingComplex:
4393 case CK_DerivedToBaseMemberPointer:
4394 case CK_BaseToDerivedMemberPointer:
4395 case CK_MemberPointerToBoolean:
4396 case CK_ReinterpretMemberPointer:
4397 case CK_AnyPointerToBlockPointerCast:
4398 case CK_ARCProduceObject:
4399 case CK_ARCConsumeObject:
4400 case CK_ARCReclaimReturnedObject:
4401 case CK_ARCExtendBlockObject:
4402 case CK_CopyAndAutoreleaseBlockObject:
4403 case CK_IntToOCLSampler:
4404 case CK_FixedPointCast:
4405 case CK_FixedPointToBoolean:
4406 case CK_FixedPointToIntegral:
4407 case CK_IntegralToFixedPoint:
4411 llvm_unreachable(
"dependent cast kind in IR gen!");
4413 case CK_BuiltinFnToFnPtr:
4414 llvm_unreachable(
"builtin functions are handled elsewhere");
4417 case CK_NonAtomicToAtomic:
4418 case CK_AtomicToNonAtomic:
4424 const auto *DCE = cast<CXXDynamicCastExpr>(E);
4428 case CK_ConstructorConversion:
4429 case CK_UserDefinedConversion:
4430 case CK_CPointerToObjCPointerCast:
4431 case CK_BlockPointerToObjCPointerCast:
4433 case CK_LValueToRValue:
4436 case CK_UncheckedDerivedToBase:
4437 case CK_DerivedToBase: {
4438 const auto *DerivedClassTy =
4440 auto *DerivedClassDecl = cast<CXXRecordDecl>(DerivedClassTy->getDecl());
4458 case CK_BaseToDerived: {
4460 auto *DerivedClassDecl = cast<CXXRecordDecl>(DerivedClassTy->getDecl());
4473 Derived.getPointer(), E->
getType());
4475 if (
SanOpts.
has(SanitizerKind::CFIDerivedCast))
4483 case CK_LValueBitCast: {
4485 const auto *CE = cast<ExplicitCastExpr>(E);
4492 if (
SanOpts.
has(SanitizerKind::CFIUnrelatedCast))
4500 case CK_AddressSpaceConversion: {
4510 case CK_ObjCObjectLValueCast: {
4517 case CK_ZeroToOCLOpaqueType:
4518 llvm_unreachable(
"NULL to OpenCL opaque type lvalue cast is not valid");
4521 llvm_unreachable(
"Unhandled lvalue cast kind?");
4533 llvm::DenseMap<const OpaqueValueExpr*,LValue>::iterator
4534 it = OpaqueLValues.find(e);
4536 if (it != OpaqueLValues.end())
4539 assert(e->
isUnique() &&
"LValue for a nonunique OVE hasn't been emitted");
4547 llvm::DenseMap<const OpaqueValueExpr*,RValue>::iterator
4548 it = OpaqueRValues.find(e);
4550 if (it != OpaqueRValues.end())
4553 assert(e->
isUnique() &&
"RValue for a nonunique OVE hasn't been emitted");
4578 llvm_unreachable(
"bad evaluation kind");
4591 if (
const auto *CE = dyn_cast<CXXMemberCallExpr>(E))
4594 if (
const auto *CE = dyn_cast<CUDAKernelCallExpr>(E))
4597 if (
const auto *CE = dyn_cast<CXXOperatorCallExpr>(E))
4599 dyn_cast_or_null<CXXMethodDecl>(CE->getCalleeDecl()))
4643 if (
auto ICE = dyn_cast<ImplicitCastExpr>(E)) {
4644 if (ICE->getCastKind() == CK_FunctionToPointerDecay ||
4645 ICE->getCastKind() == CK_BuiltinFnToFnPtr) {
4650 }
else if (
auto DRE = dyn_cast<DeclRefExpr>(E)) {
4651 if (
auto FD = dyn_cast<FunctionDecl>(DRE->getDecl())) {
4654 }
else if (
auto ME = dyn_cast<MemberExpr>(E)) {
4655 if (
auto FD = dyn_cast<FunctionDecl>(ME->getMemberDecl())) {
4661 }
else if (
auto NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) {
4665 }
else if (
auto PDE = dyn_cast<CXXPseudoDestructorExpr>(E)) {
4682 if (
const auto *VD =
4687 CGCallee callee(calleeInfo, calleePtr);
4703 assert(E->
getOpcode() == BO_Assign &&
"unexpected binary l-value");
4741 llvm_unreachable(
"bad evaluation kind");
4752 "Can't have a scalar return unless the return type is a " 4765 &&
"binding l-value to type which needs a temporary");
4803 "Can't have a scalar return unless the return type is a " 4823 unsigned CVRQualifiers) {
4825 Ivar, CVRQualifiers);
4841 ObjectTy = BaseExpr->
getType();
4865 "Call must have function pointer type!");
4867 const Decl *TargetDecl =
4872 auto PointeeType = cast<PointerType>(CalleeType)->getPointeeType();
4877 (!TargetDecl || !isa<FunctionDecl>(TargetDecl))) {
4878 if (llvm::Constant *PrefixSig =
4885 llvm::Constant *FTRTTIConst =
4888 llvm::StructType *PrefixStructTy = llvm::StructType::get(
4894 CalleePtr, llvm::PointerType::getUnqual(PrefixStructTy));
4896 Builder.CreateConstGEP2_32(PrefixStructTy, CalleePrefixStruct, 0, 0);
4903 Builder.CreateCondBr(CalleeSigMatch, TypeCheck, Cont);
4907 Builder.CreateConstGEP2_32(PrefixStructTy, CalleePrefixStruct, 0, 1);
4913 Builder.CreateICmpEQ(CalleeRTTI, FTRTTIConst);
4917 SanitizerHandler::FunctionTypeMismatch, StaticData,
4918 {CalleePtr, CalleeRTTI, FTRTTIConst});
4925 const auto *FnType = cast<FunctionType>(PointeeType);
4930 (!TargetDecl || !isa<FunctionDecl>(TargetDecl))) {
4945 CGM.
getIntrinsic(llvm::Intrinsic::type_test), {CastedCallee, TypeId});
4948 llvm::Constant *StaticData[] = {
4955 CastedCallee, StaticData);
4957 EmitCheck(std::make_pair(TypeTest, SanitizerKind::CFIICall),
4958 SanitizerHandler::CFICheckFail, StaticData,
4959 {CastedCallee, llvm::UndefValue::get(
IntPtrTy)});
4975 if (
auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
4976 if (OCE->isAssignmentOp())
4979 switch (OCE->getOperator()) {
4981 case OO_GreaterGreater:
4998 Args, FnType, Chain);
5020 if (isa<FunctionNoProtoType>(FnType) || Chain) {
5022 CalleeTy = CalleeTy->getPointerTo();
5029 llvm::CallBase *CallOrInvoke =
nullptr;
5030 RValue Call =
EmitCall(FnInfo, Callee, ReturnValue, Args, &CallOrInvoke,
5036 if (
auto *CalleeDecl = dyn_cast_or_null<FunctionDecl>(TargetDecl))
5037 DI->EmitFuncDeclForCallSite(CallOrInvoke,
QualType(FnType, 0),
5062 return MakeAddrLValue(MemberAddr, MPT->getPointeeType(), BaseInfo, TBAAInfo);
5079 llvm_unreachable(
"bad evaluation kind");
5083 assert(Val->getType()->isFPOrFPVectorTy());
5084 if (Accuracy == 0.0 || !isa<llvm::Instruction>(Val))
5088 llvm::MDNode *
Node = MDHelper.createFPMath(Accuracy);
5090 cast<llvm::Instruction>(Val)->setMetadata(llvm::LLVMContext::MD_fpmath, Node);
5094 struct LValueOrRValue {
5108 LValueOrRValue result;
5112 const Expr *semantic = *i;
5116 if (
const auto *ov = dyn_cast<OpaqueValueExpr>(semantic)) {
5118 if (ov->isUnique()) {
5119 assert(ov != resultExpr &&
5120 "A unique OVE cannot be used as the result expression");
5128 if (ov == resultExpr && ov->
isRValue() && !forLValue &&
5133 opaqueData = OVMA::bind(CGF, ov, LV);
5138 opaqueData = OVMA::bind(CGF, ov, ov->getSourceExpr());
5141 if (ov == resultExpr) {
5149 opaques.push_back(opaqueData);
5153 }
else if (semantic == resultExpr) {
5166 for (
unsigned i = 0, e = opaques.size(); i != e; ++i)
5167 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.
bool hasAttr(attr::Kind AK) const
Determine whether this type had the specified attribute applied to it (looking through top-level type...
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)
bool Cast(InterpState &S, CodePtr OpPC)
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
void SetLLVMFunctionAttributes(GlobalDecl GD, const CGFunctionInfo &Info, llvm::Function *F)
Set the LLVM function attributes (sext, zext, etc).
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()
enum clang::SubobjectAdjustment::@49 Kind
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>'.
bool This(InterpState &S, CodePtr OpPC)
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...
bool isInlineBuiltinDeclaration() const
Determine if this function provides an inline implementation of a builtin.
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.
llvm::Value * EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, bool isInc, bool isPre)
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)
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
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
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.
const Type * getUnqualifiedDesugaredType() const
Return the specified type with any "sugar" removed from the type, removing any typedefs, typeofs, etc., as well as any qualifiers.
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)
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point...
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())
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()
ValueDecl * getExtendingDecl()
Get the declaration which triggered the lifetime-extension of this temporary, if any.
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)
bool Destroy(InterpState &S, CodePtr OpPC, uint32_t I)
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.
Address getAddress(CodeGenFunction &CGF) const
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.
const AstTypeMatcher< ArrayType > arrayType
Matches all kinds of arrays.
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.
static bool IsPreserveAIArrayBase(CodeGenFunction &CGF, const Expr *ArrayBase)
Given an array base, check whether its member access belongs to a record with preserve_access_index a...
The l-value was considered opaque, so the alignment was determined from a type.
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
llvm::Value * getPointer(CodeGenFunction &CGF) 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.
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 SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F)
Set the LLVM function attributes which only apply to a function definition.
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::FunctionCallee CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList(), bool Local=false, bool AssumeConvergent=false)
Create or return a runtime function declaration with the specified type and name. ...
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)
Assembly: we accept this only so that we can preprocess it.
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.
RValue asAggregateRValue(CodeGenFunction &CGF) const
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.
LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E, bool Accessed=false)
llvm::DIType * getOrCreateStandaloneType(QualType Ty, SourceLocation Loc)
Emit standalone debug info for a type.
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...
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. ...
virtual bool usesThreadWrapperFunction(const VarDecl *VD) const =0
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 setNontemporal(bool Value)
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.
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 Null(InterpState &S, CodePtr OpPC)
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)
bool Load(InterpState &S, CodePtr OpPC)
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
Address CreatePointerBitCastOrAddrSpaceCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
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 ...
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
CallArgList - Type for representing both the value and type of arguments in a call.
const LangOptions & getLangOpts() const
static TBAAAccessInfo getMayAliasInfo()
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 ...