33 #include "llvm/Analysis/ValueTracking.h" 34 #include "llvm/IR/DataLayout.h" 35 #include "llvm/IR/GlobalVariable.h" 36 #include "llvm/IR/Intrinsics.h" 37 #include "llvm/IR/Type.h" 39 using namespace clang;
40 using namespace CodeGen;
44 case Decl::BuiltinTemplate:
45 case Decl::TranslationUnit:
46 case Decl::ExternCContext:
48 case Decl::UnresolvedUsingTypename:
49 case Decl::ClassTemplateSpecialization:
50 case Decl::ClassTemplatePartialSpecialization:
51 case Decl::VarTemplateSpecialization:
52 case Decl::VarTemplatePartialSpecialization:
53 case Decl::TemplateTypeParm:
54 case Decl::UnresolvedUsingValue:
55 case Decl::NonTypeTemplateParm:
56 case Decl::CXXDeductionGuide:
58 case Decl::CXXConstructor:
59 case Decl::CXXDestructor:
60 case Decl::CXXConversion:
62 case Decl::MSProperty:
63 case Decl::IndirectField:
65 case Decl::ObjCAtDefsField:
67 case Decl::ImplicitParam:
68 case Decl::ClassTemplate:
69 case Decl::VarTemplate:
70 case Decl::FunctionTemplate:
71 case Decl::TypeAliasTemplate:
72 case Decl::TemplateTemplateParm:
73 case Decl::ObjCMethod:
74 case Decl::ObjCCategory:
75 case Decl::ObjCProtocol:
76 case Decl::ObjCInterface:
77 case Decl::ObjCCategoryImpl:
78 case Decl::ObjCImplementation:
79 case Decl::ObjCProperty:
80 case Decl::ObjCCompatibleAlias:
81 case Decl::PragmaComment:
82 case Decl::PragmaDetectMismatch:
83 case Decl::AccessSpec:
84 case Decl::LinkageSpec:
86 case Decl::ObjCPropertyImpl:
87 case Decl::FileScopeAsm:
89 case Decl::FriendTemplate:
92 case Decl::ClassScopeFunctionSpecialization:
93 case Decl::UsingShadow:
94 case Decl::ConstructorUsingShadow:
95 case Decl::ObjCTypeParam:
97 llvm_unreachable(
"Declaration should not be in declstmts!");
101 case Decl::EnumConstant:
102 case Decl::CXXRecord:
103 case Decl::StaticAssert:
106 case Decl::OMPThreadPrivate:
107 case Decl::OMPCapturedExpr:
108 case Decl::OMPRequires:
113 case Decl::NamespaceAlias:
115 DI->EmitNamespaceAlias(cast<NamespaceAliasDecl>(D));
119 DI->EmitUsingDecl(cast<UsingDecl>(D));
121 case Decl::UsingPack:
122 for (
auto *Using : cast<UsingPackDecl>(D).expansions())
125 case Decl::UsingDirective:
127 DI->EmitUsingDirective(cast<UsingDirectiveDecl>(D));
130 case Decl::Decomposition: {
131 const VarDecl &VD = cast<VarDecl>(D);
133 "Should not see file-scope variables inside a function!");
135 if (
auto *DD = dyn_cast<DecompositionDecl>(&VD))
136 for (
auto *B : DD->bindings())
137 if (
auto *HD = B->getHoldingVar())
142 case Decl::OMPDeclareReduction:
146 case Decl::TypeAlias: {
150 if (Ty->isVariablyModifiedType())
171 llvm::GlobalValue::LinkageTypes
Linkage =
194 std::string ContextName;
196 if (
auto *CD = dyn_cast<CapturedDecl>(DC))
197 DC = cast<DeclContext>(CD->getNonClosureContext());
198 if (
const auto *FD = dyn_cast<FunctionDecl>(DC))
200 else if (
const auto *BD = dyn_cast<BlockDecl>(DC))
202 else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(DC))
203 ContextName = OMD->getSelector().getAsString();
205 llvm_unreachable(
"Unknown context for static var decl");
217 if (llvm::Constant *ExistingGV = StaticLocalDeclMap[&D])
225 if (D.hasAttr<AsmLabelAttr>())
226 Name = getMangledName(&D);
231 LangAS AS = GetGlobalVarAddressSpace(&D);
236 llvm::Constant *Init =
nullptr;
238 D.hasAttr<CUDASharedAttr>())
239 Init = llvm::UndefValue::get(LTy);
243 llvm::GlobalVariable *GV =
new llvm::GlobalVariable(
245 nullptr, llvm::GlobalVariable::NotThreadLocal, TargetAS);
248 if (supportsCOMDAT() && GV->isWeakForLinker())
249 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
254 setGVProperties(GV, &D);
258 llvm::Constant *Addr = GV;
259 if (AS != ExpectedAS) {
260 Addr = getTargetCodeGenInfo().performAddrSpaceCast(
261 *
this, GV, AS, ExpectedAS,
262 LTy->getPointerTo(
getContext().getTargetAddressSpace(ExpectedAS)));
265 setStaticLocalDeclAddress(&D, Addr);
269 const Decl *DC = cast<Decl>(D.getDeclContext());
273 if (isa<BlockDecl>(DC) || isa<CapturedDecl>(DC)) {
281 if (
const auto *CD = dyn_cast<CXXConstructorDecl>(DC))
283 else if (
const auto *DD = dyn_cast<CXXDestructorDecl>(DC))
285 else if (
const auto *FD = dyn_cast<FunctionDecl>(DC))
290 assert(isa<ObjCMethodDecl>(DC) &&
"unexpected parent code decl");
295 (void)GetAddrOfGlobal(GD);
313 llvm::GlobalVariable *
315 llvm::GlobalVariable *GV) {
327 GV->setConstant(
false);
338 if (GV->getType()->getElementType() != Init->getType()) {
339 llvm::GlobalVariable *OldGV = GV;
341 GV =
new llvm::GlobalVariable(
CGM.
getModule(), Init->getType(),
343 OldGV->getLinkage(), Init,
"",
345 OldGV->getThreadLocalMode(),
347 GV->setVisibility(OldGV->getVisibility());
348 GV->setDSOLocal(OldGV->isDSOLocal());
349 GV->setComdat(OldGV->getComdat());
355 llvm::Constant *NewPtrForOldDecl =
356 llvm::ConstantExpr::getBitCast(GV, OldGV->getType());
357 OldGV->replaceAllUsesWith(NewPtrForOldDecl);
360 OldGV->eraseFromParent();
364 GV->setInitializer(Init);
379 llvm::GlobalValue::LinkageTypes
Linkage) {
388 setAddrOfLocalVar(&D,
Address(addr, alignment));
399 llvm::GlobalVariable *var =
400 cast<llvm::GlobalVariable>(addr->stripPointerCasts());
409 if (D.
getInit() && !isCudaSharedVar)
417 if (
auto *SA = D.
getAttr<PragmaClangBSSSectionAttr>())
418 var->addAttribute(
"bss-section", SA->getName());
419 if (
auto *SA = D.
getAttr<PragmaClangDataSectionAttr>())
420 var->addAttribute(
"data-section", SA->getName());
421 if (
auto *SA = D.
getAttr<PragmaClangRodataSectionAttr>())
422 var->addAttribute(
"rodata-section", SA->getName());
424 if (
const SectionAttr *SA = D.
getAttr<SectionAttr>())
425 var->setSection(SA->getName());
435 llvm::Constant *castedAddr =
436 llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(var, expectedType);
437 if (var != castedAddr)
438 LocalDeclMap.find(&D)->second =
Address(castedAddr, alignment);
456 bool useEHCleanupForArray)
457 : addr(addr),
type(type), destroyer(destroyer),
458 useEHCleanupForArray(useEHCleanupForArray) {}
463 bool useEHCleanupForArray;
467 bool useEHCleanupForArray =
468 flags.isForNormalCleanup() && this->useEHCleanupForArray;
470 CGF.
emitDestroy(addr, type, destroyer, useEHCleanupForArray);
474 template <
class Derived>
477 : NRVOFlag(NRVOFlag), Loc(addr) {}
484 bool NRVO = flags.isForNormalCleanup() && NRVOFlag;
486 llvm::BasicBlock *SkipDtorBB =
nullptr;
493 CGF.
Builder.CreateCondBr(DidNRVO, SkipDtorBB, RunDtorBB);
497 static_cast<Derived *
>(
this)->emitDestructorCall(CGF);
502 virtual ~DestroyNRVOVariable() =
default;
505 struct DestroyNRVOVariableCXX final
506 : DestroyNRVOVariable<DestroyNRVOVariableCXX> {
509 : DestroyNRVOVariable<DestroyNRVOVariableCXX>(addr, NRVOFlag),
521 struct DestroyNRVOVariableC final
522 : DestroyNRVOVariable<DestroyNRVOVariableC> {
524 : DestroyNRVOVariable<DestroyNRVOVariableC>(addr, NRVOFlag), Ty(Ty) {}
535 CallStackRestore(
Address Stack) : Stack(Stack) {}
545 ExtendGCLifetime(
const VarDecl *var) : Var(*var) {}
559 llvm::Constant *CleanupFn;
563 CallCleanupFunction(llvm::Constant *CleanupFn,
const CGFunctionInfo *Info,
565 : CleanupFn(CleanupFn), FnInfo(*Info), Var(*Var) {}
600 llvm_unreachable(
"present but none");
608 (var.
hasAttr<ObjCPreciseLifetimeAttr>()
632 if (
const Expr *e = dyn_cast<Expr>(s)) {
635 s = e = e->IgnoreParenCasts();
637 if (
const DeclRefExpr *ref = dyn_cast<DeclRefExpr>(e))
638 return (ref->getDecl() == &var);
639 if (
const BlockExpr *be = dyn_cast<BlockExpr>(e)) {
640 const BlockDecl *block = be->getBlockDecl();
641 for (
const auto &I : block->
captures()) {
642 if (I.getVariable() == &var)
657 if (!decl)
return false;
658 if (!isa<VarDecl>(decl))
return false;
665 bool needsCast =
false;
672 case CK_BlockPointerToObjCPointerCast:
678 case CK_LValueToRValue: {
721 if (!
SanOpts.
has(SanitizerKind::NullabilityAssign))
732 llvm::Constant *StaticData[] = {
734 llvm::ConstantInt::get(
Int8Ty, 0),
736 EmitCheck({{IsNotNull, SanitizerKind::NullabilityAssign}},
737 SanitizerHandler::TypeMismatch, StaticData, RHS);
741 LValue lvalue,
bool capturedByInit) {
753 init = DIE->getExpr();
757 if (
const FullExpr *fe = dyn_cast<FullExpr>(init)) {
759 init = fe->getSubExpr();
767 bool accessedByInit =
false;
769 accessedByInit = (capturedByInit ||
isAccessedBy(D, init));
770 if (accessedByInit) {
773 if (capturedByInit) {
798 llvm_unreachable(
"present but none");
801 if (!D || !isa<VarDecl>(D) || !cast<VarDecl>(D)->isARCPseudoStrong()) {
862 if (isa<llvm::ConstantAggregateZero>(Init) ||
863 isa<llvm::ConstantPointerNull>(Init) ||
864 isa<llvm::UndefValue>(Init))
866 if (isa<llvm::ConstantInt>(Init) || isa<llvm::ConstantFP>(Init) ||
867 isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) ||
868 isa<llvm::ConstantExpr>(Init))
869 return Init->isNullValue() || NumStores--;
872 if (isa<llvm::ConstantArray>(Init) || isa<llvm::ConstantStruct>(Init)) {
873 for (
unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) {
874 llvm::Constant *Elt = cast<llvm::Constant>(Init->getOperand(i));
881 if (llvm::ConstantDataSequential *CDS =
882 dyn_cast<llvm::ConstantDataSequential>(Init)) {
883 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
884 llvm::Constant *Elt = CDS->getElementAsConstant(i);
898 llvm::Constant *Init,
Address Loc,
900 assert(!Init->isNullValue() && !isa<llvm::UndefValue>(Init) &&
901 "called emitStoresForInitAfterBZero for zero or undef value.");
903 if (isa<llvm::ConstantInt>(Init) || isa<llvm::ConstantFP>(Init) ||
904 isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) ||
905 isa<llvm::ConstantExpr>(Init)) {
910 if (llvm::ConstantDataSequential *CDS =
911 dyn_cast<llvm::ConstantDataSequential>(Init)) {
912 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
913 llvm::Constant *Elt = CDS->getElementAsConstant(i);
916 if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt))
920 isVolatile, Builder);
925 assert((isa<llvm::ConstantStruct>(Init) || isa<llvm::ConstantArray>(Init)) &&
926 "Unknown value type!");
928 for (
unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) {
929 llvm::Constant *Elt = cast<llvm::Constant>(Init->getOperand(i));
932 if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt))
936 isVolatile, Builder);
944 uint64_t GlobalSize) {
946 if (isa<llvm::ConstantAggregateZero>(Init))
return true;
952 unsigned StoreBudget = 6;
953 uint64_t SizeLimit = 32;
955 return GlobalSize > SizeLimit &&
965 uint64_t GlobalSize) {
966 uint64_t SizeLimit = 32;
967 if (GlobalSize <= SizeLimit)
969 return llvm::isBytewiseValue(Init);
977 constexpr uint64_t LargeValue = 0xAAAAAAAAAAAAAAAAull;
982 constexpr uint32_t SmallValue = 0x000000AA;
989 constexpr
bool NegativeNaN =
true;
990 constexpr uint64_t NaNPayload = 0xFFFFFFFFFFFFFFFFull;
991 if (Ty->isIntOrIntVectorTy()) {
992 unsigned BitWidth = cast<llvm::IntegerType>(
993 Ty->isVectorTy() ? Ty->getVectorElementType() : Ty)
996 return llvm::ConstantInt::get(Ty, LargeValue);
997 return llvm::ConstantInt::get(
998 Ty, llvm::APInt::getSplat(BitWidth, llvm::APInt(64, LargeValue)));
1000 if (Ty->isPtrOrPtrVectorTy()) {
1001 auto *PtrTy = cast<llvm::PointerType>(
1002 Ty->isVectorTy() ? Ty->getVectorElementType() : Ty);
1004 PtrTy->getAddressSpace());
1009 llvm_unreachable(
"pattern initialization of unsupported pointer width");
1011 IntValue = LargeValue;
1014 IntValue = SmallValue;
1017 auto *Int = llvm::ConstantInt::get(IntTy, IntValue);
1018 return llvm::ConstantExpr::getIntToPtr(Int, PtrTy);
1020 if (Ty->isFPOrFPVectorTy()) {
1021 unsigned BitWidth = llvm::APFloat::semanticsSizeInBits(
1022 (Ty->isVectorTy() ? Ty->getVectorElementType() : Ty)
1023 ->getFltSemantics());
1024 llvm::APInt Payload(64, NaNPayload);
1026 Payload = llvm::APInt::getSplat(BitWidth, Payload);
1027 return llvm::ConstantFP::getQNaN(Ty, NegativeNaN, &Payload);
1029 if (Ty->isArrayTy()) {
1032 auto *ArrTy = cast<llvm::ArrayType>(Ty);
1034 ArrTy->getNumElements(),
patternFor(CGM, ArrTy->getElementType()));
1035 return llvm::ConstantArray::get(ArrTy, Element);
1044 auto *StructTy = cast<llvm::StructType>(Ty);
1046 for (
unsigned El = 0; El != Struct.size(); ++El)
1047 Struct[El] =
patternFor(CGM, StructTy->getElementType(El));
1048 return llvm::ConstantStruct::get(StructTy, Struct);
1053 llvm::Constant *Constant,
1055 auto FunctionName = [&](
const DeclContext *DC) -> std::string {
1056 if (
const auto *FD = dyn_cast<FunctionDecl>(DC)) {
1057 if (
const auto *CC = dyn_cast<CXXConstructorDecl>(FD))
1058 return CC->getNameAsString();
1059 if (
const auto *CD = dyn_cast<CXXDestructorDecl>(FD))
1060 return CD->getNameAsString();
1062 }
else if (
const auto *OM = dyn_cast<ObjCMethodDecl>(DC)) {
1063 return OM->getNameAsString();
1064 }
else if (isa<BlockDecl>(DC)) {
1066 }
else if (isa<CapturedDecl>(DC)) {
1067 return "<captured>";
1069 llvm::llvm_unreachable_internal(
"expected a function or method");
1073 auto *Ty = Constant->getType();
1074 bool isConstant =
true;
1075 llvm::GlobalVariable *InsertBefore =
nullptr;
1078 llvm::GlobalVariable *GV =
new llvm::GlobalVariable(
1079 CGM.
getModule(), Ty, isConstant, llvm::GlobalValue::PrivateLinkage,
1083 InsertBefore, llvm::GlobalValue::NotThreadLocal, AS);
1085 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
1097 llvm::Constant *constant) {
1098 auto *Ty = constant->getType();
1099 bool isScalar = Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy() ||
1100 Ty->isFPOrFPVectorTy();
1111 uint64_t ConstantSize = CGM.
getDataLayout().getTypeAllocSize(Ty);
1112 auto *SizeVal = llvm::ConstantInt::get(IntPtrTy, ConstantSize);
1117 bool valueAlreadyCorrect =
1118 constant->isNullValue() || isa<llvm::UndefValue>(constant);
1119 if (!valueAlreadyCorrect) {
1128 uint64_t
Value = 0x00;
1129 if (!isa<llvm::UndefValue>(Pattern)) {
1130 const llvm::APInt &AP = cast<llvm::ConstantInt>(Pattern)->
getValue();
1131 assert(AP.getBitWidth() <= 8);
1132 Value = AP.getLimitedValue();
1142 SizeVal, isVolatile);
1149 llvm::Constant *constant = llvm::Constant::getNullValue(ElTy);
1157 llvm::Constant *constant =
patternFor(CGM, ElTy);
1158 assert(!isa<llvm::UndefValue>(constant));
1163 auto *Ty = constant->getType();
1164 if (isa<llvm::UndefValue>(constant))
1166 if (Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy())
1167 for (llvm::Use &Op : constant->operands())
1177 auto *Ty = constant->getType();
1178 if (isa<llvm::UndefValue>(constant))
1179 return llvm::Constant::getNullValue(Ty);
1180 if (!(Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy()))
1185 for (
unsigned Op = 0, NumOp = constant->getNumOperands(); Op != NumOp; ++Op) {
1186 auto *OpValue = cast<llvm::Constant>(constant->getOperand(Op));
1189 if (Ty->isStructTy())
1190 return llvm::ConstantStruct::get(cast<llvm::StructType>(Ty), Values);
1191 if (Ty->isArrayTy())
1192 return llvm::ConstantArray::get(cast<llvm::ArrayType>(Ty), Values);
1193 assert(Ty->isVectorTy());
1194 return llvm::ConstantVector::get(Values);
1211 if (!ShouldEmitLifetimeMarkers)
1214 assert(Addr->getType()->getPointerAddressSpace() ==
1216 "Pointer should be in alloca address space");
1221 C->setDoesNotThrow();
1226 assert(Addr->getType()->getPointerAddressSpace() ==
1228 "Pointer should be in alloca address space");
1232 C->setDoesNotThrow();
1244 while (
getContext().getAsVariableArrayType(Type1D)) {
1246 if (
auto *C = dyn_cast<llvm::ConstantInt>(VlaSize.NumElts))
1250 Twine Name = Twine(
"__vla_expr") + Twine(VLAExprCounter++);
1252 StringRef NameRef = Name.toStringRef(Buffer);
1254 VLAExprNames.push_back(&Ident);
1258 Dimensions.emplace_back(SizeExprAddr.getPointer(),
1261 Type1D = VlaSize.Type;
1270 unsigned NameIdx = 0;
1271 for (
auto &VlaSize : Dimensions) {
1273 if (
auto *C = dyn_cast<llvm::ConstantInt>(VlaSize.NumElts))
1274 MD = llvm::ConstantAsMetadata::get(C);
1278 auto VlaExprTy = VlaSize.NumElts->getType()->getPointerElementType();
1280 VlaExprTy->getScalarSizeInBits(),
false);
1290 assert(MD &&
"No Size expression debug node created");
1307 emission.IsEscapingByRef = isEscapingByRef;
1352 assert(emission.wasEmittedAsGlobal());
1357 emission.IsConstantAggregate =
true;
1370 address = OpenMPLocalAddr;
1378 const auto *RD = RecordTy->getDecl();
1380 if ((CXXRD && !CXXRD->hasTrivialDestructor()) ||
1381 RD->isNonTrivialToPrimitiveDestroy()) {
1399 if (isEscapingByRef) {
1401 allocaTy = byrefInfo.Type;
1402 allocaAlignment = byrefInfo.ByrefAlignment;
1405 allocaAlignment = alignment;
1412 nullptr, &AllocaAddr);
1417 bool IsMSCatchParam =
1439 emission.SizeForLifetimeMarkers =
1449 if (!DidCallStackSave) {
1458 DidCallStackSave =
true;
1478 setAddrOfLocalVar(&D, address);
1479 emission.Addr = address;
1480 emission.AllocaAddr = AllocaAddr;
1488 if (D.
hasAttr<AnnotateAttr>())
1505 if (
const Expr *E = dyn_cast<Expr>(S))
1520 if (
const BlockExpr *BE = dyn_cast<BlockExpr>(E)) {
1521 const BlockDecl *Block = BE->getBlockDecl();
1522 for (
const auto &I : Block->
captures()) {
1523 if (I.getVariable() == &Var)
1531 if (
const StmtExpr *SE = dyn_cast<StmtExpr>(E)) {
1533 for (
const auto *BI : CS->
body())
1534 if (
const auto *BIE = dyn_cast<Expr>(BI)) {
1538 else if (
const auto *DS = dyn_cast<DeclStmt>(BI)) {
1540 for (
const auto *I : DS->decls()) {
1541 if (
const auto *VD = dyn_cast<VarDecl>((I))) {
1542 const Expr *Init = VD->getInit();
1570 if (Constructor->isTrivial() &&
1571 Constructor->isDefaultConstructor() &&
1572 !Construct->requiresZeroInitialization())
1579 assert(emission.Variable &&
"emission was not valid!");
1582 if (emission.wasEmittedAsGlobal())
return;
1584 const VarDecl &D = *emission.Variable;
1601 if (emission.IsEscapingByRef)
1608 type.isNonTrivialToPrimitiveDefaultInitialize() ==
1611 if (emission.IsEscapingByRef)
1620 bool capturedByInit =
1621 Init && emission.IsEscapingByRef &&
isCapturedBy(D, Init);
1623 bool locIsByrefHeader = !capturedByInit;
1631 : (D.
getAttr<UninitializedAttr>()
1635 auto initializeWhatIsTechnicallyUninitialized = [&](
Address Loc) {
1636 if (trivialAutoVarInit ==
1641 if (emission.IsEscapingByRef && !locIsByrefHeader)
1646 switch (trivialAutoVarInit) {
1648 llvm_unreachable(
"Uninitialized handled above");
1669 auto SizeVal = VlaSize.NumElts;
1671 switch (trivialAutoVarInit) {
1673 llvm_unreachable(
"Uninitialized handled above");
1676 if (!EltSize.
isOne())
1690 SizeVal, llvm::ConstantInt::get(SizeVal->getType(), 0),
1692 Builder.CreateCondBr(IsZeroSizedVLA, ContBB, SetupBB);
1694 if (!EltSize.
isOne())
1700 Builder.CreateInBoundsGEP(Begin.getPointer(), SizeVal,
"vla.end");
1701 llvm::BasicBlock *OriginBB =
Builder.GetInsertBlock();
1703 llvm::PHINode *Cur =
Builder.CreatePHI(Begin.getType(), 2,
"vla.cur");
1704 Cur->addIncoming(Begin.getPointer(), OriginBB);
1709 BaseSizeInChars, isVolatile);
1711 Builder.CreateInBoundsGEP(
Int8Ty, Cur, BaseSizeInChars,
"vla.next");
1713 Builder.CreateCondBr(Done, ContBB, LoopBB);
1714 Cur->addIncoming(Next, LoopBB);
1721 initializeWhatIsTechnicallyUninitialized(Loc);
1725 llvm::Constant *constant =
nullptr;
1726 if (emission.IsConstantAggregate || D.
isConstexpr()) {
1727 assert(!capturedByInit &&
"constant init contains a capturing block?");
1729 if (constant && trivialAutoVarInit !=
1735 initializeWhatIsTechnicallyUninitialized(Loc);
1741 if (!emission.IsConstantAggregate) {
1751 isVolatile,
Builder, constant);
1767 LValue lvalue,
bool capturedByInit) {
1793 if (isa<VarDecl>(D))
1795 else if (
auto *FD = dyn_cast<FieldDecl>(D))
1806 llvm_unreachable(
"bad evaluation kind");
1819 const VarDecl *var = emission.Variable;
1827 llvm_unreachable(
"no cleanup for trivially-destructible variable");
1832 if (emission.NRVOFlag) {
1835 EHStack.pushCleanup<DestroyNRVOVariableCXX>(cleanupKind, addr, dtor,
1849 if (!var->
hasAttr<ObjCPreciseLifetimeAttr>())
1858 if (emission.NRVOFlag) {
1860 EHStack.pushCleanup<DestroyNRVOVariableC>(cleanupKind, addr,
1861 emission.NRVOFlag,
type);
1872 bool useEHCleanup = (cleanupKind &
EHCleanup);
1873 EHStack.pushCleanup<DestroyObject>(cleanupKind, addr,
type, destroyer,
1878 assert(emission.Variable &&
"emission was not valid!");
1881 if (emission.wasEmittedAsGlobal())
return;
1887 const VarDecl &D = *emission.Variable;
1895 D.
hasAttr<ObjCPreciseLifetimeAttr>()) {
1900 if (
const CleanupAttr *CA = D.
getAttr<CleanupAttr>()) {
1904 assert(F &&
"Could not find function!");
1913 if (emission.IsEscapingByRef &&
1937 llvm_unreachable(
"Unknown DestructionKind");
1944 assert(dtorKind &&
"cannot push destructor for trivial type");
1954 assert(dtorKind &&
"cannot push destructor for trivial type");
1963 bool useEHCleanupForArray) {
1964 pushFullExprCleanup<DestroyObject>(cleanupKind, addr,
type,
1965 destroyer, useEHCleanupForArray);
1969 EHStack.pushCleanup<CallStackRestore>(
Kind, SPMem);
1974 Destroyer *destroyer,
bool useEHCleanupForArray) {
1979 EHStack.pushCleanup<DestroyObject>(
1981 destroyer, useEHCleanupForArray);
1985 pushCleanupAfterFullExpr<DestroyObject>(
1986 cleanupKind, addr,
type, destroyer, useEHCleanupForArray);
2002 bool useEHCleanupForArray) {
2005 return destroyer(*
this, addr, type);
2014 bool checkZeroLength =
true;
2017 if (llvm::ConstantInt *constLength = dyn_cast<llvm::ConstantInt>(length)) {
2019 if (constLength->isZero())
return;
2020 checkZeroLength =
false;
2026 checkZeroLength, useEHCleanupForArray);
2044 bool checkZeroLength,
2045 bool useEHCleanup) {
2053 if (checkZeroLength) {
2055 "arraydestroy.isempty");
2056 Builder.CreateCondBr(isEmpty, doneBB, bodyBB);
2060 llvm::BasicBlock *entryBB =
Builder.GetInsertBlock();
2062 llvm::PHINode *elementPast =
2063 Builder.CreatePHI(begin->getType(), 2,
"arraydestroy.elementPast");
2064 elementPast->addIncoming(end, entryBB);
2069 "arraydestroy.element");
2076 destroyer(*
this,
Address(element, elementAlign), elementType);
2083 Builder.CreateCondBr(done, doneBB, bodyBB);
2084 elementPast->addIncoming(element,
Builder.GetInsertBlock());
2097 unsigned arrayDepth = 0;
2109 begin = CGF.
Builder.CreateInBoundsGEP(begin, gepIndices,
"pad.arraybegin");
2110 end = CGF.
Builder.CreateInBoundsGEP(end, gepIndices,
"pad.arrayend");
2134 : ArrayBegin(arrayBegin), ArrayEnd(arrayEnd),
2135 ElementType(elementType),
Destroyer(destroyer),
2136 ElementAlign(elementAlign) {}
2140 ElementType, ElementAlign, Destroyer);
2154 IrregularPartialArrayDestroy(
llvm::Value *arrayBegin,
2159 : ArrayBegin(arrayBegin), ArrayEndPointer(arrayEndPointer),
2160 ElementType(elementType),
Destroyer(destroyer),
2161 ElementAlign(elementAlign) {}
2166 ElementType, ElementAlign, Destroyer);
2182 pushFullExprCleanup<IrregularPartialArrayDestroy>(
EHCleanup,
2183 arrayBegin, arrayEndPointer,
2184 elementType, elementAlign,
2199 pushFullExprCleanup<RegularPartialArrayDestroy>(
EHCleanup,
2200 arrayBegin, arrayEnd,
2201 elementType, elementAlign,
2207 if (LifetimeStartFn)
2208 return LifetimeStartFn;
2209 LifetimeStartFn = llvm::Intrinsic::getDeclaration(&getModule(),
2211 return LifetimeStartFn;
2217 return LifetimeEndFn;
2218 LifetimeEndFn = llvm::Intrinsic::getDeclaration(&getModule(),
2220 return LifetimeEndFn;
2231 : Param(param), Precise(precise) {}
2247 assert((isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D)) &&
2248 "Invalid argument to EmitParmDecl");
2255 if (
auto IPD = dyn_cast<ImplicitParamDecl>(&D)) {
2268 bool DoStore =
false;
2274 unsigned AS = DeclPtr.
getType()->getAddressSpace();
2276 if (DeclPtr.
getType() != IRTy)
2285 if (SrcLangAS != DestLangAS) {
2286 assert(
getContext().getTargetAddressSpace(SrcLangAS) ==
2289 auto *T = V->getType()->getPointerElementType()->getPointerTo(DestAS);
2291 *
this, V, SrcLangAS, DestLangAS, T,
true),
2303 "unexpected destructor type");
2305 CalleeDestructedParamCleanups[cast<ParmVarDecl>(&D)] =
2316 DeclPtr = OpenMPLocalAddr;
2335 bool isConsumed = D.
hasAttr<NSConsumedAttr>();
2340 "pseudo-strong variable isn't strong?");
2341 assert(qs.
hasConst() &&
"pseudo-strong variable should be const!");
2390 setAddrOfLocalVar(&D, DeclPtr);
2400 if (D.
hasAttr<AnnotateAttr>())
2406 if (requiresReturnValueNullabilityCheck()) {
2410 RetValNullabilityPrecondition =
2411 Builder.CreateAnd(RetValNullabilityPrecondition,
2419 if (!LangOpts.OpenMP || (!LangOpts.EmitAllDecls && !D->
isUsed()))
2421 getOpenMPRuntime().emitUserDefinedReduction(CGF, D);
2425 getOpenMPRuntime().checkArchForUnifiedAddressing(*
this, D);
const llvm::DataLayout & getDataLayout() const
CGOpenCLRuntime & getOpenCLRuntime()
Return a reference to the configured OpenCL runtime.
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.
Defines the clang::ASTContext interface.
static bool canEmitInitWithFewStoresAfterBZero(llvm::Constant *Init, unsigned &NumStores)
Decide whether we can emit the non-zero parts of the specified initializer with equal or fewer than N...
void setImplicit(bool I=true)
Represents a function declaration or definition.
llvm::IntegerType * IntTy
int
void EmitStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
llvm::Value * EmitARCRetainAutoreleaseScalarExpr(const Expr *expr)
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
A (possibly-)qualified type.
Allows to disable automatic handling of functions used in target regions as those marked as omp decla...
void EmitExtendGCLifetime(llvm::Value *object)
EmitExtendGCLifetime - Given a pointer to an Objective-C object, make sure it survives garbage collec...
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
CodeGenTypes & getTypes()
llvm::Type * ConvertTypeForMem(QualType T)
const CodeGenOptions & getCodeGenOpts() const
void EmitVarDecl(const VarDecl &D)
EmitVarDecl - Emit a local variable declaration.
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::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)
bool HaveInsertPoint() const
HaveInsertPoint - True if an insertion point is defined.
llvm::LLVMContext & getLLVMContext()
Stmt - This represents one statement.
llvm::Constant * tryEmitForInitializer(const VarDecl &D)
Try to emit the initiaizer of the given declaration as an abstract constant.
Defines the SourceManager interface.
bool isRecordType() const
bool hasLabelBeenSeenInCurrentScope() const
Return true if a label was seen in the current scope.
void emitAutoVarTypeCleanup(const AutoVarEmission &emission, QualType::DestructionKind dtorKind)
Enter a destroy cleanup for the given local variable.
Decl - This represents one declaration (or definition), e.g.
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 call a handler function in a sanitizer runtime with the provided argum...
void EmitAutoVarDecl(const VarDecl &D)
EmitAutoVarDecl - Emit an auto variable declaration.
static Destroyer destroyARCStrongPrecise
void pushLifetimeExtendedDestroy(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
EmitStoreThroughLValue - Store the specified rvalue into the specified lvalue, where both are guarant...
static void emitStoresForInitAfterBZero(CodeGenModule &CGM, llvm::Constant *Init, Address Loc, bool isVolatile, CGBuilderTy &Builder)
For inits that canEmitInitWithFewStoresAfterBZero returned true for, emit the scalar stores that woul...
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Represents a call to a C++ constructor.
bool isZero() const
isZero - Test whether the quantity equals zero.
stable_iterator stable_begin() const
Create a stable reference to the top of the EH stack.
const TargetInfo & getTargetInfo() const
void EmitARCCopyWeak(Address dst, Address src)
void @objc_copyWeak(i8** dest, i8** src) Disregards the current value in dest.
constexpr XRayInstrMask Function
llvm::Value * EmitARCRetainNonBlock(llvm::Value *value)
Retain the given object, with normal retain semantics.
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Represents a C++ constructor within a class.
const DeclContext * getParentFunctionOrMethod() const
If this decl is defined inside a function/method/block it returns the corresponding DeclContext...
The type is a struct containing a field whose type is not PCK_Trivial.
static bool shouldUseBZeroPlusStoresToInitialize(llvm::Constant *Init, uint64_t GlobalSize)
Decide whether we should use bzero plus some stores to initialize a local variable instead of using a...
static llvm::Value * shouldUseMemSetToInitialize(llvm::Constant *Init, uint64_t GlobalSize)
Decide whether we should use memset to initialize a local variable instead of using a memcpy from a c...
static Destroyer destroyARCWeak
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::Instruction **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.
Represents a variable declaration or definition.
Address getObjectAddress(CodeGenFunction &CGF) const
Returns the address of the object within this declaration.
RAII object to set/unset CodeGenFunction::IsSanitizerScope.
const T * getAs() const
Member-template getAs<specific type>'.
LangAS
Defines the address space values used by the address space qualifier of QualType. ...
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
void EmitVariablyModifiedType(QualType Ty)
EmitVLASize - Capture all the sizes for the VLA expressions in the given variably-modified type and s...
llvm::Value * getPointer() const
bool useLifetimeMarkers() const
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
unsigned getAddressSpace() const
Return the address space that this address resides in.
The collection of all-type qualifiers we support.
void add(RValue rvalue, QualType type)
bool isARCPseudoStrong() const
Determine whether this variable is an ARC pseudo-__strong variable.
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
const TargetInfo & getTarget() const
One of these records is kept for each identifier that is lexed.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
void emitDestroy(Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
emitDestroy - Immediately perform the destruction of the given object.
void emitByrefStructureInit(const AutoVarEmission &emission)
Initialize the structural components of a __block variable, i.e.
VlaSizePair getVLAElements1D(const VariableArrayType *vla)
Return the number of elements for a single dimension for the given array type.
Address getAddress() const
CGDebugInfo * getDebugInfo()
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
llvm::Constant * tryEmitAbstractForInitializer(const VarDecl &D)
Try to emit the initializer of the given declaration as an abstract constant.
void EmitExprAsInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
EmitExprAsInit - Emits the code necessary to initialize a location in memory with the given initializ...
Address getIndirectAddress() const
llvm::IntegerType * Int64Ty
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
FullExpr - Represents a "full-expression" node.
llvm::IntegerType * SizeTy
Qualifiers::ObjCLifetime getObjCLifetime() const
bool isReferenceType() const
void pushEHDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
pushEHDestroy - Push the standard destructor for the given type as an EH-only cleanup.
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
static bool containsUndef(llvm::Constant *constant)
Address getAllocatedAddress() const
Returns the raw, allocated address, which is not necessarily the address of the object itself...
CleanupKind getCleanupKind(QualType::DestructionKind kind)
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...
void setNonGC(bool Value)
llvm::Constant * getLLVMLifetimeStartFn()
Lazily declare the .lifetime.start intrinsic.
llvm::Value * EmitARCStoreStrongCall(Address addr, llvm::Value *value, bool resultIgnored)
Store into a strong object.
void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin, llvm::Value *arrayEnd, QualType elementType, CharUnits elementAlignment, Destroyer *destroyer)
pushRegularPartialArrayCleanup - Push an EH cleanup to destroy already-constructed elements of the gi...
static bool hasScalarEvaluationKind(QualType T)
static void drillIntoBlockVariable(CodeGenFunction &CGF, LValue &lvalue, const VarDecl *var)
void defaultInitNonTrivialCStructVar(LValue Dst)
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.
void EmitOMPRequiresDecl(const OMPRequiresDecl *D)
Emit a code for requires directive.
void EmitOMPDeclareReduction(const OMPDeclareReductionDecl *D, CodeGenFunction *CGF=nullptr)
Emit a code for declare reduction construct.
bool isOne() const
isOne - Test whether the quantity equals one.
An x-value expression is a reference to an object with independent storage but which can be "moved"...
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl)
Emit information about a global variable.
CharUnits getAlignment() const
Return the alignment of this pointer.
void setStaticLocalDeclAddress(const VarDecl *D, llvm::Constant *C)
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
static void emitStoresForConstant(CodeGenModule &CGM, const VarDecl &D, Address Loc, bool isVolatile, CGBuilderTy &Builder, llvm::Constant *constant)
bool needsEHCleanup(QualType::DestructionKind kind)
Determines whether an EH cleanup is required to destroy a type with the given destruction kind...
const_arg_iterator arg_begin() const
llvm::Value * EmitARCUnsafeUnretainedScalarExpr(const Expr *expr)
EmitARCUnsafeUnretainedScalarExpr - Semantically equivalent to immediately releasing the resut of Emi...
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
static llvm::Constant * patternFor(CodeGenModule &CGM, llvm::Type *Ty)
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
Expr * IgnoreParenCasts() LLVM_READONLY
IgnoreParenCasts - Ignore parentheses and casts.
Values of this type can never be null.
Scope - A scope is a transient data structure that is used while parsing the program.
static void emitStoresForPatternInit(CodeGenModule &CGM, const VarDecl &D, Address Loc, bool isVolatile, CGBuilderTy &Builder)
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
llvm::Value * EmitARCRetainScalarExpr(const Expr *expr)
EmitARCRetainScalarExpr - Semantically equivalent to EmitARCRetainObject(e->getType(), EmitScalarExpr(e)), but making a best-effort attempt to peephole expressions that naturally produce retained objects.
Denotes a cleanup that should run when a scope is exited using normal control flow (falling off the e...
void EmitAtomicInit(Expr *E, LValue lvalue)
const internal::VariadicDynCastAllOfMatcher< Stmt, CastExpr > castExpr
Matches any cast nodes of Clang's AST.
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
CharUnits getPointerAlign() const
static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts=false)
ContainsLabel - Return true if the statement contains a label in it.
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
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...
static bool isCapturedBy(const VarDecl &, const Expr *)
Determines whether the given __block variable is potentially captured by the given expression...
void registerVLASizeExpression(QualType Ty, llvm::Metadata *SizeExpr)
Register VLA size expression debug node with the qualified type.
This object can be modified without requiring retains or releases.
bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor)
isTypeConstant - Determine whether an object of this type can be emitted as a constant.
StorageDuration getStorageDuration() const
Get the storage duration of this variable, per C++ [basic.stc].
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...
static CharUnits One()
One - Construct a CharUnits quantity of one.
CompoundStmt - This represents a group of statements like { stmt stmt }.
std::pair< llvm::Value *, llvm::Value * > ComplexPairTy
AutoVarEmission EmitAutoVarAlloca(const VarDecl &var)
EmitAutoVarAlloca - Emit the alloca and debug information for a local variable.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
ASTContext & getContext() const
const CodeGen::CGBlockInfo * BlockInfo
IdentifierInfo & getOwn(StringRef Name)
Gets an IdentifierInfo for the given name without consulting external sources.
RValue - This trivial value class is used to represent the result of an expression that is evaluated...
void setAddress(Address address)
CleanupKind getARCCleanupKind()
Retrieves the default cleanup kind for an ARC cleanup.
StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD)
llvm::Constant * getNullPointer(llvm::PointerType *T, QualType QT)
Get target specific null pointer.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
AggValueSlot::Overlap_t overlapForFieldInit(const FieldDecl *FD)
Determine whether a field initialization may overlap some other object.
Address CreateDefaultAlignTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
CreateDefaultAlignedTempAlloca - This creates an alloca with the default ABI alignment of the given L...
This represents '#pragma omp requires...' directive.
llvm::Value * EmitARCStoreWeak(Address addr, llvm::Value *value, bool ignored)
i8* @objc_storeWeak(i8** addr, i8* value) Returns value.
void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr, bool PerformInit)
Emit code in this function to perform a guarded variable initialization.
llvm::DILocalVariable * EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI, CGBuilderTy &Builder)
Emit call to llvm.dbg.declare for an automatic variable declaration.
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
Pepresents a block literal declaration, which is like an unnamed FunctionDecl.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
This represents one expression.
void EmitARCMoveWeak(Address dst, Address src)
void @objc_moveWeak(i8** dest, i8** src) Disregards the current value in dest.
Emit only debug info necessary for generating line number tables (-gline-tables-only).
Address getOriginalAllocatedAddress() const
Returns the address for the original alloca instruction.
void EmitAutoVarInit(const AutoVarEmission &emission)
void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV)
Add global annotations that are set on D, for the global GV.
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited...
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
virtual void EmitWorkGroupLocalVarDecl(CodeGenFunction &CGF, const VarDecl &D)
Emit the IR required for a work-group-local variable declaration, and add an entry to CGF's LocalDecl...
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Represents a C++ destructor within a class.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
bool isExceptionVariable() const
Determine whether this variable is the exception variable in a C++ catch statememt or an Objective-C ...
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.
llvm::PointerType * getType() const
Return the type of the pointer value.
ObjCLifetime getObjCLifetime() const
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
DeclContext * getDeclContext()
static SVal getValue(SVal val, SValBuilder &svalBuilder)
const AstTypeMatcher< ArrayType > arrayType
Matches all kinds of arrays.
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.
Checking the value assigned to a _Nonnull pointer. Must not be null.
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
llvm::PointerType * AllocaInt8PtrTy
llvm::CallInst * CreateMemSet(Address Dest, llvm::Value *Value, llvm::Value *Size, bool IsVolatile=false)
void emitArrayDestroy(llvm::Value *begin, llvm::Value *end, QualType elementType, CharUnits elementAlign, Destroyer *destroyer, bool checkZeroLength, bool useEHCleanup)
emitArrayDestroy - Destroys all the elements of the given array, beginning from last to first...
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
static bool hasNontrivialDestruction(QualType T)
hasNontrivialDestruction - Determine whether a type's destruction is non-trivial. ...
float __ovld __cnfn length(float p)
Return the length of vector p, i.e., sqrt(p.x2 + p.y 2 + ...)
const LangOptions & getLangOpts() const
ASTContext & getContext() const
GlobalDecl - represents a global declaration.
VarBypassDetector Bypasses
The l-value was considered opaque, so the alignment was determined from a type.
void setBlockContextParameter(const ImplicitParamDecl *D, unsigned argNum, llvm::Value *ptr)
llvm::Constant * getOrCreateStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
There is no lifetime qualification on this type.
Address CreateBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Assigning into this object requires the old value to be released and the new value to be retained...
llvm::GlobalVariable * AddInitializerToStaticVarDecl(const VarDecl &D, llvm::GlobalVariable *GV)
AddInitializerToStaticVarDecl - Add the initializer for 'D' to the global variable that has already b...
void pushDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
pushDestroy - Push the standard destructor for the given type as at least a normal cleanup...
Encodes a location in the source.
void EmitAndRegisterVariableArrayDimensions(CGDebugInfo *DI, const VarDecl &D, bool EmitDebugInfo)
Emits the alloca and debug information for the size expressions for each dimension of an array...
void EnsureInsertPoint()
EnsureInsertPoint - Ensure that an insertion point is defined so that emitted IR has a place to go...
void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise)
Release the given object.
LValue EmitDeclRefLValue(const DeclRefExpr *E)
This represents '#pragma omp declare reduction ...' directive.
LangAS getAddressSpace() const
Return the address space of this type.
static std::string getStaticDeclName(CodeGenModule &CGM, const VarDecl &D)
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
TypeSourceInfo * CreateTypeSourceInfo(QualType T, unsigned Size=0) const
Allocate an uninitialized TypeSourceInfo.
static void emitPartialArrayDestroy(CodeGenFunction &CGF, llvm::Value *begin, llvm::Value *end, QualType type, CharUnits elementAlign, CodeGenFunction::Destroyer *destroyer)
Perform partial array destruction as if in an EH cleanup.
const Decl * getDecl() const
const BlockByrefInfo & getBlockByrefInfo(const VarDecl *var)
BuildByrefInfo - This routine changes a __block variable declared as T x into:
llvm::Value * EmitLifetimeStart(uint64_t Size, llvm::Value *Addr)
Emit a lifetime.begin marker if some criteria are satisfied.
LangAS getStringLiteralAddressSpace() const
Return the AST address space of string literal, which is used to emit the string literal as global va...
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
static bool cxxDestructorCanThrow(QualType T)
Check if T is a C++ class that has a destructor that can throw.
static bool isAccessedBy(const VarDecl &var, const Stmt *s)
static void emitStoresForZeroInit(CodeGenModule &CGM, const VarDecl &D, Address Loc, bool isVolatile, CGBuilderTy &Builder)
SanitizerSet SanOpts
Sanitizers enabled for this function.
This file defines OpenMP nodes for declarative directives.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
bool isTrivialInitializer(const Expr *Init)
Determine whether the given initializer is trivial in the sense that it requires no code to be genera...
bool isObjCObjectPointerType() const
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after...
static void EmitAutoVarWithLifetime(CodeGenFunction &CGF, const VarDecl &var, Address addr, Qualifiers::ObjCLifetime lifetime)
EmitAutoVarWithLifetime - Does the setup required for an automatic variable with lifetime.
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required...
void enterByrefCleanup(CleanupKind Kind, Address Addr, BlockFieldFlags Flags, bool LoadBlockVarAddr, bool CanThrow)
Enter a cleanup to destroy a __block variable.
Address CreateConstInBoundsGEP2_32(Address Addr, unsigned Idx0, unsigned Idx1, const llvm::DataLayout &DL, const llvm::Twine &Name="")
void EmitParmDecl(const VarDecl &D, ParamValue Arg, unsigned ArgNo)
EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
Assigning into this object requires a lifetime extension.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
llvm::Value * getDirectValue() const
static llvm::Constant * replaceUndef(llvm::Constant *constant)
llvm::Constant * getLLVMLifetimeEndFn()
Lazily declare the .lifetime.end intrinsic.
void EmitDecl(const Decl &D)
EmitDecl - Emit a declaration.
const TargetCodeGenInfo & getTargetHooks() const
static Destroyer destroyARCStrongImprecise
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type, returning the result.
void addUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.used metadata.
bool isObjCGCWeak() const
true when Type is objc's weak.
Base class for declarations which introduce a typedef-name.
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
CGFunctionInfo - Class to encapsulate the information about a function definition.
This class organizes the cross-function state that is used while generating LLVM code.
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
Dataflow Directional Tag Classes.
static ApplyDebugLocation CreateDefaultArtificial(CodeGenFunction &CGF, SourceLocation TemporaryLocation)
Apply TemporaryLocation if it is valid.
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating, Address This)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
ArrayRef< Capture > captures() const
const CGFunctionInfo & arrangeFunctionDeclaration(const FunctionDecl *FD)
Free functions are functions that are compatible with an ordinary C function pointer type...
QualType getUnderlyingType() const
const Expr * getInit() const
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
llvm::IntegerType * IntPtrTy
llvm::Value * getAnyValue() const
Decl * getNonClosureContext()
Find the innermost non-closure ancestor of this declaration, walking up through blocks, lambdas, etc.
llvm::Constant * EmitNullConstant(QualType T)
Return the result of value-initializing the given type, i.e.
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type *> Tys=None)
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
static AggValueSlot forLValue(const LValue &LV, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
bool isEscapingByref() const
Indicates the capture is a __block variable that is captured by a block that can potentially escape (...
llvm::Module & getModule() const
static bool tryEmitARCCopyWeakInit(CodeGenFunction &CGF, const LValue &destLV, const Expr *init)
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type. ...
static bool hasAggregateEvaluationKind(QualType T)
void EmitAutoVarCleanups(const AutoVarEmission &emission)
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6.7.5p3.
CodeGenTypes & getTypes() const
void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
bool isConstantInitializer(ASTContext &Ctx, bool ForRef, const Expr **Culprit=nullptr) const
isConstantInitializer - Returns true if this expression can be emitted to IR as a constant...
llvm::Type * getElementType() const
Return the type of the values stored in this address.
bool isAtomicType() const
llvm::PointerType * Int8PtrTy
llvm::LoadInst * CreateFlagLoad(llvm::Value *Addr, const llvm::Twine &Name="")
Emit a load from an i1 flag variable.
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.
StringRef getMangledName(GlobalDecl GD)
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 EmitARCInitWeak(Address addr, llvm::Value *value)
i8* @objc_initWeak(i8** addr, i8* value) Returns value.
Optional< NullabilityKind > getNullability(const ASTContext &context) const
Determine the nullability of the given type.
static Destroyer destroyNonTrivialCStruct
bool IsBypassed(const VarDecl *D) const
Returns true if the variable declaration was by bypassed by any goto or switch statement.
ARCPreciseLifetime_t
Does an ARC strong l-value have precise lifetime?
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.
llvm::ConstantInt * getSize(CharUnits numChars)
Emit the given number of characters as a value of type size_t.
A use of a default initializer in a constructor or in aggregate initialization.
static llvm::Constant * EmitNullConstant(CodeGenModule &CGM, const RecordDecl *record, bool asCompleteObject)
Reading or writing from this object requires a barrier call.
llvm::DenseMap< const VarDecl *, llvm::Value * > NRVOFlags
A mapping from NRVO variables to the flags used to indicate when the NRVO has been applied to this va...
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Represents a C++ struct/union/class.
bool isNRVOVariable() const
Determine whether this local variable can be used with the named return value optimization (NRVO)...
llvm::Type * ConvertType(QualType T)
static Destroyer destroyCXXObject
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
static Address createUnnamedGlobalFrom(CodeGenModule &CGM, const VarDecl &D, CGBuilderTy &Builder, llvm::Constant *Constant, CharUnits Align)
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 pushStackRestore(CleanupKind kind, Address SPMem)
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
bool hasExternalStorage() const
Returns true if a variable has extern or private_extern storage.
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
Defines the clang::TargetInfo interface.
void finalize(llvm::GlobalVariable *global)
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
LangAS getASTAllocaAddressSpace() const
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
llvm::Value * getSizeForLifetimeMarkers() const
void setLocation(SourceLocation Loc)
Update the current source location.
A reference to a declared variable, function, enum, etc.
static RValue get(llvm::Value *V)
void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr)
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...
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
An l-value expression is a reference to an object with independent storage.
LValue - This represents an lvalue references.
Information for lazily generating a cleanup.
void EmitVarAnnotations(const VarDecl *D, llvm::Value *V)
Emit local annotations for the local variable V, declared by D.
Represents a C array with a specified size that is not an integer-constant-expression.
Automatic storage duration (most local variables).
SanitizerMetadata * getSanitizerMetadata()
bool isConstant(const ASTContext &Ctx) const
bool CurFuncIsThunk
In C++, whether we are code generating a thunk.
const LangOptions & getLangOpts() const
unsigned getTargetAddressSpace(QualType T) const
llvm::Value * emitArrayLength(const ArrayType *arrayType, QualType &baseType, Address &addr)
emitArrayLength - Compute the length of an array, even if it's a VLA, and drill down to the base elem...
CallArgList - Type for representing both the value and type of arguments in a call.
const LangOptions & getLangOpts() const
void PopCleanupBlock(bool FallThroughIsBranchThrough=false)
PopCleanupBlock - Will pop the cleanup entry on the stack and process all branch fixups.
llvm::Value * getPointer() const
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...
SourceLocation getLocation() const
void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin, Address arrayEndPointer, QualType elementType, CharUnits elementAlignment, Destroyer *destroyer)
pushIrregularPartialArrayCleanup - Push an EH cleanup to destroy already-constructed elements of the ...
bool isExternallyVisible() const
QualType getIntTypeForBitwidth(unsigned DestWidth, unsigned Signed) const
getIntTypeForBitwidth - sets integer QualTy according to specified details: bitwidth, signed/unsigned.
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
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.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.