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::OMPAllocate:
108 case Decl::OMPCapturedExpr:
109 case Decl::OMPRequires:
115 case Decl::NamespaceAlias:
117 DI->EmitNamespaceAlias(cast<NamespaceAliasDecl>(D));
121 DI->EmitUsingDecl(cast<UsingDecl>(D));
123 case Decl::UsingPack:
124 for (
auto *Using : cast<UsingPackDecl>(D).expansions())
127 case Decl::UsingDirective:
129 DI->EmitUsingDirective(cast<UsingDirectiveDecl>(D));
132 case Decl::Decomposition: {
133 const VarDecl &VD = cast<VarDecl>(D);
135 "Should not see file-scope variables inside a function!");
137 if (
auto *DD = dyn_cast<DecompositionDecl>(&VD))
138 for (
auto *B : DD->bindings())
139 if (
auto *HD = B->getHoldingVar())
144 case Decl::OMPDeclareReduction:
147 case Decl::OMPDeclareMapper:
151 case Decl::TypeAlias: {
155 if (Ty->isVariablyModifiedType())
178 llvm::GlobalValue::LinkageTypes
Linkage =
201 std::string ContextName;
203 if (
auto *CD = dyn_cast<CapturedDecl>(DC))
204 DC = cast<DeclContext>(CD->getNonClosureContext());
205 if (
const auto *FD = dyn_cast<FunctionDecl>(DC))
207 else if (
const auto *BD = dyn_cast<BlockDecl>(DC))
209 else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(DC))
210 ContextName = OMD->getSelector().getAsString();
212 llvm_unreachable(
"Unknown context for static var decl");
224 if (llvm::Constant *ExistingGV = StaticLocalDeclMap[&D])
232 if (D.hasAttr<AsmLabelAttr>())
233 Name = getMangledName(&D);
238 LangAS AS = GetGlobalVarAddressSpace(&D);
243 llvm::Constant *Init =
nullptr;
245 D.hasAttr<CUDASharedAttr>())
246 Init = llvm::UndefValue::get(LTy);
250 llvm::GlobalVariable *GV =
new llvm::GlobalVariable(
252 nullptr, llvm::GlobalVariable::NotThreadLocal, TargetAS);
255 if (supportsCOMDAT() && GV->isWeakForLinker())
256 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
261 setGVProperties(GV, &D);
265 llvm::Constant *Addr = GV;
266 if (AS != ExpectedAS) {
267 Addr = getTargetCodeGenInfo().performAddrSpaceCast(
268 *
this, GV, AS, ExpectedAS,
269 LTy->getPointerTo(
getContext().getTargetAddressSpace(ExpectedAS)));
272 setStaticLocalDeclAddress(&D, Addr);
276 const Decl *DC = cast<Decl>(D.getDeclContext());
280 if (isa<BlockDecl>(DC) || isa<CapturedDecl>(DC)) {
288 if (
const auto *CD = dyn_cast<CXXConstructorDecl>(DC))
290 else if (
const auto *DD = dyn_cast<CXXDestructorDecl>(DC))
292 else if (
const auto *FD = dyn_cast<FunctionDecl>(DC))
297 assert(isa<ObjCMethodDecl>(DC) &&
"unexpected parent code decl");
302 (void)GetAddrOfGlobal(GD);
320 llvm::GlobalVariable *
322 llvm::GlobalVariable *GV) {
334 GV->setConstant(
false);
345 if (GV->getType()->getElementType() != Init->getType()) {
346 llvm::GlobalVariable *OldGV = GV;
348 GV =
new llvm::GlobalVariable(
CGM.
getModule(), Init->getType(),
350 OldGV->getLinkage(), Init,
"",
352 OldGV->getThreadLocalMode(),
354 GV->setVisibility(OldGV->getVisibility());
355 GV->setDSOLocal(OldGV->isDSOLocal());
356 GV->setComdat(OldGV->getComdat());
362 llvm::Constant *NewPtrForOldDecl =
363 llvm::ConstantExpr::getBitCast(GV, OldGV->getType());
364 OldGV->replaceAllUsesWith(NewPtrForOldDecl);
367 OldGV->eraseFromParent();
371 GV->setInitializer(Init);
386 llvm::GlobalValue::LinkageTypes
Linkage) {
395 setAddrOfLocalVar(&D,
Address(addr, alignment));
406 llvm::GlobalVariable *var =
407 cast<llvm::GlobalVariable>(addr->stripPointerCasts());
416 if (D.
getInit() && !isCudaSharedVar)
424 if (
auto *SA = D.
getAttr<PragmaClangBSSSectionAttr>())
425 var->addAttribute(
"bss-section", SA->getName());
426 if (
auto *SA = D.
getAttr<PragmaClangDataSectionAttr>())
427 var->addAttribute(
"data-section", SA->getName());
428 if (
auto *SA = D.
getAttr<PragmaClangRodataSectionAttr>())
429 var->addAttribute(
"rodata-section", SA->getName());
431 if (
const SectionAttr *SA = D.
getAttr<SectionAttr>())
432 var->setSection(SA->getName());
442 llvm::Constant *castedAddr =
443 llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(var, expectedType);
444 if (var != castedAddr)
445 LocalDeclMap.find(&D)->second =
Address(castedAddr, alignment);
463 bool useEHCleanupForArray)
464 : addr(addr),
type(type), destroyer(destroyer),
465 useEHCleanupForArray(useEHCleanupForArray) {}
470 bool useEHCleanupForArray;
474 bool useEHCleanupForArray =
475 flags.isForNormalCleanup() && this->useEHCleanupForArray;
477 CGF.
emitDestroy(addr, type, destroyer, useEHCleanupForArray);
481 template <
class Derived>
484 : NRVOFlag(NRVOFlag), Loc(addr), Ty(type) {}
492 bool NRVO = flags.isForNormalCleanup() && NRVOFlag;
494 llvm::BasicBlock *SkipDtorBB =
nullptr;
501 CGF.
Builder.CreateCondBr(DidNRVO, SkipDtorBB, RunDtorBB);
505 static_cast<Derived *
>(
this)->emitDestructorCall(CGF);
510 virtual ~DestroyNRVOVariable() =
default;
513 struct DestroyNRVOVariableCXX final
514 : DestroyNRVOVariable<DestroyNRVOVariableCXX> {
517 : DestroyNRVOVariable<DestroyNRVOVariableCXX>(addr,
type, NRVOFlag),
529 struct DestroyNRVOVariableC final
530 : DestroyNRVOVariable<DestroyNRVOVariableC> {
532 : DestroyNRVOVariable<DestroyNRVOVariableC>(addr, Ty, NRVOFlag) {}
541 CallStackRestore(
Address Stack) : Stack(Stack) {}
544 llvm::Function *F = CGF.
CGM.
getIntrinsic(llvm::Intrinsic::stackrestore);
551 ExtendGCLifetime(
const VarDecl *var) : Var(*var) {}
565 llvm::Constant *CleanupFn;
569 CallCleanupFunction(llvm::Constant *CleanupFn,
const CGFunctionInfo *Info,
571 : CleanupFn(CleanupFn), FnInfo(*Info), Var(*Var) {}
606 llvm_unreachable(
"present but none");
614 (var.
hasAttr<ObjCPreciseLifetimeAttr>()
638 if (
const Expr *e = dyn_cast<Expr>(s)) {
641 s = e = e->IgnoreParenCasts();
643 if (
const DeclRefExpr *ref = dyn_cast<DeclRefExpr>(e))
644 return (ref->getDecl() == &var);
645 if (
const BlockExpr *be = dyn_cast<BlockExpr>(e)) {
646 const BlockDecl *block = be->getBlockDecl();
647 for (
const auto &I : block->
captures()) {
648 if (I.getVariable() == &var)
663 if (!decl)
return false;
664 if (!isa<VarDecl>(decl))
return false;
671 bool needsCast =
false;
678 case CK_BlockPointerToObjCPointerCast:
684 case CK_LValueToRValue: {
727 if (!
SanOpts.
has(SanitizerKind::NullabilityAssign))
738 llvm::Constant *StaticData[] = {
740 llvm::ConstantInt::get(
Int8Ty, 0),
742 EmitCheck({{IsNotNull, SanitizerKind::NullabilityAssign}},
743 SanitizerHandler::TypeMismatch, StaticData, RHS);
747 LValue lvalue,
bool capturedByInit) {
759 init = DIE->getExpr();
763 if (
const FullExpr *fe = dyn_cast<FullExpr>(init)) {
765 init = fe->getSubExpr();
773 bool accessedByInit =
false;
775 accessedByInit = (capturedByInit ||
isAccessedBy(D, init));
776 if (accessedByInit) {
779 if (capturedByInit) {
804 llvm_unreachable(
"present but none");
807 if (!D || !isa<VarDecl>(D) || !cast<VarDecl>(D)->isARCPseudoStrong()) {
868 if (isa<llvm::ConstantAggregateZero>(Init) ||
869 isa<llvm::ConstantPointerNull>(Init) ||
870 isa<llvm::UndefValue>(Init))
872 if (isa<llvm::ConstantInt>(Init) || isa<llvm::ConstantFP>(Init) ||
873 isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) ||
874 isa<llvm::ConstantExpr>(Init))
875 return Init->isNullValue() || NumStores--;
878 if (isa<llvm::ConstantArray>(Init) || isa<llvm::ConstantStruct>(Init)) {
879 for (
unsigned i = 0, e = Init->getNumOperands();
i != e; ++
i) {
880 llvm::Constant *Elt = cast<llvm::Constant>(Init->getOperand(
i));
887 if (llvm::ConstantDataSequential *CDS =
888 dyn_cast<llvm::ConstantDataSequential>(Init)) {
889 for (
unsigned i = 0, e = CDS->getNumElements();
i != e; ++
i) {
890 llvm::Constant *Elt = CDS->getElementAsConstant(
i);
904 llvm::Constant *Init,
Address Loc,
906 assert(!Init->isNullValue() && !isa<llvm::UndefValue>(Init) &&
907 "called emitStoresForInitAfterBZero for zero or undef value.");
909 if (isa<llvm::ConstantInt>(Init) || isa<llvm::ConstantFP>(Init) ||
910 isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) ||
911 isa<llvm::ConstantExpr>(Init)) {
916 if (llvm::ConstantDataSequential *CDS =
917 dyn_cast<llvm::ConstantDataSequential>(Init)) {
918 for (
unsigned i = 0, e = CDS->getNumElements();
i != e; ++
i) {
919 llvm::Constant *Elt = CDS->getElementAsConstant(
i);
922 if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt))
930 assert((isa<llvm::ConstantStruct>(Init) || isa<llvm::ConstantArray>(Init)) &&
931 "Unknown value type!");
933 for (
unsigned i = 0, e = Init->getNumOperands();
i != e; ++
i) {
934 llvm::Constant *Elt = cast<llvm::Constant>(Init->getOperand(
i));
937 if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt))
948 uint64_t GlobalSize) {
950 if (isa<llvm::ConstantAggregateZero>(Init))
return true;
956 unsigned StoreBudget = 6;
957 uint64_t SizeLimit = 32;
959 return GlobalSize > SizeLimit &&
970 const llvm::DataLayout &DL) {
971 uint64_t SizeLimit = 32;
972 if (GlobalSize <= SizeLimit)
974 return llvm::isBytewiseValue(Init, DL);
981 uint64_t GlobalByteSize) {
983 uint64_t ByteSizeLimit = 64;
986 if (GlobalByteSize <= ByteSizeLimit)
999 return llvm::Constant::getNullValue(Ty);
1003 llvm::Constant *constant);
1008 llvm::StructType *STy,
1009 llvm::Constant *constant) {
1011 const llvm::StructLayout *Layout = DL.getStructLayout(STy);
1013 unsigned SizeSoFar = 0;
1015 bool NestedIntact =
true;
1016 for (
unsigned i = 0, e = STy->getNumElements();
i != e;
i++) {
1017 unsigned CurOff = Layout->getElementOffset(
i);
1018 if (SizeSoFar < CurOff) {
1019 assert(!STy->isPacked());
1020 auto *PadTy = llvm::ArrayType::get(Int8Ty, CurOff - SizeSoFar);
1023 llvm::Constant *CurOp;
1024 if (constant->isZeroValue())
1025 CurOp = llvm::Constant::getNullValue(STy->getElementType(
i));
1027 CurOp = cast<llvm::Constant>(constant->getAggregateElement(
i));
1030 NestedIntact =
false;
1031 Values.push_back(NewOp);
1032 SizeSoFar = CurOff + DL.getTypeAllocSize(CurOp->getType());
1034 unsigned TotalSize = Layout->getSizeInBytes();
1035 if (SizeSoFar < TotalSize) {
1036 auto *PadTy = llvm::ArrayType::get(Int8Ty, TotalSize - SizeSoFar);
1039 if (NestedIntact && Values.size() == STy->getNumElements())
1041 return llvm::ConstantStruct::getAnon(Values, STy->isPacked());
1047 llvm::Constant *constant) {
1049 if (
const auto STy = dyn_cast<llvm::StructType>(OrigTy))
1051 if (
auto *STy = dyn_cast<llvm::SequentialType>(OrigTy)) {
1053 unsigned Size = STy->getNumElements();
1057 bool ZeroInitializer = constant->isZeroValue();
1058 llvm::Constant *OpValue, *PaddedOp;
1059 if (ZeroInitializer) {
1060 OpValue = llvm::Constant::getNullValue(ElemTy);
1063 for (
unsigned Op = 0; Op != Size; ++Op) {
1064 if (!ZeroInitializer) {
1065 OpValue = constant->getAggregateElement(Op);
1068 Values.push_back(PaddedOp);
1070 auto *NewElemTy = Values[0]->getType();
1071 if (NewElemTy == ElemTy)
1073 if (OrigTy->isArrayTy()) {
1074 auto *ArrayTy = llvm::ArrayType::get(NewElemTy, Size);
1075 return llvm::ConstantArray::get(ArrayTy, Values);
1077 return llvm::ConstantVector::get(Values);
1084 llvm::Constant *Constant,
1086 auto FunctionName = [&](
const DeclContext *DC) -> std::string {
1087 if (
const auto *FD = dyn_cast<FunctionDecl>(DC)) {
1088 if (
const auto *CC = dyn_cast<CXXConstructorDecl>(FD))
1089 return CC->getNameAsString();
1090 if (
const auto *CD = dyn_cast<CXXDestructorDecl>(FD))
1091 return CD->getNameAsString();
1092 return getMangledName(FD);
1093 }
else if (
const auto *OM = dyn_cast<ObjCMethodDecl>(DC)) {
1094 return OM->getNameAsString();
1095 }
else if (isa<BlockDecl>(DC)) {
1097 }
else if (isa<CapturedDecl>(DC)) {
1098 return "<captured>";
1100 llvm_unreachable(
"expected a function or method");
1106 llvm::GlobalVariable *&CacheEntry = InitializerConstants[&D];
1107 if (!CacheEntry || CacheEntry->getInitializer() != Constant) {
1108 auto *Ty = Constant->getType();
1109 bool isConstant =
true;
1110 llvm::GlobalVariable *InsertBefore =
nullptr;
1115 Name = getMangledName(&D).str() +
".const";
1117 Name = (
"__const." + FunctionName(DC) +
"." + D.
getName()).str();
1119 llvm_unreachable(
"local variable has no parent function or method");
1120 llvm::GlobalVariable *GV =
new llvm::GlobalVariable(
1121 getModule(), Ty, isConstant, llvm::GlobalValue::PrivateLinkage,
1122 Constant, Name, InsertBefore, llvm::GlobalValue::NotThreadLocal, AS);
1124 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
1126 }
else if (CacheEntry->getAlignment() < Align.
getQuantity()) {
1130 return Address(CacheEntry, Align);
1136 llvm::Constant *Constant,
1149 llvm::Constant *constant) {
1150 auto *Ty = constant->getType();
1151 uint64_t ConstantSize = CGM.
getDataLayout().getTypeAllocSize(Ty);
1155 bool canDoSingleStore = Ty->isIntOrIntVectorTy() ||
1156 Ty->isPtrOrPtrVectorTy() || Ty->isFPOrFPVectorTy();
1157 if (canDoSingleStore) {
1162 auto *SizeVal = llvm::ConstantInt::get(CGM.
IntPtrTy, ConstantSize);
1170 bool valueAlreadyCorrect =
1171 constant->isNullValue() || isa<llvm::UndefValue>(constant);
1172 if (!valueAlreadyCorrect) {
1183 uint64_t
Value = 0x00;
1184 if (!isa<llvm::UndefValue>(Pattern)) {
1185 const llvm::APInt &AP = cast<llvm::ConstantInt>(Pattern)->
getValue();
1186 assert(AP.getBitWidth() <= 8);
1187 Value = AP.getLimitedValue();
1196 if (
auto *STy = dyn_cast<llvm::StructType>(Ty)) {
1199 for (
unsigned i = 0;
i != constant->getNumOperands();
i++) {
1202 CGM, D, EltPtr, isVolatile, Builder,
1203 cast<llvm::Constant>(Builder.CreateExtractValue(constant,
i)));
1207 }
else if (
auto *ATy = dyn_cast<llvm::ArrayType>(Ty)) {
1210 for (
unsigned i = 0;
i != ATy->getNumElements();
i++) {
1213 CGM, D, EltPtr, isVolatile, Builder,
1214 cast<llvm::Constant>(Builder.CreateExtractValue(constant,
i)));
1225 SizeVal, isVolatile);
1232 llvm::Constant *constant =
1243 assert(!isa<llvm::UndefValue>(constant));
1248 auto *Ty = constant->getType();
1249 if (isa<llvm::UndefValue>(constant))
1251 if (Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy())
1252 for (llvm::Use &Op : constant->operands())
1259 llvm::Constant *constant) {
1260 auto *Ty = constant->getType();
1261 if (isa<llvm::UndefValue>(constant))
1263 if (!(Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy()))
1268 for (
unsigned Op = 0, NumOp = constant->getNumOperands(); Op != NumOp; ++Op) {
1269 auto *OpValue = cast<llvm::Constant>(constant->getOperand(Op));
1272 if (Ty->isStructTy())
1273 return llvm::ConstantStruct::get(cast<llvm::StructType>(Ty), Values);
1274 if (Ty->isArrayTy())
1275 return llvm::ConstantArray::get(cast<llvm::ArrayType>(Ty), Values);
1276 assert(Ty->isVectorTy());
1277 return llvm::ConstantVector::get(Values);
1294 if (!ShouldEmitLifetimeMarkers)
1297 assert(Addr->getType()->getPointerAddressSpace() ==
1299 "Pointer should be in alloca address space");
1304 C->setDoesNotThrow();
1309 assert(Addr->getType()->getPointerAddressSpace() ==
1311 "Pointer should be in alloca address space");
1315 C->setDoesNotThrow();
1327 while (
getContext().getAsVariableArrayType(Type1D)) {
1329 if (
auto *C = dyn_cast<llvm::ConstantInt>(VlaSize.NumElts))
1333 Twine Name = Twine(
"__vla_expr") + Twine(VLAExprCounter++);
1335 StringRef NameRef = Name.toStringRef(Buffer);
1337 VLAExprNames.push_back(&Ident);
1341 Dimensions.emplace_back(SizeExprAddr.getPointer(),
1344 Type1D = VlaSize.Type;
1353 unsigned NameIdx = 0;
1354 for (
auto &VlaSize : Dimensions) {
1356 if (
auto *C = dyn_cast<llvm::ConstantInt>(VlaSize.NumElts))
1357 MD = llvm::ConstantAsMetadata::get(C);
1361 auto VlaExprTy = VlaSize.NumElts->getType()->getPointerElementType();
1363 VlaExprTy->getScalarSizeInBits(),
false);
1373 assert(MD &&
"No Size expression debug node created");
1390 emission.IsEscapingByRef = isEscapingByRef;
1399 bool EmitDebugInfo = DI && CGM.
getCodeGenOpts().getDebugInfo() >=
1411 address = OpenMPLocalAddr;
1440 assert(emission.wasEmittedAsGlobal());
1445 emission.IsConstantAggregate =
true;
1459 const auto *RD = RecordTy->getDecl();
1461 if ((CXXRD && !CXXRD->hasTrivialDestructor()) ||
1462 RD->isNonTrivialToPrimitiveDestroy()) {
1480 if (isEscapingByRef) {
1482 allocaTy = byrefInfo.Type;
1483 allocaAlignment = byrefInfo.ByrefAlignment;
1486 allocaAlignment = alignment;
1493 nullptr, &AllocaAddr);
1498 bool IsMSCatchParam =
1519 uint64_t size = CGM.
getDataLayout().getTypeAllocSize(allocaTy);
1520 emission.SizeForLifetimeMarkers =
1530 if (!DidCallStackSave) {
1535 llvm::Function *F = CGM.
getIntrinsic(llvm::Intrinsic::stacksave);
1539 DidCallStackSave =
true;
1559 setAddrOfLocalVar(&D, address);
1560 emission.Addr = address;
1561 emission.AllocaAddr = AllocaAddr;
1570 if (UsePointerValue)
1594 if (
const Expr *E = dyn_cast<Expr>(S))
1609 if (
const BlockExpr *BE = dyn_cast<BlockExpr>(E)) {
1610 const BlockDecl *Block = BE->getBlockDecl();
1611 for (
const auto &I : Block->
captures()) {
1612 if (I.getVariable() == &Var)
1620 if (
const StmtExpr *SE = dyn_cast<StmtExpr>(E)) {
1622 for (
const auto *BI : CS->
body())
1623 if (
const auto *BIE = dyn_cast<Expr>(BI)) {
1627 else if (
const auto *DS = dyn_cast<DeclStmt>(BI)) {
1629 for (
const auto *I : DS->decls()) {
1630 if (
const auto *VD = dyn_cast<VarDecl>((I))) {
1631 const Expr *Init = VD->getInit();
1659 if (Constructor->isTrivial() &&
1660 Constructor->isDefaultConstructor() &&
1661 !Construct->requiresZeroInitialization())
1667 void CodeGenFunction::emitZeroOrPatternForAutoVarInit(
QualType type,
1674 switch (trivialAutoVarInit) {
1676 llvm_unreachable(
"Uninitialized handled by caller");
1696 auto SizeVal = VlaSize.NumElts;
1698 switch (trivialAutoVarInit) {
1700 llvm_unreachable(
"Uninitialized handled by caller");
1703 if (!EltSize.
isOne())
1718 SizeVal, llvm::ConstantInt::get(SizeVal->getType(), 0),
1720 Builder.CreateCondBr(IsZeroSizedVLA, ContBB, SetupBB);
1722 if (!EltSize.
isOne())
1728 Builder.CreateInBoundsGEP(Begin.getPointer(), SizeVal,
"vla.end");
1729 llvm::BasicBlock *OriginBB =
Builder.GetInsertBlock();
1731 llvm::PHINode *Cur =
Builder.CreatePHI(Begin.getType(), 2,
"vla.cur");
1732 Cur->addIncoming(Begin.getPointer(), OriginBB);
1736 CGM, D,
Builder, Constant, ConstantAlign),
1737 BaseSizeInChars, isVolatile);
1739 Builder.CreateInBoundsGEP(
Int8Ty, Cur, BaseSizeInChars,
"vla.next");
1741 Builder.CreateCondBr(Done, ContBB, LoopBB);
1742 Cur->addIncoming(Next, LoopBB);
1749 assert(emission.Variable &&
"emission was not valid!");
1752 if (emission.wasEmittedAsGlobal())
return;
1754 const VarDecl &D = *emission.Variable;
1769 if (emission.IsEscapingByRef)
1776 type.isNonTrivialToPrimitiveDefaultInitialize() ==
1779 if (emission.IsEscapingByRef)
1788 bool capturedByInit =
1789 Init && emission.IsEscapingByRef &&
isCapturedBy(D, Init);
1791 bool locIsByrefHeader = !capturedByInit;
1799 : (D.
getAttr<UninitializedAttr>()
1803 auto initializeWhatIsTechnicallyUninitialized = [&](
Address Loc) {
1804 if (trivialAutoVarInit ==
1809 if (emission.IsEscapingByRef && !locIsByrefHeader)
1812 return emitZeroOrPatternForAutoVarInit(type, D, Loc);
1816 return initializeWhatIsTechnicallyUninitialized(Loc);
1818 llvm::Constant *constant =
nullptr;
1819 if (emission.IsConstantAggregate ||
1821 assert(!capturedByInit &&
"constant init contains a capturing block?");
1823 if (constant && !constant->isZeroValue() &&
1824 (trivialAutoVarInit !=
1842 initializeWhatIsTechnicallyUninitialized(Loc);
1848 if (!emission.IsConstantAggregate) {
1858 type.isVolatileQualified(),
Builder, constant);
1874 LValue lvalue,
bool capturedByInit) {
1900 if (isa<VarDecl>(D))
1902 else if (
auto *FD = dyn_cast<FieldDecl>(D))
1913 llvm_unreachable(
"bad evaluation kind");
1926 const VarDecl *var = emission.Variable;
1934 llvm_unreachable(
"no cleanup for trivially-destructible variable");
1939 if (emission.NRVOFlag) {
1942 EHStack.pushCleanup<DestroyNRVOVariableCXX>(cleanupKind, addr,
type, dtor,
1956 if (!var->
hasAttr<ObjCPreciseLifetimeAttr>())
1965 if (emission.NRVOFlag) {
1967 EHStack.pushCleanup<DestroyNRVOVariableC>(cleanupKind, addr,
1968 emission.NRVOFlag,
type);
1979 bool useEHCleanup = (cleanupKind &
EHCleanup);
1980 EHStack.pushCleanup<DestroyObject>(cleanupKind, addr,
type, destroyer,
1985 assert(emission.Variable &&
"emission was not valid!");
1988 if (emission.wasEmittedAsGlobal())
return;
1994 const VarDecl &D = *emission.Variable;
2002 D.
hasAttr<ObjCPreciseLifetimeAttr>()) {
2007 if (
const CleanupAttr *CA = D.
getAttr<CleanupAttr>()) {
2011 assert(F &&
"Could not find function!");
2020 if (emission.IsEscapingByRef &&
2044 llvm_unreachable(
"Unknown DestructionKind");
2051 assert(dtorKind &&
"cannot push destructor for trivial type");
2061 assert(dtorKind &&
"cannot push destructor for trivial type");
2070 bool useEHCleanupForArray) {
2071 pushFullExprCleanup<DestroyObject>(cleanupKind, addr,
type,
2072 destroyer, useEHCleanupForArray);
2076 EHStack.pushCleanup<CallStackRestore>(
Kind, SPMem);
2081 Destroyer *destroyer,
bool useEHCleanupForArray) {
2086 EHStack.pushCleanup<DestroyObject>(
2088 destroyer, useEHCleanupForArray);
2092 pushCleanupAfterFullExpr<DestroyObject>(
2093 cleanupKind, addr,
type, destroyer, useEHCleanupForArray);
2109 bool useEHCleanupForArray) {
2112 return destroyer(*
this, addr, type);
2121 bool checkZeroLength =
true;
2124 if (llvm::ConstantInt *constLength = dyn_cast<llvm::ConstantInt>(length)) {
2126 if (constLength->isZero())
return;
2127 checkZeroLength =
false;
2133 checkZeroLength, useEHCleanupForArray);
2151 bool checkZeroLength,
2152 bool useEHCleanup) {
2160 if (checkZeroLength) {
2162 "arraydestroy.isempty");
2163 Builder.CreateCondBr(isEmpty, doneBB, bodyBB);
2167 llvm::BasicBlock *entryBB =
Builder.GetInsertBlock();
2169 llvm::PHINode *elementPast =
2170 Builder.CreatePHI(begin->getType(), 2,
"arraydestroy.elementPast");
2171 elementPast->addIncoming(end, entryBB);
2176 "arraydestroy.element");
2183 destroyer(*
this,
Address(element, elementAlign), elementType);
2190 Builder.CreateCondBr(done, doneBB, bodyBB);
2191 elementPast->addIncoming(element,
Builder.GetInsertBlock());
2204 unsigned arrayDepth = 0;
2216 begin = CGF.
Builder.CreateInBoundsGEP(begin, gepIndices,
"pad.arraybegin");
2217 end = CGF.
Builder.CreateInBoundsGEP(end, gepIndices,
"pad.arrayend");
2241 : ArrayBegin(arrayBegin), ArrayEnd(arrayEnd),
2242 ElementType(elementType),
Destroyer(destroyer),
2243 ElementAlign(elementAlign) {}
2247 ElementType, ElementAlign, Destroyer);
2261 IrregularPartialArrayDestroy(
llvm::Value *arrayBegin,
2266 : ArrayBegin(arrayBegin), ArrayEndPointer(arrayEndPointer),
2267 ElementType(elementType),
Destroyer(destroyer),
2268 ElementAlign(elementAlign) {}
2273 ElementType, ElementAlign, Destroyer);
2289 pushFullExprCleanup<IrregularPartialArrayDestroy>(
EHCleanup,
2290 arrayBegin, arrayEndPointer,
2291 elementType, elementAlign,
2306 pushFullExprCleanup<RegularPartialArrayDestroy>(
EHCleanup,
2307 arrayBegin, arrayEnd,
2308 elementType, elementAlign,
2314 if (LifetimeStartFn)
2315 return LifetimeStartFn;
2316 LifetimeStartFn = llvm::Intrinsic::getDeclaration(&getModule(),
2318 return LifetimeStartFn;
2324 return LifetimeEndFn;
2325 LifetimeEndFn = llvm::Intrinsic::getDeclaration(&getModule(),
2327 return LifetimeEndFn;
2338 : Param(param), Precise(precise) {}
2354 assert((isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D)) &&
2355 "Invalid argument to EmitParmDecl");
2362 if (
auto IPD = dyn_cast<ImplicitParamDecl>(&D)) {
2375 bool DoStore =
false;
2381 unsigned AS = DeclPtr.
getType()->getAddressSpace();
2383 if (DeclPtr.
getType() != IRTy)
2392 if (SrcLangAS != DestLangAS) {
2393 assert(
getContext().getTargetAddressSpace(SrcLangAS) ==
2396 auto *T =
V->getType()->getPointerElementType()->getPointerTo(DestAS);
2398 *
this,
V, SrcLangAS, DestLangAS, T,
true),
2410 "unexpected destructor type");
2412 CalleeDestructedParamCleanups[cast<ParmVarDecl>(&D)] =
2423 DeclPtr = OpenMPLocalAddr;
2442 bool isConsumed = D.
hasAttr<NSConsumedAttr>();
2447 "pseudo-strong variable isn't strong?");
2448 assert(qs.
hasConst() &&
"pseudo-strong variable should be const!");
2497 setAddrOfLocalVar(&D, DeclPtr);
2507 if (D.
hasAttr<AnnotateAttr>())
2513 if (requiresReturnValueNullabilityCheck()) {
2517 RetValNullabilityPrecondition =
2518 Builder.CreateAnd(RetValNullabilityPrecondition,
2526 if (!LangOpts.OpenMP || (!LangOpts.EmitAllDecls && !D->
isUsed()))
2528 getOpenMPRuntime().emitUserDefinedReduction(CGF, D);
2533 if (!LangOpts.OpenMP || (!LangOpts.EmitAllDecls && !D->
isUsed()))
2539 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.
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
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.
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.
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.
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.
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.
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)
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...
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.
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.
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.
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after...
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)
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.
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 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.
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
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.