34 #include "llvm/Analysis/ValueTracking.h" 35 #include "llvm/IR/DataLayout.h" 36 #include "llvm/IR/GlobalVariable.h" 37 #include "llvm/IR/Intrinsics.h" 38 #include "llvm/IR/Type.h" 40 using namespace clang;
41 using namespace CodeGen;
45 case Decl::BuiltinTemplate:
46 case Decl::TranslationUnit:
47 case Decl::ExternCContext:
49 case Decl::UnresolvedUsingTypename:
50 case Decl::ClassTemplateSpecialization:
51 case Decl::ClassTemplatePartialSpecialization:
52 case Decl::VarTemplateSpecialization:
53 case Decl::VarTemplatePartialSpecialization:
54 case Decl::TemplateTypeParm:
55 case Decl::UnresolvedUsingValue:
56 case Decl::NonTypeTemplateParm:
57 case Decl::CXXDeductionGuide:
59 case Decl::CXXConstructor:
60 case Decl::CXXDestructor:
61 case Decl::CXXConversion:
63 case Decl::MSProperty:
64 case Decl::IndirectField:
66 case Decl::ObjCAtDefsField:
68 case Decl::ImplicitParam:
69 case Decl::ClassTemplate:
70 case Decl::VarTemplate:
71 case Decl::FunctionTemplate:
72 case Decl::TypeAliasTemplate:
73 case Decl::TemplateTemplateParm:
74 case Decl::ObjCMethod:
75 case Decl::ObjCCategory:
76 case Decl::ObjCProtocol:
77 case Decl::ObjCInterface:
78 case Decl::ObjCCategoryImpl:
79 case Decl::ObjCImplementation:
80 case Decl::ObjCProperty:
81 case Decl::ObjCCompatibleAlias:
82 case Decl::PragmaComment:
83 case Decl::PragmaDetectMismatch:
84 case Decl::AccessSpec:
85 case Decl::LinkageSpec:
87 case Decl::ObjCPropertyImpl:
88 case Decl::FileScopeAsm:
90 case Decl::FriendTemplate:
93 case Decl::ClassScopeFunctionSpecialization:
94 case Decl::UsingShadow:
95 case Decl::ConstructorUsingShadow:
96 case Decl::ObjCTypeParam:
98 llvm_unreachable(
"Declaration should not be in declstmts!");
102 case Decl::EnumConstant:
103 case Decl::CXXRecord:
104 case Decl::StaticAssert:
107 case Decl::OMPThreadPrivate:
108 case Decl::OMPAllocate:
109 case Decl::OMPCapturedExpr:
110 case Decl::OMPRequires:
113 case Decl::LifetimeExtendedTemporary:
114 case Decl::RequiresExprBody:
118 case Decl::NamespaceAlias:
120 DI->EmitNamespaceAlias(cast<NamespaceAliasDecl>(D));
124 DI->EmitUsingDecl(cast<UsingDecl>(D));
126 case Decl::UsingPack:
127 for (
auto *Using : cast<UsingPackDecl>(D).expansions())
130 case Decl::UsingDirective:
132 DI->EmitUsingDirective(cast<UsingDirectiveDecl>(D));
135 case Decl::Decomposition: {
136 const VarDecl &VD = cast<VarDecl>(D);
138 "Should not see file-scope variables inside a function!");
140 if (
auto *DD = dyn_cast<DecompositionDecl>(&VD))
141 for (
auto *B : DD->bindings())
142 if (
auto *HD = B->getHoldingVar())
147 case Decl::OMPDeclareReduction:
150 case Decl::OMPDeclareMapper:
154 case Decl::TypeAlias: {
158 if (Ty->isVariablyModifiedType())
181 llvm::GlobalValue::LinkageTypes
Linkage =
204 std::string ContextName;
206 if (
auto *CD = dyn_cast<CapturedDecl>(DC))
207 DC = cast<DeclContext>(CD->getNonClosureContext());
208 if (
const auto *FD = dyn_cast<FunctionDecl>(DC))
210 else if (
const auto *BD = dyn_cast<BlockDecl>(DC))
212 else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(DC))
213 ContextName = OMD->getSelector().getAsString();
215 llvm_unreachable(
"Unknown context for static var decl");
227 if (llvm::Constant *ExistingGV = StaticLocalDeclMap[&D])
235 if (D.hasAttr<AsmLabelAttr>())
236 Name = getMangledName(&D);
241 LangAS AS = GetGlobalVarAddressSpace(&D);
246 llvm::Constant *Init =
nullptr;
248 D.hasAttr<CUDASharedAttr>())
249 Init = llvm::UndefValue::get(LTy);
253 llvm::GlobalVariable *GV =
new llvm::GlobalVariable(
255 nullptr, llvm::GlobalVariable::NotThreadLocal, TargetAS);
258 if (supportsCOMDAT() && GV->isWeakForLinker())
259 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
264 setGVProperties(GV, &D);
268 llvm::Constant *Addr = GV;
269 if (AS != ExpectedAS) {
270 Addr = getTargetCodeGenInfo().performAddrSpaceCast(
271 *
this, GV, AS, ExpectedAS,
272 LTy->getPointerTo(
getContext().getTargetAddressSpace(ExpectedAS)));
275 setStaticLocalDeclAddress(&D, Addr);
279 const Decl *DC = cast<Decl>(D.getDeclContext());
283 if (isa<BlockDecl>(DC) || isa<CapturedDecl>(DC)) {
291 if (
const auto *CD = dyn_cast<CXXConstructorDecl>(DC))
293 else if (
const auto *DD = dyn_cast<CXXDestructorDecl>(DC))
295 else if (
const auto *FD = dyn_cast<FunctionDecl>(DC))
300 assert(isa<ObjCMethodDecl>(DC) &&
"unexpected parent code decl");
305 (void)GetAddrOfGlobal(GD);
315 llvm::GlobalVariable *
317 llvm::GlobalVariable *GV) {
329 GV->setConstant(
false);
340 if (GV->getType()->getElementType() != Init->getType()) {
341 llvm::GlobalVariable *OldGV = GV;
343 GV =
new llvm::GlobalVariable(
CGM.
getModule(), Init->getType(),
345 OldGV->getLinkage(), Init,
"",
347 OldGV->getThreadLocalMode(),
349 GV->setVisibility(OldGV->getVisibility());
350 GV->setDSOLocal(OldGV->isDSOLocal());
351 GV->setComdat(OldGV->getComdat());
357 llvm::Constant *NewPtrForOldDecl =
358 llvm::ConstantExpr::getBitCast(GV, OldGV->getType());
359 OldGV->replaceAllUsesWith(NewPtrForOldDecl);
362 OldGV->eraseFromParent();
366 GV->setInitializer(Init);
382 llvm::GlobalValue::LinkageTypes
Linkage) {
391 setAddrOfLocalVar(&D,
Address(addr, alignment));
402 llvm::GlobalVariable *var =
403 cast<llvm::GlobalVariable>(addr->stripPointerCasts());
412 if (D.
getInit() && !isCudaSharedVar)
420 if (
auto *SA = D.
getAttr<PragmaClangBSSSectionAttr>())
421 var->addAttribute(
"bss-section", SA->getName());
422 if (
auto *SA = D.
getAttr<PragmaClangDataSectionAttr>())
423 var->addAttribute(
"data-section", SA->getName());
424 if (
auto *SA = D.
getAttr<PragmaClangRodataSectionAttr>())
425 var->addAttribute(
"rodata-section", SA->getName());
426 if (
auto *SA = D.
getAttr<PragmaClangRelroSectionAttr>())
427 var->addAttribute(
"relro-section", SA->getName());
429 if (
const SectionAttr *SA = D.
getAttr<SectionAttr>())
430 var->setSection(SA->getName());
440 llvm::Constant *castedAddr =
441 llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(var, expectedType);
442 if (var != castedAddr)
443 LocalDeclMap.find(&D)->second =
Address(castedAddr, alignment);
460 bool useEHCleanupForArray)
461 : addr(addr),
type(type), destroyer(destroyer),
462 useEHCleanupForArray(useEHCleanupForArray) {}
467 bool useEHCleanupForArray;
471 bool useEHCleanupForArray =
472 flags.isForNormalCleanup() && this->useEHCleanupForArray;
474 CGF.
emitDestroy(addr, type, destroyer, useEHCleanupForArray);
478 template <
class Derived>
481 : NRVOFlag(NRVOFlag), Loc(addr), Ty(type) {}
489 bool NRVO = flags.isForNormalCleanup() && NRVOFlag;
491 llvm::BasicBlock *SkipDtorBB =
nullptr;
498 CGF.
Builder.CreateCondBr(DidNRVO, SkipDtorBB, RunDtorBB);
502 static_cast<Derived *
>(
this)->emitDestructorCall(CGF);
507 virtual ~DestroyNRVOVariable() =
default;
510 struct DestroyNRVOVariableCXX final
511 : DestroyNRVOVariable<DestroyNRVOVariableCXX> {
514 : DestroyNRVOVariable<DestroyNRVOVariableCXX>(addr,
type, NRVOFlag),
526 struct DestroyNRVOVariableC final
527 : DestroyNRVOVariable<DestroyNRVOVariableC> {
529 : DestroyNRVOVariable<DestroyNRVOVariableC>(addr, Ty, NRVOFlag) {}
538 CallStackRestore(
Address Stack) : Stack(Stack) {}
541 llvm::Function *F = CGF.
CGM.
getIntrinsic(llvm::Intrinsic::stackrestore);
548 ExtendGCLifetime(
const VarDecl *var) : Var(*var) {}
562 llvm::Constant *CleanupFn;
566 CallCleanupFunction(llvm::Constant *CleanupFn,
const CGFunctionInfo *Info,
568 : CleanupFn(CleanupFn), FnInfo(*Info), Var(*Var) {}
603 llvm_unreachable(
"present but none");
611 (var.
hasAttr<ObjCPreciseLifetimeAttr>()
635 if (
const Expr *e = dyn_cast<Expr>(s)) {
638 s = e = e->IgnoreParenCasts();
640 if (
const DeclRefExpr *ref = dyn_cast<DeclRefExpr>(e))
641 return (ref->getDecl() == &var);
642 if (
const BlockExpr *be = dyn_cast<BlockExpr>(e)) {
643 const BlockDecl *block = be->getBlockDecl();
644 for (
const auto &I : block->
captures()) {
645 if (I.getVariable() == &var)
660 if (!decl)
return false;
661 if (!isa<VarDecl>(decl))
return false;
668 bool needsCast =
false;
675 case CK_BlockPointerToObjCPointerCast:
681 case CK_LValueToRValue: {
724 if (!
SanOpts.
has(SanitizerKind::NullabilityAssign))
735 llvm::Constant *StaticData[] = {
737 llvm::ConstantInt::get(
Int8Ty, 0),
739 EmitCheck({{IsNotNull, SanitizerKind::NullabilityAssign}},
740 SanitizerHandler::TypeMismatch, StaticData, RHS);
744 LValue lvalue,
bool capturedByInit) {
756 init = DIE->getExpr();
760 if (
const FullExpr *fe = dyn_cast<FullExpr>(init)) {
762 init = fe->getSubExpr();
770 bool accessedByInit =
false;
772 accessedByInit = (capturedByInit ||
isAccessedBy(D, init));
773 if (accessedByInit) {
776 if (capturedByInit) {
802 llvm_unreachable(
"present but none");
805 if (!D || !isa<VarDecl>(D) || !cast<VarDecl>(D)->isARCPseudoStrong()) {
866 if (isa<llvm::ConstantAggregateZero>(Init) ||
867 isa<llvm::ConstantPointerNull>(Init) ||
868 isa<llvm::UndefValue>(Init))
870 if (isa<llvm::ConstantInt>(Init) || isa<llvm::ConstantFP>(Init) ||
871 isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) ||
872 isa<llvm::ConstantExpr>(Init))
873 return Init->isNullValue() || NumStores--;
876 if (isa<llvm::ConstantArray>(Init) || isa<llvm::ConstantStruct>(Init)) {
877 for (
unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) {
878 llvm::Constant *Elt = cast<llvm::Constant>(Init->getOperand(i));
885 if (llvm::ConstantDataSequential *CDS =
886 dyn_cast<llvm::ConstantDataSequential>(Init)) {
887 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
888 llvm::Constant *Elt = CDS->getElementAsConstant(i);
902 llvm::Constant *Init,
Address Loc,
904 assert(!Init->isNullValue() && !isa<llvm::UndefValue>(Init) &&
905 "called emitStoresForInitAfterBZero for zero or undef value.");
907 if (isa<llvm::ConstantInt>(Init) || isa<llvm::ConstantFP>(Init) ||
908 isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) ||
909 isa<llvm::ConstantExpr>(Init)) {
914 if (llvm::ConstantDataSequential *CDS =
915 dyn_cast<llvm::ConstantDataSequential>(Init)) {
916 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
917 llvm::Constant *Elt = CDS->getElementAsConstant(i);
920 if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt))
928 assert((isa<llvm::ConstantStruct>(Init) || isa<llvm::ConstantArray>(Init)) &&
929 "Unknown value type!");
931 for (
unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) {
932 llvm::Constant *Elt = cast<llvm::Constant>(Init->getOperand(i));
935 if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt))
946 uint64_t GlobalSize) {
948 if (isa<llvm::ConstantAggregateZero>(Init))
return true;
954 unsigned StoreBudget = 6;
955 uint64_t SizeLimit = 32;
957 return GlobalSize > SizeLimit &&
968 const llvm::DataLayout &DL) {
969 uint64_t SizeLimit = 32;
970 if (GlobalSize <= SizeLimit)
972 return llvm::isBytewiseValue(Init, DL);
979 uint64_t GlobalByteSize) {
981 uint64_t ByteSizeLimit = 64;
984 if (GlobalByteSize <= ByteSizeLimit)
997 return llvm::Constant::getNullValue(Ty);
1001 llvm::Constant *constant);
1006 llvm::StructType *STy,
1007 llvm::Constant *constant) {
1009 const llvm::StructLayout *Layout = DL.getStructLayout(STy);
1011 unsigned SizeSoFar = 0;
1013 bool NestedIntact =
true;
1014 for (
unsigned i = 0, e = STy->getNumElements(); i != e; i++) {
1015 unsigned CurOff = Layout->getElementOffset(i);
1016 if (SizeSoFar < CurOff) {
1017 assert(!STy->isPacked());
1018 auto *PadTy = llvm::ArrayType::get(Int8Ty, CurOff - SizeSoFar);
1021 llvm::Constant *CurOp;
1022 if (constant->isZeroValue())
1023 CurOp = llvm::Constant::getNullValue(STy->getElementType(i));
1025 CurOp = cast<llvm::Constant>(constant->getAggregateElement(i));
1028 NestedIntact =
false;
1029 Values.push_back(NewOp);
1030 SizeSoFar = CurOff + DL.getTypeAllocSize(CurOp->getType());
1032 unsigned TotalSize = Layout->getSizeInBytes();
1033 if (SizeSoFar < TotalSize) {
1034 auto *PadTy = llvm::ArrayType::get(Int8Ty, TotalSize - SizeSoFar);
1037 if (NestedIntact && Values.size() == STy->getNumElements())
1039 return llvm::ConstantStruct::getAnon(Values, STy->isPacked());
1045 llvm::Constant *constant) {
1047 if (
const auto STy = dyn_cast<llvm::StructType>(OrigTy))
1049 if (
auto *STy = dyn_cast<llvm::SequentialType>(OrigTy)) {
1051 unsigned Size = STy->getNumElements();
1055 bool ZeroInitializer = constant->isZeroValue();
1056 llvm::Constant *OpValue, *PaddedOp;
1057 if (ZeroInitializer) {
1058 OpValue = llvm::Constant::getNullValue(ElemTy);
1061 for (
unsigned Op = 0; Op != Size; ++Op) {
1062 if (!ZeroInitializer) {
1063 OpValue = constant->getAggregateElement(Op);
1066 Values.push_back(PaddedOp);
1068 auto *NewElemTy = Values[0]->getType();
1069 if (NewElemTy == ElemTy)
1071 if (OrigTy->isArrayTy()) {
1072 auto *ArrayTy = llvm::ArrayType::get(NewElemTy, Size);
1073 return llvm::ConstantArray::get(ArrayTy, Values);
1075 return llvm::ConstantVector::get(Values);
1082 llvm::Constant *Constant,
1084 auto FunctionName = [&](
const DeclContext *DC) -> std::string {
1085 if (
const auto *FD = dyn_cast<FunctionDecl>(DC)) {
1086 if (
const auto *CC = dyn_cast<CXXConstructorDecl>(FD))
1087 return CC->getNameAsString();
1088 if (
const auto *CD = dyn_cast<CXXDestructorDecl>(FD))
1089 return CD->getNameAsString();
1090 return getMangledName(FD);
1091 }
else if (
const auto *OM = dyn_cast<ObjCMethodDecl>(DC)) {
1092 return OM->getNameAsString();
1093 }
else if (isa<BlockDecl>(DC)) {
1095 }
else if (isa<CapturedDecl>(DC)) {
1096 return "<captured>";
1098 llvm_unreachable(
"expected a function or method");
1104 llvm::GlobalVariable *&CacheEntry = InitializerConstants[&D];
1105 if (!CacheEntry || CacheEntry->getInitializer() != Constant) {
1106 auto *Ty = Constant->getType();
1107 bool isConstant =
true;
1108 llvm::GlobalVariable *InsertBefore =
nullptr;
1113 Name = getMangledName(&D).str() +
".const";
1115 Name = (
"__const." + FunctionName(DC) +
"." + D.
getName()).str();
1117 llvm_unreachable(
"local variable has no parent function or method");
1118 llvm::GlobalVariable *GV =
new llvm::GlobalVariable(
1119 getModule(), Ty, isConstant, llvm::GlobalValue::PrivateLinkage,
1120 Constant, Name, InsertBefore, llvm::GlobalValue::NotThreadLocal, AS);
1122 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
1124 }
else if (CacheEntry->getAlignment() < Align.
getQuantity()) {
1125 CacheEntry->setAlignment(Align.
getAsAlign());
1128 return Address(CacheEntry, Align);
1134 llvm::Constant *Constant,
1147 llvm::Constant *constant) {
1148 auto *Ty = constant->getType();
1149 uint64_t ConstantSize = CGM.
getDataLayout().getTypeAllocSize(Ty);
1153 bool canDoSingleStore = Ty->isIntOrIntVectorTy() ||
1154 Ty->isPtrOrPtrVectorTy() || Ty->isFPOrFPVectorTy();
1155 if (canDoSingleStore) {
1160 auto *SizeVal = llvm::ConstantInt::get(CGM.
IntPtrTy, ConstantSize);
1168 bool valueAlreadyCorrect =
1169 constant->isNullValue() || isa<llvm::UndefValue>(constant);
1170 if (!valueAlreadyCorrect) {
1181 uint64_t
Value = 0x00;
1182 if (!isa<llvm::UndefValue>(Pattern)) {
1184 assert(AP.getBitWidth() <= 8);
1185 Value = AP.getLimitedValue();
1194 if (
auto *STy = dyn_cast<llvm::StructType>(Ty)) {
1197 for (
unsigned i = 0; i != constant->getNumOperands(); i++) {
1200 CGM, D, EltPtr, isVolatile, Builder,
1201 cast<llvm::Constant>(Builder.CreateExtractValue(constant, i)));
1205 }
else if (
auto *ATy = dyn_cast<llvm::ArrayType>(Ty)) {
1208 for (
unsigned i = 0; i != ATy->getNumElements(); i++) {
1211 CGM, D, EltPtr, isVolatile, Builder,
1212 cast<llvm::Constant>(Builder.CreateExtractValue(constant, i)));
1223 SizeVal, isVolatile);
1230 llvm::Constant *constant =
1241 assert(!isa<llvm::UndefValue>(constant));
1246 auto *Ty = constant->getType();
1247 if (isa<llvm::UndefValue>(constant))
1249 if (Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy())
1250 for (llvm::Use &Op : constant->operands())
1257 llvm::Constant *constant) {
1258 auto *Ty = constant->getType();
1259 if (isa<llvm::UndefValue>(constant))
1261 if (!(Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy()))
1266 for (
unsigned Op = 0, NumOp = constant->getNumOperands(); Op != NumOp; ++Op) {
1267 auto *OpValue = cast<llvm::Constant>(constant->getOperand(Op));
1270 if (Ty->isStructTy())
1271 return llvm::ConstantStruct::get(cast<llvm::StructType>(Ty), Values);
1272 if (Ty->isArrayTy())
1273 return llvm::ConstantArray::get(cast<llvm::ArrayType>(Ty), Values);
1274 assert(Ty->isVectorTy());
1275 return llvm::ConstantVector::get(Values);
1292 if (!ShouldEmitLifetimeMarkers)
1295 assert(Addr->getType()->getPointerAddressSpace() ==
1297 "Pointer should be in alloca address space");
1302 C->setDoesNotThrow();
1307 assert(Addr->getType()->getPointerAddressSpace() ==
1309 "Pointer should be in alloca address space");
1313 C->setDoesNotThrow();
1325 while (
getContext().getAsVariableArrayType(Type1D)) {
1327 if (
auto *C = dyn_cast<llvm::ConstantInt>(VlaSize.NumElts))
1331 Twine Name = Twine(
"__vla_expr") + Twine(VLAExprCounter++);
1333 StringRef NameRef = Name.toStringRef(Buffer);
1335 VLAExprNames.push_back(&Ident);
1339 Dimensions.emplace_back(SizeExprAddr.getPointer(),
1342 Type1D = VlaSize.Type;
1351 unsigned NameIdx = 0;
1352 for (
auto &VlaSize : Dimensions) {
1354 if (
auto *C = dyn_cast<llvm::ConstantInt>(VlaSize.NumElts))
1355 MD = llvm::ConstantAsMetadata::get(C);
1359 auto VlaExprTy = VlaSize.NumElts->getType()->getPointerElementType();
1361 VlaExprTy->getScalarSizeInBits(),
false);
1371 assert(MD &&
"No Size expression debug node created");
1388 emission.IsEscapingByRef = isEscapingByRef;
1408 address = OpenMPLocalAddr;
1437 assert(emission.wasEmittedAsGlobal());
1442 emission.IsConstantAggregate =
true;
1456 const auto *RD = RecordTy->getDecl();
1458 if ((CXXRD && !CXXRD->hasTrivialDestructor()) ||
1459 RD->isNonTrivialToPrimitiveDestroy()) {
1477 if (isEscapingByRef) {
1479 allocaTy = byrefInfo.Type;
1480 allocaAlignment = byrefInfo.ByrefAlignment;
1483 allocaAlignment = alignment;
1490 nullptr, &AllocaAddr);
1495 bool IsMSCatchParam =
1516 uint64_t size = CGM.
getDataLayout().getTypeAllocSize(allocaTy);
1517 emission.SizeForLifetimeMarkers =
1527 if (!DidCallStackSave) {
1532 llvm::Function *F = CGM.
getIntrinsic(llvm::Intrinsic::stacksave);
1536 DidCallStackSave =
true;
1556 setAddrOfLocalVar(&D, address);
1557 emission.Addr = address;
1558 emission.AllocaAddr = AllocaAddr;
1567 if (UsePointerValue)
1591 if (
const Expr *E = dyn_cast<Expr>(S))
1606 if (
const BlockExpr *BE = dyn_cast<BlockExpr>(E)) {
1607 const BlockDecl *Block = BE->getBlockDecl();
1608 for (
const auto &I : Block->
captures()) {
1609 if (I.getVariable() == &Var)
1617 if (
const StmtExpr *SE = dyn_cast<StmtExpr>(E)) {
1619 for (
const auto *BI : CS->
body())
1620 if (
const auto *BIE = dyn_cast<Expr>(BI)) {
1624 else if (
const auto *DS = dyn_cast<DeclStmt>(BI)) {
1626 for (
const auto *I : DS->decls()) {
1627 if (
const auto *VD = dyn_cast<VarDecl>((I))) {
1628 const Expr *Init = VD->getInit();
1656 if (Constructor->isTrivial() &&
1657 Constructor->isDefaultConstructor() &&
1658 !Construct->requiresZeroInitialization())
1664 void CodeGenFunction::emitZeroOrPatternForAutoVarInit(
QualType type,
1671 switch (trivialAutoVarInit) {
1673 llvm_unreachable(
"Uninitialized handled by caller");
1693 auto SizeVal = VlaSize.NumElts;
1695 switch (trivialAutoVarInit) {
1697 llvm_unreachable(
"Uninitialized handled by caller");
1700 if (!EltSize.
isOne())
1715 SizeVal, llvm::ConstantInt::get(SizeVal->getType(), 0),
1717 Builder.CreateCondBr(IsZeroSizedVLA, ContBB, SetupBB);
1719 if (!EltSize.
isOne())
1725 Builder.CreateInBoundsGEP(Begin.getPointer(), SizeVal,
"vla.end");
1726 llvm::BasicBlock *OriginBB =
Builder.GetInsertBlock();
1728 llvm::PHINode *Cur =
Builder.CreatePHI(Begin.getType(), 2,
"vla.cur");
1729 Cur->addIncoming(Begin.getPointer(), OriginBB);
1733 CGM, D,
Builder, Constant, ConstantAlign),
1734 BaseSizeInChars, isVolatile);
1736 Builder.CreateInBoundsGEP(
Int8Ty, Cur, BaseSizeInChars,
"vla.next");
1738 Builder.CreateCondBr(Done, ContBB, LoopBB);
1739 Cur->addIncoming(Next, LoopBB);
1746 assert(emission.Variable &&
"emission was not valid!");
1749 if (emission.wasEmittedAsGlobal())
return;
1751 const VarDecl &D = *emission.Variable;
1766 if (emission.IsEscapingByRef)
1773 type.isNonTrivialToPrimitiveDefaultInitialize() ==
1776 if (emission.IsEscapingByRef)
1785 bool capturedByInit =
1786 Init && emission.IsEscapingByRef &&
isCapturedBy(D, Init);
1788 bool locIsByrefHeader = !capturedByInit;
1796 : (D.
getAttr<UninitializedAttr>()
1800 auto initializeWhatIsTechnicallyUninitialized = [&](
Address Loc) {
1801 if (trivialAutoVarInit ==
1806 if (emission.IsEscapingByRef && !locIsByrefHeader)
1809 return emitZeroOrPatternForAutoVarInit(type, D, Loc);
1813 return initializeWhatIsTechnicallyUninitialized(Loc);
1815 llvm::Constant *constant =
nullptr;
1816 if (emission.IsConstantAggregate ||
1818 assert(!capturedByInit &&
"constant init contains a capturing block?");
1820 if (constant && !constant->isZeroValue() &&
1821 (trivialAutoVarInit !=
1839 initializeWhatIsTechnicallyUninitialized(Loc);
1845 if (!emission.IsConstantAggregate) {
1855 type.isVolatileQualified(),
Builder, constant);
1871 LValue lvalue,
bool capturedByInit) {
1897 if (isa<VarDecl>(D))
1899 else if (
auto *FD = dyn_cast<FieldDecl>(D))
1909 llvm_unreachable(
"bad evaluation kind");
1922 const VarDecl *var = emission.Variable;
1930 llvm_unreachable(
"no cleanup for trivially-destructible variable");
1935 if (emission.NRVOFlag) {
1938 EHStack.pushCleanup<DestroyNRVOVariableCXX>(cleanupKind, addr,
type, dtor,
1952 if (!var->
hasAttr<ObjCPreciseLifetimeAttr>())
1961 if (emission.NRVOFlag) {
1963 EHStack.pushCleanup<DestroyNRVOVariableC>(cleanupKind, addr,
1964 emission.NRVOFlag,
type);
1975 bool useEHCleanup = (cleanupKind &
EHCleanup);
1976 EHStack.pushCleanup<DestroyObject>(cleanupKind, addr,
type, destroyer,
1981 assert(emission.Variable &&
"emission was not valid!");
1984 if (emission.wasEmittedAsGlobal())
return;
1990 const VarDecl &D = *emission.Variable;
1998 D.
hasAttr<ObjCPreciseLifetimeAttr>()) {
2003 if (
const CleanupAttr *CA = D.
getAttr<CleanupAttr>()) {
2007 assert(F &&
"Could not find function!");
2016 if (emission.IsEscapingByRef &&
2040 llvm_unreachable(
"Unknown DestructionKind");
2047 assert(dtorKind &&
"cannot push destructor for trivial type");
2057 assert(dtorKind &&
"cannot push destructor for trivial type");
2066 bool useEHCleanupForArray) {
2067 pushFullExprCleanup<DestroyObject>(cleanupKind, addr,
type,
2068 destroyer, useEHCleanupForArray);
2072 EHStack.pushCleanup<CallStackRestore>(
Kind, SPMem);
2077 Destroyer *destroyer,
bool useEHCleanupForArray) {
2082 EHStack.pushCleanup<DestroyObject>(
2084 destroyer, useEHCleanupForArray);
2088 pushCleanupAfterFullExpr<DestroyObject>(
2089 cleanupKind, addr,
type, destroyer, useEHCleanupForArray);
2105 bool useEHCleanupForArray) {
2108 return destroyer(*
this, addr, type);
2117 bool checkZeroLength =
true;
2120 if (llvm::ConstantInt *constLength = dyn_cast<llvm::ConstantInt>(length)) {
2122 if (constLength->isZero())
return;
2123 checkZeroLength =
false;
2129 checkZeroLength, useEHCleanupForArray);
2147 bool checkZeroLength,
2148 bool useEHCleanup) {
2156 if (checkZeroLength) {
2158 "arraydestroy.isempty");
2159 Builder.CreateCondBr(isEmpty, doneBB, bodyBB);
2163 llvm::BasicBlock *entryBB =
Builder.GetInsertBlock();
2165 llvm::PHINode *elementPast =
2166 Builder.CreatePHI(begin->getType(), 2,
"arraydestroy.elementPast");
2167 elementPast->addIncoming(end, entryBB);
2172 "arraydestroy.element");
2179 destroyer(*
this,
Address(element, elementAlign), elementType);
2186 Builder.CreateCondBr(done, doneBB, bodyBB);
2187 elementPast->addIncoming(element,
Builder.GetInsertBlock());
2200 unsigned arrayDepth = 0;
2212 begin = CGF.
Builder.CreateInBoundsGEP(begin, gepIndices,
"pad.arraybegin");
2213 end = CGF.
Builder.CreateInBoundsGEP(end, gepIndices,
"pad.arrayend");
2237 : ArrayBegin(arrayBegin), ArrayEnd(arrayEnd),
2238 ElementType(elementType),
Destroyer(destroyer),
2239 ElementAlign(elementAlign) {}
2243 ElementType, ElementAlign, Destroyer);
2257 IrregularPartialArrayDestroy(
llvm::Value *arrayBegin,
2262 : ArrayBegin(arrayBegin), ArrayEndPointer(arrayEndPointer),
2263 ElementType(elementType),
Destroyer(destroyer),
2264 ElementAlign(elementAlign) {}
2269 ElementType, ElementAlign, Destroyer);
2285 pushFullExprCleanup<IrregularPartialArrayDestroy>(
EHCleanup,
2286 arrayBegin, arrayEndPointer,
2287 elementType, elementAlign,
2302 pushFullExprCleanup<RegularPartialArrayDestroy>(
EHCleanup,
2303 arrayBegin, arrayEnd,
2304 elementType, elementAlign,
2310 if (LifetimeStartFn)
2311 return LifetimeStartFn;
2312 LifetimeStartFn = llvm::Intrinsic::getDeclaration(&getModule(),
2314 return LifetimeStartFn;
2320 return LifetimeEndFn;
2321 LifetimeEndFn = llvm::Intrinsic::getDeclaration(&getModule(),
2323 return LifetimeEndFn;
2334 : Param(param), Precise(precise) {}
2350 assert((isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D)) &&
2351 "Invalid argument to EmitParmDecl");
2358 if (
auto IPD = dyn_cast<ImplicitParamDecl>(&D)) {
2371 bool DoStore =
false;
2377 unsigned AS = DeclPtr.
getType()->getAddressSpace();
2379 if (DeclPtr.
getType() != IRTy)
2388 if (SrcLangAS != DestLangAS) {
2389 assert(
getContext().getTargetAddressSpace(SrcLangAS) ==
2392 auto *T =
V->getType()->getPointerElementType()->getPointerTo(DestAS);
2394 *
this,
V, SrcLangAS, DestLangAS, T,
true),
2407 "unexpected destructor type");
2409 CalleeDestructedParamCleanups[cast<ParmVarDecl>(&D)] =
2420 DeclPtr = OpenMPLocalAddr;
2439 bool isConsumed = D.
hasAttr<NSConsumedAttr>();
2444 "pseudo-strong variable isn't strong?");
2445 assert(qs.
hasConst() &&
"pseudo-strong variable should be const!");
2494 setAddrOfLocalVar(&D, DeclPtr);
2503 if (D.
hasAttr<AnnotateAttr>())
2509 if (requiresReturnValueNullabilityCheck()) {
2513 RetValNullabilityPrecondition =
2514 Builder.CreateAnd(RetValNullabilityPrecondition,
2522 if (!LangOpts.OpenMP || (!LangOpts.EmitAllDecls && !D->
isUsed()))
2524 getOpenMPRuntime().emitUserDefinedReduction(CGF, D);
2529 if (!LangOpts.OpenMP || LangOpts.OpenMPSimd ||
2530 (!LangOpts.EmitAllDecls && !D->
isUsed()))
2532 getOpenMPRuntime().emitUserDefinedMapper(D, CGF);
2536 getOpenMPRuntime().checkArchForUnifiedAddressing(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.
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name="")
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...
bool mightBeUsableInConstantExpressions(ASTContext &C) const
Determine whether this variable's value might be usable in a constant expression, according to the re...
void setImplicit(bool I=true)
Represents a function declaration or definition.
void EmitStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
llvm::Value * EmitARCRetainAutoreleaseScalarExpr(const Expr *expr)
void EmitOMPDeclareMapper(const OMPDeclareMapperDecl *D, CodeGenFunction *CGF=nullptr)
Emit a code for declare mapper construct.
llvm::Constant * initializationPatternFor(CodeGenModule &, llvm::Type *)
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
llvm::Function * getLLVMLifetimeEndFn()
Lazily declare the .lifetime.end intrinsic.
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 either trap or call a handler function in the UBSan runtime with the p...
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.
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::Constant * constWithPadding(CodeGenModule &CGM, IsPattern isPattern, llvm::Constant *constant)
Replace all padding bytes in a given constant with either a pattern byte or 0x00. ...
static Destroyer destroyARCWeak
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>'.
AggValueSlot::Overlap_t getOverlapForFieldInit(const FieldDecl *FD)
Determine whether a field initialization may overlap some other object.
LangAS
Defines the address space values used by the address space qualifier of QualType. ...
static llvm::Value * shouldUseMemSetToInitialize(llvm::Constant *Init, uint64_t GlobalSize, const llvm::DataLayout &DL)
Decide whether we should use memset to initialize a local variable instead of using a memcpy from a c...
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating, Address This, QualType ThisTy)
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.
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.
QualType::DestructionKind needsDestruction(const ASTContext &Ctx) const
Would the destruction of this variable have any effect, and if so, what kind?
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
static llvm::Constant * constStructWithPadding(CodeGenModule &CGM, IsPattern isPattern, llvm::StructType *STy, llvm::Constant *constant)
Helper function for constWithPadding() to deal with padding in structures.
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
FullExpr - Represents a "full-expression" node.
llvm::IntegerType * SizeTy
static llvm::Constant * patternOrZeroFor(CodeGenModule &CGM, IsPattern isPattern, llvm::Type *Ty)
Generate a constant filled with either a pattern or zeroes.
bool Zero(InterpState &S, CodePtr OpPC)
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::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.
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
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)
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
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
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.
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.
static bool shouldSplitConstantStore(CodeGenModule &CGM, uint64_t GlobalByteSize)
Decide whether we want to split a constant structure or array store into a sequence of its fields' st...
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.
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
Represents 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.
static AggValueSlot forLValue(const LValue &LV, CodeGenFunction &CGF, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
void EmitARCMoveWeak(Address dst, Address src)
void @objc_moveWeak(i8** dest, i8** src) Disregards the current value in dest.
Address getOriginalAllocatedAddress() const
Returns the address for the original alloca instruction.
void EmitAutoVarInit(const AutoVarEmission &emission)
Address getAddress(CodeGenFunction &CGF) const
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...
const T * castAs() const
Member-template castAs<specific type>.
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)
llvm::Function * getLLVMLifetimeStartFn()
Lazily declare the .lifetime.start intrinsic.
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...
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.
static llvm::Constant * replaceUndef(CodeGenModule &CGM, IsPattern isPattern, llvm::Constant *constant)
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).
Address CreateConstInBoundsGEP2_32(Address Addr, unsigned Idx0, unsigned Idx1, const llvm::Twine &Name="")
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.
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.
llvm::Value * getPointer(CodeGenFunction &CGF) const
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:
Address CreateConstArrayGEP(Address Addr, uint64_t Index, const llvm::Twine &Name="")
Given addr = [n x T]* ...
llvm::Value * EmitLifetimeStart(uint64_t Size, llvm::Value *Addr)
Emit a lifetime.begin marker if some criteria are satisfied.
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)
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
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
Address createUnnamedGlobalFrom(const VarDecl &D, llvm::Constant *Constant, CharUnits Align)
static Address createUnnamedGlobalForMemcpyFrom(CodeGenModule &CGM, const VarDecl &D, CGBuilderTy &Builder, llvm::Constant *Constant, CharUnits Align)
llvm::DILocalVariable * EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI, CGBuilderTy &Builder, const bool UsePointerValue=false)
Emit call to llvm.dbg.declare for an automatic variable declaration.
Address ReturnValuePointer
ReturnValuePointer - The temporary alloca to hold a pointer to sret.
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.
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
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.
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)
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.
bool hasReducedDebugInfo() const
Check if type and variable info should be emitted.
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.
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.
This represents '#pragma omp declare mapper ...' directive.
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.
const VariableArrayType * getAsVariableArrayType(QualType T) const
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 Null(InterpState &S, CodePtr OpPC)
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.
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.
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
Skip past any parentheses which might surround this expression until reaching a fixed point...
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.