35#include "llvm/Analysis/ValueTracking.h"
36#include "llvm/IR/DataLayout.h"
37#include "llvm/IR/GlobalVariable.h"
38#include "llvm/IR/Intrinsics.h"
39#include "llvm/IR/Type.h"
43using namespace CodeGen;
46 "Clang max alignment greater than what LLVM supports?");
48void CodeGenFunction::EmitDecl(
const Decl &D) {
50 case Decl::BuiltinTemplate:
51 case Decl::TranslationUnit:
52 case Decl::ExternCContext:
54 case Decl::UnresolvedUsingTypename:
55 case Decl::ClassTemplateSpecialization:
56 case Decl::ClassTemplatePartialSpecialization:
57 case Decl::VarTemplateSpecialization:
58 case Decl::VarTemplatePartialSpecialization:
59 case Decl::TemplateTypeParm:
60 case Decl::UnresolvedUsingValue:
61 case Decl::NonTypeTemplateParm:
62 case Decl::CXXDeductionGuide:
64 case Decl::CXXConstructor:
65 case Decl::CXXDestructor:
66 case Decl::CXXConversion:
68 case Decl::MSProperty:
69 case Decl::IndirectField:
71 case Decl::ObjCAtDefsField:
73 case Decl::ImplicitParam:
74 case Decl::ClassTemplate:
75 case Decl::VarTemplate:
76 case Decl::FunctionTemplate:
77 case Decl::TypeAliasTemplate:
78 case Decl::TemplateTemplateParm:
79 case Decl::ObjCMethod:
80 case Decl::ObjCCategory:
81 case Decl::ObjCProtocol:
82 case Decl::ObjCInterface:
83 case Decl::ObjCCategoryImpl:
84 case Decl::ObjCImplementation:
85 case Decl::ObjCProperty:
86 case Decl::ObjCCompatibleAlias:
87 case Decl::PragmaComment:
88 case Decl::PragmaDetectMismatch:
89 case Decl::AccessSpec:
90 case Decl::LinkageSpec:
92 case Decl::ObjCPropertyImpl:
93 case Decl::FileScopeAsm:
94 case Decl::TopLevelStmt:
96 case Decl::FriendTemplate:
99 case Decl::ClassScopeFunctionSpecialization:
100 case Decl::UsingShadow:
101 case Decl::ConstructorUsingShadow:
102 case Decl::ObjCTypeParam:
104 case Decl::UnresolvedUsingIfExists:
105 case Decl::HLSLBuffer:
106 llvm_unreachable(
"Declaration should not be in declstmts!");
108 case Decl::CXXRecord:
116 DI->EmitAndRetainType(
getContext().getEnumType(cast<EnumDecl>(&D)));
119 case Decl::EnumConstant:
120 case Decl::StaticAssert:
124 case Decl::UnnamedGlobalConstant:
125 case Decl::TemplateParamObject:
126 case Decl::OMPThreadPrivate:
127 case Decl::OMPAllocate:
128 case Decl::OMPCapturedExpr:
129 case Decl::OMPRequires:
132 case Decl::ImplicitConceptSpecialization:
133 case Decl::LifetimeExtendedTemporary:
134 case Decl::RequiresExprBody:
138 case Decl::NamespaceAlias:
140 DI->EmitNamespaceAlias(cast<NamespaceAliasDecl>(D));
144 DI->EmitUsingDecl(cast<UsingDecl>(D));
146 case Decl::UsingEnum:
148 DI->EmitUsingEnumDecl(cast<UsingEnumDecl>(D));
150 case Decl::UsingPack:
151 for (
auto *Using : cast<UsingPackDecl>(D).expansions())
154 case Decl::UsingDirective:
156 DI->EmitUsingDirective(cast<UsingDirectiveDecl>(D));
159 case Decl::Decomposition: {
160 const VarDecl &VD = cast<VarDecl>(D);
162 "Should not see file-scope variables inside a function!");
164 if (
auto *DD = dyn_cast<DecompositionDecl>(&VD))
165 for (
auto *B : DD->bindings())
166 if (
auto *HD = B->getHoldingVar())
171 case Decl::OMPDeclareReduction:
174 case Decl::OMPDeclareMapper:
178 case Decl::TypeAlias: {
179 QualType Ty = cast<TypedefNameDecl>(D).getUnderlyingType();
181 DI->EmitAndRetainType(Ty);
204 llvm::GlobalValue::LinkageTypes
Linkage =
227 std::string ContextName;
229 if (
auto *CD = dyn_cast<CapturedDecl>(DC))
230 DC = cast<DeclContext>(CD->getNonClosureContext());
231 if (
const auto *FD = dyn_cast<FunctionDecl>(DC))
233 else if (
const auto *BD = dyn_cast<BlockDecl>(DC))
235 else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(DC))
236 ContextName = OMD->getSelector().getAsString();
238 llvm_unreachable(
"Unknown context for static var decl");
250 if (llvm::Constant *ExistingGV = StaticLocalDeclMap[&D])
269 llvm::Constant *Init =
nullptr;
271 D.
hasAttr<CUDASharedAttr>() || D.
hasAttr<LoaderUninitializedAttr>())
272 Init = llvm::UndefValue::get(LTy);
276 llvm::GlobalVariable *GV =
new llvm::GlobalVariable(
278 nullptr, llvm::GlobalVariable::NotThreadLocal, TargetAS);
279 GV->setAlignment(
getContext().getDeclAlign(&D).getAsAlign());
282 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
291 llvm::Constant *Addr = GV;
292 if (AS != ExpectedAS) {
294 *
this, GV, AS, ExpectedAS,
295 LTy->getPointerTo(
getContext().getTargetAddressSpace(ExpectedAS)));
306 if (isa<BlockDecl>(DC) || isa<CapturedDecl>(DC)) {
314 if (
const auto *CD = dyn_cast<CXXConstructorDecl>(DC))
316 else if (
const auto *DD = dyn_cast<CXXDestructorDecl>(DC))
318 else if (
const auto *FD = dyn_cast<FunctionDecl>(DC))
323 assert(isa<ObjCMethodDecl>(DC) &&
"unexpected parent code decl");
338llvm::GlobalVariable *
340 llvm::GlobalVariable *GV) {
342 llvm::Constant *Init = emitter.tryEmitForInitializer(D);
354 GV->setConstant(
false);
366 assert(VarSize == CstSize &&
"Emitted constant has unexpected size");
373 if (GV->getValueType() != Init->getType()) {
374 llvm::GlobalVariable *OldGV = GV;
376 GV =
new llvm::GlobalVariable(
378 OldGV->getLinkage(), Init,
"",
379 OldGV, OldGV->getThreadLocalMode(),
380 OldGV->getType()->getPointerAddressSpace());
381 GV->setVisibility(OldGV->getVisibility());
382 GV->setDSOLocal(OldGV->isDSOLocal());
383 GV->setComdat(OldGV->getComdat());
389 llvm::Constant *NewPtrForOldDecl =
390 llvm::ConstantExpr::getBitCast(GV, OldGV->getType());
391 OldGV->replaceAllUsesWith(NewPtrForOldDecl);
394 OldGV->eraseFromParent();
401 GV->setInitializer(Init);
403 emitter.finalize(GV);
416 llvm::GlobalValue::LinkageTypes
Linkage) {
426 setAddrOfLocalVar(&D,
Address(addr, elemTy, alignment));
435 llvm::Type *expectedType = addr->getType();
437 llvm::GlobalVariable *var =
438 cast<llvm::GlobalVariable>(addr->stripPointerCasts());
447 if (D.
getInit() && !isCudaSharedVar)
455 if (
auto *SA = D.
getAttr<PragmaClangBSSSectionAttr>())
456 var->addAttribute(
"bss-section", SA->getName());
457 if (
auto *SA = D.
getAttr<PragmaClangDataSectionAttr>())
458 var->addAttribute(
"data-section", SA->getName());
459 if (
auto *SA = D.
getAttr<PragmaClangRodataSectionAttr>())
460 var->addAttribute(
"rodata-section", SA->getName());
461 if (
auto *SA = D.
getAttr<PragmaClangRelroSectionAttr>())
462 var->addAttribute(
"relro-section", SA->getName());
464 if (
const SectionAttr *SA = D.
getAttr<SectionAttr>())
465 var->setSection(SA->getName());
469 else if (D.
hasAttr<UsedAttr>())
477 llvm::Constant *castedAddr =
478 llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(var, expectedType);
479 LocalDeclMap.find(&D)->second =
Address(castedAddr, elemTy, alignment);
495 CodeGenFunction::Destroyer *destroyer,
496 bool useEHCleanupForArray)
497 : addr(addr),
type(
type), destroyer(destroyer),
498 useEHCleanupForArray(useEHCleanupForArray) {}
502 CodeGenFunction::Destroyer *destroyer;
503 bool useEHCleanupForArray;
507 bool useEHCleanupForArray =
508 flags.isForNormalCleanup() && this->useEHCleanupForArray;
514 template <
class Derived>
517 : NRVOFlag(NRVOFlag), Loc(addr), Ty(
type) {}
519 llvm::Value *NRVOFlag;
525 bool NRVO = flags.isForNormalCleanup() && NRVOFlag;
527 llvm::BasicBlock *SkipDtorBB =
nullptr;
532 llvm::Value *DidNRVO =
534 CGF.
Builder.CreateCondBr(DidNRVO, SkipDtorBB, RunDtorBB);
538 static_cast<Derived *
>(
this)->emitDestructorCall(CGF);
543 virtual ~DestroyNRVOVariable() =
default;
546 struct DestroyNRVOVariableCXX final
547 : DestroyNRVOVariable<DestroyNRVOVariableCXX> {
550 : DestroyNRVOVariable<DestroyNRVOVariableCXX>(addr,
type, NRVOFlag),
562 struct DestroyNRVOVariableC final
563 : DestroyNRVOVariable<DestroyNRVOVariableC> {
565 : DestroyNRVOVariable<DestroyNRVOVariableC>(addr, Ty, NRVOFlag) {}
574 CallStackRestore(
Address Stack) : Stack(Stack) {}
575 bool isRedundantBeforeReturn()
override {
return true; }
578 llvm::Function *F = CGF.
CGM.
getIntrinsic(llvm::Intrinsic::stackrestore);
585 ExtendGCLifetime(
const VarDecl *var) : Var(*var) {}
599 llvm::Constant *CleanupFn;
603 CallCleanupFunction(llvm::Constant *CleanupFn,
const CGFunctionInfo *Info,
605 : CleanupFn(CleanupFn), FnInfo(*Info), Var(*Var) {}
640 llvm_unreachable(
"present but none");
648 (var.
hasAttr<ObjCPreciseLifetimeAttr>()
672 if (
const Expr *e = dyn_cast<Expr>(
s)) {
675 s = e = e->IgnoreParenCasts();
677 if (
const DeclRefExpr *ref = dyn_cast<DeclRefExpr>(e))
678 return (ref->getDecl() == &var);
679 if (
const BlockExpr *be = dyn_cast<BlockExpr>(e)) {
680 const BlockDecl *block = be->getBlockDecl();
681 for (
const auto &I : block->
captures()) {
682 if (I.getVariable() == &var)
688 for (
const Stmt *SubStmt :
s->children())
697 if (!
decl)
return false;
698 if (!isa<VarDecl>(
decl))
return false;
705 bool needsCast =
false;
712 case CK_BlockPointerToObjCPointerCast:
718 case CK_LValueToRValue: {
761 if (!
SanOpts.
has(SanitizerKind::NullabilityAssign))
770 SanitizerScope SanScope(
this);
772 llvm::Constant *StaticData[] = {
774 llvm::ConstantInt::get(
Int8Ty, 0),
777 SanitizerHandler::TypeMismatch, StaticData, RHS);
781 LValue lvalue,
bool capturedByInit) {
793 init = DIE->getExpr();
797 if (
auto *EWC = dyn_cast<ExprWithCleanups>(init)) {
798 CodeGenFunction::RunCleanupsScope
Scope(*
this);
799 return EmitScalarInit(EWC->getSubExpr(), D, lvalue, capturedByInit);
806 bool accessedByInit =
false;
808 accessedByInit = (capturedByInit ||
isAccessedBy(D, init));
809 if (accessedByInit) {
812 if (capturedByInit) {
834 llvm::Value *value =
nullptr;
838 llvm_unreachable(
"present but none");
841 if (!D || !isa<VarDecl>(D) || !cast<VarDecl>(D)->isARCPseudoStrong()) {
900 unsigned &NumStores) {
902 if (isa<llvm::ConstantAggregateZero>(Init) ||
903 isa<llvm::ConstantPointerNull>(Init) ||
904 isa<llvm::UndefValue>(Init))
906 if (isa<llvm::ConstantInt>(Init) || isa<llvm::ConstantFP>(Init) ||
907 isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) ||
908 isa<llvm::ConstantExpr>(Init))
909 return Init->isNullValue() || NumStores--;
912 if (isa<llvm::ConstantArray>(Init) || isa<llvm::ConstantStruct>(Init)) {
913 for (
unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) {
914 llvm::Constant *Elt = cast<llvm::Constant>(Init->getOperand(i));
921 if (llvm::ConstantDataSequential *CDS =
922 dyn_cast<llvm::ConstantDataSequential>(Init)) {
923 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
924 llvm::Constant *Elt = CDS->getElementAsConstant(i);
938 llvm::Constant *Init,
Address Loc,
941 assert(!Init->isNullValue() && !isa<llvm::UndefValue>(Init) &&
942 "called emitStoresForInitAfterBZero for zero or undef value.");
944 if (isa<llvm::ConstantInt>(Init) || isa<llvm::ConstantFP>(Init) ||
945 isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) ||
946 isa<llvm::ConstantExpr>(Init)) {
947 auto *I = Builder.CreateStore(Init, Loc, isVolatile);
949 I->addAnnotationMetadata(
"auto-init");
953 if (llvm::ConstantDataSequential *CDS =
954 dyn_cast<llvm::ConstantDataSequential>(Init)) {
955 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
956 llvm::Constant *Elt = CDS->getElementAsConstant(i);
959 if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt))
961 CGM, Elt, Builder.CreateConstInBoundsGEP2_32(Loc, 0, i), isVolatile,
962 Builder, IsAutoInit);
967 assert((isa<llvm::ConstantStruct>(Init) || isa<llvm::ConstantArray>(Init)) &&
968 "Unknown value type!");
970 for (
unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) {
971 llvm::Constant *Elt = cast<llvm::Constant>(Init->getOperand(i));
974 if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt))
976 Builder.CreateConstInBoundsGEP2_32(Loc, 0, i),
977 isVolatile, Builder, IsAutoInit);
985 uint64_t GlobalSize) {
987 if (isa<llvm::ConstantAggregateZero>(Init))
return true;
993 unsigned StoreBudget = 6;
994 uint64_t SizeLimit = 32;
996 return GlobalSize > SizeLimit &&
1006 uint64_t GlobalSize,
1007 const llvm::DataLayout &DL) {
1008 uint64_t SizeLimit = 32;
1009 if (GlobalSize <= SizeLimit)
1011 return llvm::isBytewiseValue(Init, DL);
1018 uint64_t GlobalByteSize) {
1020 uint64_t ByteSizeLimit = 64;
1023 if (GlobalByteSize <= ByteSizeLimit)
1033 if (isPattern == IsPattern::Yes)
1036 return llvm::Constant::getNullValue(Ty);
1040 llvm::Constant *constant);
1045 llvm::StructType *STy,
1046 llvm::Constant *constant) {
1048 const llvm::StructLayout *Layout = DL.getStructLayout(STy);
1049 llvm::Type *Int8Ty = llvm::IntegerType::getInt8Ty(CGM.
getLLVMContext());
1050 unsigned SizeSoFar = 0;
1052 bool NestedIntact =
true;
1053 for (
unsigned i = 0, e = STy->getNumElements(); i != e; i++) {
1054 unsigned CurOff = Layout->getElementOffset(i);
1055 if (SizeSoFar < CurOff) {
1056 assert(!STy->isPacked());
1057 auto *PadTy = llvm::ArrayType::get(Int8Ty, CurOff - SizeSoFar);
1060 llvm::Constant *CurOp;
1061 if (constant->isZeroValue())
1062 CurOp = llvm::Constant::getNullValue(STy->getElementType(i));
1064 CurOp = cast<llvm::Constant>(constant->getAggregateElement(i));
1067 NestedIntact =
false;
1068 Values.push_back(NewOp);
1069 SizeSoFar = CurOff + DL.getTypeAllocSize(CurOp->getType());
1071 unsigned TotalSize = Layout->getSizeInBytes();
1072 if (SizeSoFar < TotalSize) {
1073 auto *PadTy = llvm::ArrayType::get(Int8Ty, TotalSize - SizeSoFar);
1076 if (NestedIntact && Values.size() == STy->getNumElements())
1078 return llvm::ConstantStruct::getAnon(Values, STy->isPacked());
1084 llvm::Constant *constant) {
1085 llvm::Type *OrigTy = constant->getType();
1086 if (
const auto STy = dyn_cast<llvm::StructType>(OrigTy))
1088 if (
auto *ArrayTy = dyn_cast<llvm::ArrayType>(OrigTy)) {
1090 uint64_t Size = ArrayTy->getNumElements();
1093 llvm::Type *ElemTy = ArrayTy->getElementType();
1094 bool ZeroInitializer = constant->isNullValue();
1095 llvm::Constant *OpValue, *PaddedOp;
1096 if (ZeroInitializer) {
1097 OpValue = llvm::Constant::getNullValue(ElemTy);
1100 for (
unsigned Op = 0; Op != Size; ++Op) {
1101 if (!ZeroInitializer) {
1102 OpValue = constant->getAggregateElement(Op);
1105 Values.push_back(PaddedOp);
1107 auto *NewElemTy = Values[0]->getType();
1108 if (NewElemTy == ElemTy)
1110 auto *NewArrayTy = llvm::ArrayType::get(NewElemTy, Size);
1111 return llvm::ConstantArray::get(NewArrayTy, Values);
1120 llvm::Constant *Constant,
1122 auto FunctionName = [&](
const DeclContext *DC) -> std::string {
1123 if (
const auto *FD = dyn_cast<FunctionDecl>(DC)) {
1124 if (
const auto *CC = dyn_cast<CXXConstructorDecl>(FD))
1125 return CC->getNameAsString();
1126 if (
const auto *CD = dyn_cast<CXXDestructorDecl>(FD))
1127 return CD->getNameAsString();
1129 }
else if (
const auto *OM = dyn_cast<ObjCMethodDecl>(DC)) {
1130 return OM->getNameAsString();
1131 }
else if (isa<BlockDecl>(DC)) {
1133 }
else if (isa<CapturedDecl>(DC)) {
1134 return "<captured>";
1136 llvm_unreachable(
"expected a function or method");
1142 llvm::GlobalVariable *&CacheEntry = InitializerConstants[&D];
1143 if (!CacheEntry || CacheEntry->getInitializer() != Constant) {
1144 auto *Ty = Constant->getType();
1145 bool isConstant =
true;
1146 llvm::GlobalVariable *InsertBefore =
nullptr;
1153 Name = (
"__const." + FunctionName(DC) +
"." + D.
getName()).str();
1155 llvm_unreachable(
"local variable has no parent function or method");
1156 llvm::GlobalVariable *GV =
new llvm::GlobalVariable(
1157 getModule(), Ty, isConstant, llvm::GlobalValue::PrivateLinkage,
1158 Constant, Name, InsertBefore, llvm::GlobalValue::NotThreadLocal, AS);
1160 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
1162 }
else if (CacheEntry->getAlignment() < uint64_t(Align.
getQuantity())) {
1163 CacheEntry->setAlignment(Align.
getAsAlign());
1166 return Address(CacheEntry, CacheEntry->getValueType(), Align);
1172 llvm::Constant *Constant,
1175 return Builder.CreateElementBitCast(SrcPtr, CGM.
Int8Ty);
1181 llvm::Constant *constant,
bool IsAutoInit) {
1182 auto *Ty = constant->getType();
1183 uint64_t ConstantSize = CGM.
getDataLayout().getTypeAllocSize(Ty);
1187 bool canDoSingleStore = Ty->isIntOrIntVectorTy() ||
1188 Ty->isPtrOrPtrVectorTy() || Ty->isFPOrFPVectorTy();
1189 if (canDoSingleStore) {
1190 auto *I = Builder.CreateStore(constant, Loc, isVolatile);
1192 I->addAnnotationMetadata(
"auto-init");
1196 auto *SizeVal = llvm::ConstantInt::get(CGM.
IntPtrTy, ConstantSize);
1201 auto *I = Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.
Int8Ty, 0),
1202 SizeVal, isVolatile);
1204 I->addAnnotationMetadata(
"auto-init");
1206 bool valueAlreadyCorrect =
1207 constant->isNullValue() || isa<llvm::UndefValue>(constant);
1208 if (!valueAlreadyCorrect) {
1209 Loc = Builder.CreateElementBitCast(Loc, Ty);
1217 llvm::Value *Pattern =
1220 uint64_t
Value = 0x00;
1221 if (!isa<llvm::UndefValue>(Pattern)) {
1222 const llvm::APInt &AP = cast<llvm::ConstantInt>(Pattern)->getValue();
1223 assert(AP.getBitWidth() <= 8);
1224 Value = AP.getLimitedValue();
1226 auto *I = Builder.CreateMemSet(
1227 Loc, llvm::ConstantInt::get(CGM.
Int8Ty,
Value), SizeVal, isVolatile);
1229 I->addAnnotationMetadata(
"auto-init");
1235 if (
auto *STy = dyn_cast<llvm::StructType>(Ty)) {
1238 for (
unsigned i = 0; i != constant->getNumOperands(); i++) {
1239 Address EltPtr = Builder.CreateStructGEP(Loc, i);
1241 CGM, D, EltPtr, isVolatile, Builder,
1242 cast<llvm::Constant>(Builder.CreateExtractValue(constant, i)),
1247 }
else if (
auto *ATy = dyn_cast<llvm::ArrayType>(Ty)) {
1250 for (
unsigned i = 0; i != ATy->getNumElements(); i++) {
1251 Address EltPtr = Builder.CreateConstArrayGEP(Loc, i);
1253 CGM, D, EltPtr, isVolatile, Builder,
1254 cast<llvm::Constant>(Builder.CreateExtractValue(constant, i)),
1264 Builder.CreateMemCpy(Loc,
1267 SizeVal, isVolatile);
1269 I->addAnnotationMetadata(
"auto-init");
1276 llvm::Constant *constant =
1288 assert(!isa<llvm::UndefValue>(constant));
1294 auto *Ty = constant->getType();
1295 if (isa<llvm::UndefValue>(constant))
1297 if (Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy())
1298 for (llvm::Use &Op : constant->operands())
1305 llvm::Constant *constant) {
1306 auto *Ty = constant->getType();
1307 if (isa<llvm::UndefValue>(constant))
1309 if (!(Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy()))
1314 for (
unsigned Op = 0, NumOp = constant->getNumOperands(); Op != NumOp; ++Op) {
1315 auto *OpValue = cast<llvm::Constant>(constant->getOperand(Op));
1318 if (Ty->isStructTy())
1319 return llvm::ConstantStruct::get(cast<llvm::StructType>(Ty), Values);
1320 if (Ty->isArrayTy())
1321 return llvm::ConstantArray::get(cast<llvm::ArrayType>(Ty), Values);
1322 assert(Ty->isVectorTy());
1323 return llvm::ConstantVector::get(Values);
1339 llvm::Value *Addr) {
1340 if (!ShouldEmitLifetimeMarkers)
1343 assert(Addr->getType()->getPointerAddressSpace() ==
1345 "Pointer should be in alloca address space");
1346 llvm::Value *SizeV = llvm::ConstantInt::get(
1351 C->setDoesNotThrow();
1356 assert(Addr->getType()->getPointerAddressSpace() ==
1358 "Pointer should be in alloca address space");
1362 C->setDoesNotThrow();
1374 while (
getContext().getAsVariableArrayType(Type1D)) {
1376 if (
auto *
C = dyn_cast<llvm::ConstantInt>(VlaSize.NumElts))
1380 Twine Name = Twine(
"__vla_expr") + Twine(VLAExprCounter++);
1382 StringRef NameRef = Name.toStringRef(Buffer);
1384 VLAExprNames.push_back(&Ident);
1388 Dimensions.emplace_back(SizeExprAddr.getPointer(),
1391 Type1D = VlaSize.Type;
1400 unsigned NameIdx = 0;
1401 for (
auto &VlaSize : Dimensions) {
1403 if (
auto *
C = dyn_cast<llvm::ConstantInt>(VlaSize.NumElts))
1404 MD = llvm::ConstantAsMetadata::get(
C);
1408 assert(cast<llvm::PointerType>(VlaSize.NumElts->getType())
1409 ->isOpaqueOrPointeeTypeMatches(
SizeTy) &&
1410 "Number of VLA elements must be SizeTy");
1412 SizeTy->getScalarSizeInBits(),
false);
1417 ArtificialDecl->setImplicit();
1422 assert(MD &&
"No Size expression debug node created");
1429CodeGenFunction::AutoVarEmission
1436 AutoVarEmission emission(D);
1439 emission.IsEscapingByRef = isEscapingByRef;
1464 address = OpenMPLocalAddr;
1465 AllocaAddr = OpenMPLocalAddr;
1478 getContext().getBaseElementType(Ty)->isObjCObjectPointerType()) &&
1496 assert(emission.wasEmittedAsGlobal());
1501 emission.IsConstantAggregate =
true;
1516 const auto *RD = RecordTy->getDecl();
1517 const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1518 if ((CXXRD && !CXXRD->hasTrivialDestructor()) ||
1519 RD->isNonTrivialToPrimitiveDestroy()) {
1526 nullptr, &AllocaAddr);
1537 llvm::Type *allocaTy;
1538 if (isEscapingByRef) {
1540 allocaTy = byrefInfo.Type;
1541 allocaAlignment = byrefInfo.ByrefAlignment;
1544 allocaAlignment = alignment;
1551 nullptr, &AllocaAddr);
1556 bool IsMSCatchParam =
1578 emission.SizeForLifetimeMarkers =
1582 assert(!emission.useLifetimeMarkers());
1588 if (!DidCallStackSave) {
1594 llvm::Value *
V =
Builder.CreateCall(F);
1597 DidCallStackSave =
true;
1617 setAddrOfLocalVar(&D, address);
1618 emission.Addr = address;
1619 emission.AllocaAddr = AllocaAddr;
1628 if (UsePointerValue) {
1640 if (emission.useLifetimeMarkers())
1642 emission.getOriginalAllocatedAddress(),
1643 emission.getSizeForLifetimeMarkers());
1653 if (
const Expr *E = dyn_cast<Expr>(S))
1655 for (
const Stmt *SubStmt : S->children())
1668 if (
const BlockExpr *BE = dyn_cast<BlockExpr>(E)) {
1670 for (
const auto &I :
Block->captures()) {
1671 if (I.getVariable() == &Var)
1679 if (
const StmtExpr *SE = dyn_cast<StmtExpr>(E)) {
1681 for (
const auto *BI : CS->
body())
1682 if (
const auto *BIE = dyn_cast<Expr>(BI)) {
1686 else if (
const auto *DS = dyn_cast<DeclStmt>(BI)) {
1688 for (
const auto *I : DS->decls()) {
1689 if (
const auto *VD = dyn_cast<VarDecl>((I))) {
1720 !Construct->requiresZeroInitialization())
1726void CodeGenFunction::emitZeroOrPatternForAutoVarInit(
QualType type,
1731 bool isVolatile =
type.isVolatileQualified();
1732 if (!
Size.isZero()) {
1733 switch (trivialAutoVarInit) {
1735 llvm_unreachable(
"Uninitialized handled by caller");
1759 auto SizeVal = VlaSize.NumElts;
1761 switch (trivialAutoVarInit) {
1763 llvm_unreachable(
"Uninitialized handled by caller");
1768 if (!EltSize.
isOne())
1771 SizeVal, isVolatile);
1772 I->addAnnotationMetadata(
"auto-init");
1786 llvm::Value *IsZeroSizedVLA =
Builder.CreateICmpEQ(
1787 SizeVal, llvm::ConstantInt::get(SizeVal->getType(), 0),
1789 Builder.CreateCondBr(IsZeroSizedVLA, ContBB, SetupBB);
1791 if (!EltSize.
isOne())
1793 llvm::Value *BaseSizeInChars =
1796 llvm::Value *End =
Builder.CreateInBoundsGEP(
1797 Begin.getElementType(),
Begin.getPointer(), SizeVal,
"vla.end");
1798 llvm::BasicBlock *OriginBB =
Builder.GetInsertBlock();
1800 llvm::PHINode *Cur =
Builder.CreatePHI(
Begin.getType(), 2,
"vla.cur");
1801 Cur->addIncoming(
Begin.getPointer(), OriginBB);
1807 BaseSizeInChars, isVolatile);
1808 I->addAnnotationMetadata(
"auto-init");
1810 Builder.CreateInBoundsGEP(
Int8Ty, Cur, BaseSizeInChars,
"vla.next");
1811 llvm::Value *Done =
Builder.CreateICmpEQ(Next, End,
"vla-init.isdone");
1812 Builder.CreateCondBr(Done, ContBB, LoopBB);
1813 Cur->addIncoming(Next, LoopBB);
1820 assert(emission.Variable &&
"emission was not valid!");
1823 if (emission.wasEmittedAsGlobal())
return;
1825 const VarDecl &D = *emission.Variable;
1840 if (emission.IsEscapingByRef)
1847 type.isNonTrivialToPrimitiveDefaultInitialize() ==
1850 if (emission.IsEscapingByRef)
1859 bool capturedByInit =
1860 Init && emission.IsEscapingByRef &&
isCapturedBy(D, Init);
1862 bool locIsByrefHeader = !capturedByInit;
1864 locIsByrefHeader ? emission.getObjectAddress(*
this) : emission.Addr;
1870 : (D.
getAttr<UninitializedAttr>()
1874 auto initializeWhatIsTechnicallyUninitialized = [&](
Address Loc) {
1875 if (trivialAutoVarInit ==
1880 if (emission.IsEscapingByRef && !locIsByrefHeader)
1883 return emitZeroOrPatternForAutoVarInit(
type, D, Loc);
1887 return initializeWhatIsTechnicallyUninitialized(Loc);
1889 llvm::Constant *constant =
nullptr;
1890 if (emission.IsConstantAggregate ||
1892 assert(!capturedByInit &&
"constant init contains a capturing block?");
1894 if (constant && !constant->isZeroValue() &&
1895 (trivialAutoVarInit !=
1913 initializeWhatIsTechnicallyUninitialized(Loc);
1919 if (!emission.IsConstantAggregate) {
1942 LValue lvalue,
bool capturedByInit) {
1945 if (
type->isReferenceType()) {
1964 if (
type->isAtomicType()) {
1968 if (isa<VarDecl>(D))
1970 else if (
auto *FD = dyn_cast<FieldDecl>(D))
1980 llvm_unreachable(
"bad evaluation kind");
1985 const CodeGenFunction::AutoVarEmission &emission,
1991 Address addr = emission.getObjectAddress(*
this);
1993 const VarDecl *var = emission.Variable;
2001 llvm_unreachable(
"no cleanup for trivially-destructible variable");
2006 if (emission.NRVOFlag) {
2007 assert(!
type->isArrayType());
2009 EHStack.pushCleanup<DestroyNRVOVariableCXX>(cleanupKind, addr,
type, dtor,
2023 if (!var->
hasAttr<ObjCPreciseLifetimeAttr>())
2032 if (emission.NRVOFlag) {
2033 assert(!
type->isArrayType());
2034 EHStack.pushCleanup<DestroyNRVOVariableC>(cleanupKind, addr,
2035 emission.NRVOFlag,
type);
2046 bool useEHCleanup = (cleanupKind &
EHCleanup);
2047 EHStack.pushCleanup<DestroyObject>(cleanupKind, addr,
type, destroyer,
2052 assert(emission.Variable &&
"emission was not valid!");
2055 if (emission.wasEmittedAsGlobal())
return;
2061 const VarDecl &D = *emission.Variable;
2069 D.
hasAttr<ObjCPreciseLifetimeAttr>()) {
2074 if (
const CleanupAttr *CA = D.
getAttr<CleanupAttr>()) {
2078 assert(F &&
"Could not find function!");
2087 if (emission.IsEscapingByRef &&
2090 if (emission.Variable->getType().isObjCGCWeak())
2111 llvm_unreachable(
"Unknown DestructionKind");
2118 assert(dtorKind &&
"cannot push destructor for trivial type");
2128 assert(dtorKind &&
"cannot push destructor for trivial type");
2137 bool useEHCleanupForArray) {
2138 pushFullExprCleanup<DestroyObject>(cleanupKind, addr,
type,
2139 destroyer, useEHCleanupForArray);
2143 EHStack.pushCleanup<CallStackRestore>(
Kind, SPMem);
2148 Destroyer *destroyer,
2149 bool useEHCleanupForArray) {
2157 EHStack.pushCleanup<DestroyObject>(
2159 destroyer, useEHCleanupForArray);
2161 return pushCleanupAfterFullExprWithActiveFlag<DestroyObject>(
2170 using ConditionalCleanupType =
2178 EHStack.pushCleanup<ConditionalCleanupType>(
2179 static_cast<CleanupKind>(cleanupKind & ~NormalCleanup), SavedAddr,
type,
2180 destroyer, useEHCleanupForArray);
2184 pushCleanupAfterFullExprWithActiveFlag<ConditionalCleanupType>(
2185 cleanupKind, ActiveFlag, SavedAddr,
type, destroyer,
2186 useEHCleanupForArray);
2201 Destroyer *destroyer,
2202 bool useEHCleanupForArray) {
2205 return destroyer(*
this, addr,
type);
2214 bool checkZeroLength =
true;
2217 if (llvm::ConstantInt *constLength = dyn_cast<llvm::ConstantInt>(
length)) {
2219 if (constLength->isZero())
return;
2220 checkZeroLength =
false;
2227 checkZeroLength, useEHCleanupForArray);
2244 Destroyer *destroyer,
2245 bool checkZeroLength,
2246 bool useEHCleanup) {
2254 if (checkZeroLength) {
2255 llvm::Value *isEmpty =
Builder.CreateICmpEQ(begin, end,
2256 "arraydestroy.isempty");
2257 Builder.CreateCondBr(isEmpty, doneBB, bodyBB);
2261 llvm::BasicBlock *entryBB =
Builder.GetInsertBlock();
2263 llvm::PHINode *elementPast =
2264 Builder.CreatePHI(begin->getType(), 2,
"arraydestroy.elementPast");
2265 elementPast->addIncoming(end, entryBB);
2268 llvm::Value *negativeOne = llvm::ConstantInt::get(
SizeTy, -1,
true);
2270 llvm::Value *element =
Builder.CreateInBoundsGEP(
2271 llvmElementType, elementPast, negativeOne,
"arraydestroy.element");
2278 destroyer(*
this,
Address(element, llvmElementType, elementAlign),
2285 llvm::Value *done =
Builder.CreateICmpEQ(element, begin,
"arraydestroy.done");
2286 Builder.CreateCondBr(done, doneBB, bodyBB);
2287 elementPast->addIncoming(element,
Builder.GetInsertBlock());
2296 llvm::Value *begin, llvm::Value *end,
2302 unsigned arrayDepth = 0;
2311 llvm::Value *zero = llvm::ConstantInt::get(CGF.
SizeTy, 0);
2314 begin = CGF.
Builder.CreateInBoundsGEP(
2315 elemTy, begin, gepIndices,
"pad.arraybegin");
2316 end = CGF.
Builder.CreateInBoundsGEP(
2317 elemTy, end, gepIndices,
"pad.arrayend");
2332 llvm::Value *ArrayBegin;
2333 llvm::Value *ArrayEnd;
2335 CodeGenFunction::Destroyer *Destroyer;
2338 RegularPartialArrayDestroy(llvm::Value *arrayBegin, llvm::Value *arrayEnd,
2340 CodeGenFunction::Destroyer *destroyer)
2341 : ArrayBegin(arrayBegin), ArrayEnd(arrayEnd),
2342 ElementType(elementType), Destroyer(destroyer),
2343 ElementAlign(elementAlign) {}
2347 ElementType, ElementAlign, Destroyer);
2355 llvm::Value *ArrayBegin;
2358 CodeGenFunction::Destroyer *Destroyer;
2361 IrregularPartialArrayDestroy(llvm::Value *arrayBegin,
2365 CodeGenFunction::Destroyer *destroyer)
2366 : ArrayBegin(arrayBegin), ArrayEndPointer(arrayEndPointer),
2367 ElementType(elementType), Destroyer(destroyer),
2368 ElementAlign(elementAlign) {}
2373 ElementType, ElementAlign, Destroyer);
2388 Destroyer *destroyer) {
2389 pushFullExprCleanup<IrregularPartialArrayDestroy>(
EHCleanup,
2390 arrayBegin, arrayEndPointer,
2391 elementType, elementAlign,
2402 llvm::Value *arrayEnd,
2405 Destroyer *destroyer) {
2406 pushFullExprCleanup<RegularPartialArrayDestroy>(
EHCleanup,
2407 arrayBegin, arrayEnd,
2408 elementType, elementAlign,
2414 if (LifetimeStartFn)
2415 return LifetimeStartFn;
2416 LifetimeStartFn = llvm::Intrinsic::getDeclaration(&
getModule(),
2418 return LifetimeStartFn;
2424 return LifetimeEndFn;
2425 LifetimeEndFn = llvm::Intrinsic::getDeclaration(&
getModule(),
2427 return LifetimeEndFn;
2436 ConsumeARCParameter(llvm::Value *param,
2438 : Param(param), Precise(precise) {}
2453 bool NoDebugInfo =
false;
2455 assert((isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D)) &&
2456 "Invalid argument to EmitParmDecl");
2458 Arg.getAnyValue()->setName(D.
getName());
2463 if (
auto IPD = dyn_cast<ImplicitParamDecl>(&D)) {
2467 llvm::Value *
V = Arg.isIndirect()
2469 : Arg.getDirectValue();
2481 bool DoStore =
false;
2483 bool UseIndirectDebugAddress =
false;
2486 if (Arg.isIndirect()) {
2488 DeclPtr = Arg.getIndirectAddress();
2495 AllocaPtr = DeclPtr;
2502 if (UseIndirectDebugAddress) {
2505 D.
getName() +
".indirect_addr");
2512 if (SrcLangAS != DestLangAS) {
2513 assert(
getContext().getTargetAddressSpace(SrcLangAS) ==
2519 *
this,
V, SrcLangAS, DestLangAS, T,
true),
2532 "unexpected destructor type");
2534 CalleeDestructedParamCleanups[cast<ParmVarDecl>(&D)] =
2545 DeclPtr = OpenMPLocalAddr;
2546 AllocaPtr = DeclPtr;
2550 D.
getName() +
".addr", &AllocaPtr);
2555 llvm::Value *ArgVal = (DoStore ? Arg.getDirectValue() :
nullptr);
2565 bool isConsumed = D.
hasAttr<NSConsumedAttr>();
2570 "pseudo-strong variable isn't strong?");
2571 assert(qs.
hasConst() &&
"pseudo-strong variable should be const!");
2576 if (Arg.isIndirect() && !ArgVal)
2620 setAddrOfLocalVar(&D, DeclPtr);
2628 if (
const auto *Var = dyn_cast_or_null<ParmVarDecl>(&D))
2633 if (D.
hasAttr<AnnotateAttr>())
2639 if (requiresReturnValueNullabilityCheck()) {
2642 SanitizerScope SanScope(
this);
2643 RetValNullabilityPrecondition =
2644 Builder.CreateAnd(RetValNullabilityPrecondition,
2645 Builder.CreateIsNotNull(Arg.getAnyValue()));
2652 if (!LangOpts.OpenMP || (!LangOpts.EmitAllDecls && !D->
isUsed()))
2659 if (!LangOpts.OpenMP || LangOpts.OpenMPSimd ||
2660 (!LangOpts.EmitAllDecls && !D->
isUsed()))
2671 const auto *DE = cast<DeclRefExpr>(E);
2672 const auto *VD = cast<VarDecl>(DE->getDecl());
2695 if (Entry->getType()->getAddressSpace() == TargetAS)
2700 llvm::PointerType *PTy = llvm::PointerType::get(Ty, TargetAS);
2705 llvm::GlobalVariable *DummyGV =
new llvm::GlobalVariable(
2706 getModule(), Entry->getValueType(),
false,
2707 llvm::GlobalValue::CommonLinkage,
nullptr,
"dummy",
nullptr,
2708 llvm::GlobalVariable::NotThreadLocal, Entry->getAddressSpace());
2709 Entry->replaceAllUsesWith(DummyGV);
2711 Entry->mutateType(PTy);
2712 llvm::Constant *NewPtrForOldDecl =
2713 llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
2714 Entry, DummyGV->getType());
2718 DummyGV->replaceAllUsesWith(NewPtrForOldDecl);
2719 DummyGV->eraseFromParent();
2723std::optional<CharUnits>
2725 if (
const auto *AA = VD->
getAttr<OMPAllocateDeclAttr>()) {
2726 if (
Expr *Alignment = AA->getAlignment()) {
2727 unsigned UserAlign =
2728 Alignment->EvaluateKnownConstInt(
getContext()).getExtValue();
2736 std::max<unsigned>(UserAlign, NaturalAlign.
getQuantity()));
2739 return std::nullopt;
Defines the clang::ASTContext interface.
static void emitStoresForInitAfterBZero(CodeGenModule &CGM, llvm::Constant *Init, Address Loc, bool isVolatile, CGBuilderTy &Builder, bool IsAutoInit)
For inits that canEmitInitWithFewStoresAfterBZero returned true for, emit the scalar stores that woul...
static bool isCapturedBy(const VarDecl &, const Expr *)
Determines whether the given __block variable is potentially captured by the given expression.
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.
static void emitStoresForPatternInit(CodeGenModule &CGM, const VarDecl &D, Address Loc, bool isVolatile, CGBuilderTy &Builder)
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...
static llvm::Constant * patternOrZeroFor(CodeGenModule &CGM, IsPattern isPattern, llvm::Type *Ty)
Generate a constant filled with either a pattern or zeroes.
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 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...
static std::string getStaticDeclName(CodeGenModule &CGM, const VarDecl &D)
static void emitStoresForConstant(CodeGenModule &CGM, const VarDecl &D, Address Loc, bool isVolatile, CGBuilderTy &Builder, llvm::Constant *constant, bool IsAutoInit)
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...
static llvm::Constant * replaceUndef(CodeGenModule &CGM, IsPattern isPattern, llvm::Constant *constant)
static bool tryEmitARCCopyWeakInit(CodeGenFunction &CGF, const LValue &destLV, const Expr *init)
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 * constStructWithPadding(CodeGenModule &CGM, IsPattern isPattern, llvm::StructType *STy, llvm::Constant *constant)
Helper function for constWithPadding() to deal with padding in structures.
static bool containsUndef(llvm::Constant *constant)
static bool isAccessedBy(const VarDecl &var, const Stmt *s)
static void EmitAutoVarWithLifetime(CodeGenFunction &CGF, const VarDecl &var, Address addr, Qualifiers::ObjCLifetime lifetime)
EmitAutoVarWithLifetime - Does the setup required for an automatic variable with lifetime.
static Address createUnnamedGlobalForMemcpyFrom(CodeGenModule &CGM, const VarDecl &D, CGBuilderTy &Builder, llvm::Constant *Constant, CharUnits Align)
static void emitStoresForZeroInit(CodeGenModule &CGM, const VarDecl &D, Address Loc, bool isVolatile, CGBuilderTy &Builder)
static void drillIntoBlockVariable(CodeGenFunction &CGF, LValue &lvalue, const VarDecl *var)
CodeGenFunction::ComplexPairTy ComplexPairTy
This file defines OpenMP nodes for declarative directives.
static const RecordType * getRecordType(QualType QT)
Checks that the passed in QualType either is of RecordType or points to RecordType.
static const NamedDecl * getDefinition(const Decl *D)
Defines the SourceManager interface.
__device__ __2f16 float bool s
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
const LangOptions & getLangOpts() const
QualType getIntTypeForBitwidth(unsigned DestWidth, unsigned Signed) const
getIntTypeForBitwidth - sets integer QualTy according to specified details: bitwidth,...
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
const VariableArrayType * getAsVariableArrayType(QualType T) const
unsigned getTargetAddressSpace(LangAS AS) const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
ArrayRef< Capture > captures() const
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Represents a call to a C++ constructor.
Represents a C++ constructor within a class.
A use of a default initializer in a constructor or in aggregate initialization.
Represents a C++ destructor within a class.
CharUnits - This is an opaque type for sizes expressed in character units.
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits One()
One - Construct a CharUnits quantity of one.
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
bool isOne() const
isOne - Test whether the quantity equals one.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
bool hasReducedDebugInfo() const
Check if type and variable info should be emitted.
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
bool getIndirectByVal() const
CharUnits getAlignment() const
Return the alignment of this pointer.
llvm::Type * getElementType() const
Return the type of the values stored in this address.
Address withPointer(llvm::Value *NewPointer, KnownNonNull_t IsKnownNonNull) const
Return address with different pointer, but same element type and alignment.
KnownNonNull_t isKnownNonNull() const
Whether the pointer is known not to be null.
llvm::Value * getPointer() const
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)
static ApplyDebugLocation CreateDefaultArtificial(CodeGenFunction &CGF, SourceLocation TemporaryLocation)
Apply TemporaryLocation if it is valid.
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
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...
llvm::CallInst * CreateMemSet(Address Dest, llvm::Value *Value, llvm::Value *Size, bool IsVolatile=false)
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
llvm::LoadInst * CreateFlagLoad(llvm::Value *Addr, const llvm::Twine &Name="")
Emit a load from an i1 flag variable.
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl)
Emit information about a global variable.
Param2DILocTy & getParamDbgMappings()
llvm::DILocalVariable * EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, unsigned ArgNo, CGBuilderTy &Builder, bool UsePointerValue=false)
Emit call to llvm.dbg.declare for an argument variable declaration.
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.
void setLocation(SourceLocation Loc)
Update the current source location.
void registerVLASizeExpression(QualType Ty, llvm::Metadata *SizeExpr)
Register VLA size expression debug node with the qualified type.
CGFunctionInfo - Class to encapsulate the information about a function definition.
const_arg_iterator arg_begin() const
MutableArrayRef< ArgInfo > arguments()
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...
Allows to disable automatic handling of functions used in target regions as those marked as omp decla...
void emitUserDefinedMapper(const OMPDeclareMapperDecl *D, CodeGenFunction *CGF=nullptr)
Emit the function for the user defined mapper construct.
virtual void processRequiresDirective(const OMPRequiresDecl *D)
Perform check on requires decl to ensure that target architecture supports unified addressing.
virtual void emitUserDefinedReduction(CodeGenFunction *CGF, const OMPDeclareReductionDecl *D)
Emit code for the specified user defined reduction construct.
virtual Address getAddressOfLocalVariable(CodeGenFunction &CGF, const VarDecl *VD)
Gets the OpenMP-specific address of the local variable.
CallArgList - Type for representing both the value and type of arguments in a call.
void add(RValue rvalue, QualType type)
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
void emitAutoVarTypeCleanup(const AutoVarEmission &emission, QualType::DestructionKind dtorKind)
void enterByrefCleanup(CleanupKind Kind, Address Addr, BlockFieldFlags Flags, bool LoadBlockVarAddr, bool CanThrow)
Enter a cleanup to destroy a __block variable.
llvm::Value * EmitLifetimeStart(llvm::TypeSize Size, llvm::Value *Addr)
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts=false)
ContainsLabel - Return true if the statement contains a label in it.
void PopCleanupBlock(bool FallThroughIsBranchThrough=false)
PopCleanupBlock - Will pop the cleanup entry on the stack and process all branch fixups.
static Destroyer destroyNonTrivialCStruct
static bool cxxDestructorCanThrow(QualType T)
Check if T is a C++ class that has a destructor that can throw.
SanitizerSet SanOpts
Sanitizers enabled for this function.
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...
void EmitARCMoveWeak(Address dst, Address src)
void EmitAutoVarDecl(const VarDecl &D)
EmitAutoVarDecl - Emit an auto variable declaration.
void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr)
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
EmitStoreThroughLValue - Store the specified rvalue into the specified lvalue, where both are guarant...
void pushLifetimeExtendedDestroy(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
static bool hasScalarEvaluationKind(QualType T)
const BlockByrefInfo & getBlockByrefInfo(const VarDecl *var)
void EmitDecl(const Decl &D)
EmitDecl - Emit a declaration.
void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin, Address arrayEndPointer, QualType elementType, CharUnits elementAlignment, Destroyer *destroyer)
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...
VlaSizePair getVLASize(const VariableArrayType *vla)
Returns an LLVM value that corresponds to the size, in non-variably-sized elements,...
CleanupKind getARCCleanupKind()
Retrieves the default cleanup kind for an ARC cleanup.
bool CurFuncIsThunk
In C++, whether we are code generating a thunk.
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating, Address This, QualType ThisTy)
LValue EmitLValue(const Expr *E, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
EmitLValue - Emit code to compute a designator that specifies the location of the expression.
void EmitExtendGCLifetime(llvm::Value *object)
EmitExtendGCLifetime - Given a pointer to an Objective-C object, make sure it survives garbage collec...
llvm::Value * EmitARCStoreWeak(Address addr, llvm::Value *value, bool ignored)
void EmitVariablyModifiedType(QualType Ty)
EmitVLASize - Capture all the sizes for the VLA expressions in the given variably-modified type and s...
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
const LangOptions & getLangOpts() const
llvm::Constant * EmitCheckTypeDescriptor(QualType T)
Emit a description of a type in a format suitable for passing to a runtime sanitizer handler.
void pushEHDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
void emitArrayDestroy(llvm::Value *begin, llvm::Value *end, QualType elementType, CharUnits elementAlign, Destroyer *destroyer, bool checkZeroLength, bool useEHCleanup)
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
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...
const CodeGen::CGBlockInfo * BlockInfo
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...
void emitByrefStructureInit(const AutoVarEmission &emission)
ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal=false, bool IgnoreImag=false)
EmitComplexExpr - Emit the computation of the specified expression of complex type,...
@ TCK_NonnullAssign
Checking the value assigned to a _Nonnull pointer. Must not be null.
llvm::Value * EmitARCStoreStrongCall(Address addr, llvm::Value *value, bool resultIgnored)
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **callOrInvoke, bool IsMustTail, SourceLocation Loc)
EmitCall - Generate a call of the given function, expecting the given result type,...
llvm::Type * ConvertTypeForMem(QualType T)
llvm::Value * EmitARCUnsafeUnretainedScalarExpr(const Expr *expr)
void EmitAutoVarInit(const AutoVarEmission &emission)
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
DominatingValue< T >::saved_type saveValueInCond(T value)
void EmitStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
static Destroyer destroyCXXObject
void EmitVarAnnotations(const VarDecl *D, llvm::Value *V)
Emit local annotations for the local variable V, declared by D.
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
void EmitAtomicInit(Expr *E, LValue lvalue)
const TargetInfo & getTarget() const
bool isInConditionalBranch() const
isInConditionalBranch - Return true if we're currently emitting one branch or the other of a conditio...
void emitDestroy(Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr, bool PerformInit)
Emit code in this function to perform a guarded variable initialization.
void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise)
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 EmitARCCopyWeak(Address dst, Address src)
void setBlockContextParameter(const ImplicitParamDecl *D, unsigned argNum, llvm::Value *ptr)
void defaultInitNonTrivialCStructVar(LValue Dst)
bool HaveInsertPoint() const
HaveInsertPoint - True if an insertion point is defined.
llvm::Constant * EmitCheckSourceLocation(SourceLocation Loc)
Emit a description of a source location in a format suitable for passing to a runtime sanitizer handl...
bool isTrivialInitializer(const Expr *Init)
Determine whether the given initializer is trivial in the sense that it requires no code to be genera...
CGDebugInfo * getDebugInfo()
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...
LValue EmitDeclRefLValue(const DeclRefExpr *E)
AggValueSlot::Overlap_t getOverlapForFieldInit(const FieldDecl *FD)
Determine whether a field initialization may overlap some other object.
Address createCleanupActiveFlag()
Address CreateDefaultAlignTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
CreateDefaultAlignedTempAlloca - This creates an alloca with the default ABI alignment of the given L...
llvm::Value * EmitARCRetainAutoreleaseScalarExpr(const Expr *expr)
const TargetCodeGenInfo & getTargetHooks() const
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type.
VlaSizePair getVLAElements1D(const VariableArrayType *vla)
Return the number of elements for a single dimension for the given array type.
void EmitVarDecl(const VarDecl &D)
EmitVarDecl - Emit a local variable declaration.
ASTContext & getContext() const
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...
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...
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.
void Destroyer(CodeGenFunction &CGF, Address addr, QualType ty)
AutoVarEmission EmitAutoVarAlloca(const VarDecl &var)
void pushDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
Address ReturnValuePointer
ReturnValuePointer - The temporary alloca to hold a pointer to sret.
void EmitAutoVarCleanups(const AutoVarEmission &emission)
llvm::GlobalVariable * AddInitializerToStaticVarDecl(const VarDecl &D, llvm::GlobalVariable *GV)
AddInitializerToStaticVarDecl - Add the initializer for 'D' to the global variable that has already b...
static Destroyer destroyARCWeak
bool needsEHCleanup(QualType::DestructionKind kind)
Determines whether an EH cleanup is required to destroy a type with the given destruction kind.
CleanupKind getCleanupKind(QualType::DestructionKind kind)
llvm::Type * ConvertType(QualType T)
void EmitARCInitWeak(Address addr, llvm::Value *value)
static Destroyer destroyARCStrongPrecise
void initFullExprCleanupWithFlag(Address ActiveFlag)
VarBypassDetector Bypasses
llvm::Value * EmitARCRetainNonBlock(llvm::Value *value)
void pushStackRestore(CleanupKind kind, Address SPMem)
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
const CGFunctionInfo * CurFnInfo
void EmitParmDecl(const VarDecl &D, ParamValue Arg, unsigned ArgNo)
EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
static Destroyer destroyARCStrongImprecise
void EnsureInsertPoint()
EnsureInsertPoint - Ensure that an insertion point is defined so that emitted IR has a place to go.
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type,...
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.
llvm::Value * EmitARCRetainScalarExpr(const Expr *expr)
void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin, llvm::Value *arrayEnd, QualType elementType, CharUnits elementAlignment, Destroyer *destroyer)
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...
bool hasLabelBeenSeenInCurrentScope() const
Return true if a label was seen in the current scope.
This class organizes the cross-function state that is used while generating LLVM code.
StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD)
void setGVProperties(llvm::GlobalValue *GV, GlobalDecl GD) const
Set visibility, dllimport/dllexport and dso_local.
llvm::Module & getModule() const
void setStaticLocalDeclAddress(const VarDecl *D, llvm::Constant *C)
llvm::Function * getLLVMLifetimeStartFn()
Lazily declare the @llvm.lifetime.start intrinsic.
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.
Address createUnnamedGlobalFrom(const VarDecl &D, llvm::Constant *Constant, CharUnits Align)
llvm::Constant * getNullPointer(llvm::PointerType *T, QualType QT)
Get target specific null pointer.
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
const LangOptions & getLangOpts() const
CharUnits getNaturalTypeAlignment(QualType T, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr, bool forPointeeType=false)
CodeGenTypes & getTypes()
CGOpenCLRuntime & getOpenCLRuntime()
Return a reference to the configured OpenCL runtime.
llvm::GlobalValue::LinkageTypes getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant)
Returns LLVM linkage for a declarator.
void addUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.used metadata.
void EmitOMPAllocateDecl(const OMPAllocateDecl *D)
Emit a code for the allocate directive.
const llvm::DataLayout & getDataLayout() const
void addUsedOrCompilerUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.compiler.used metadata.
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
SanitizerMetadata * getSanitizerMetadata()
llvm::Constant * getOrCreateStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
llvm::Constant * GetAddrOfGlobal(GlobalDecl GD, ForDefinition_t IsForDefinition=NotForDefinition)
void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV)
Add global annotations that are set on D, for the global GV.
void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const
Set the TLS mode for the given LLVM GlobalValue for the thread-local variable declaration D.
ASTContext & getContext() const
void EmitOMPDeclareMapper(const OMPDeclareMapperDecl *D, CodeGenFunction *CGF=nullptr)
Emit a code for declare mapper construct.
llvm::Function * getLLVMLifetimeEndFn()
Lazily declare the @llvm.lifetime.end intrinsic.
bool supportsCOMDAT() const
void EmitOMPRequiresDecl(const OMPRequiresDecl *D)
Emit a code for requires directive.
const TargetCodeGenInfo & getTargetCodeGenInfo()
const CodeGenOptions & getCodeGenOpts() const
StringRef getMangledName(GlobalDecl GD)
std::optional< CharUnits > getOMPAllocateAlignment(const VarDecl *VD)
Return the alignment specified in an allocate directive, if present.
llvm::LLVMContext & getLLVMContext()
llvm::GlobalValue * GetGlobalValue(StringRef Ref)
void EmitOMPDeclareReduction(const OMPDeclareReductionDecl *D, CodeGenFunction *CGF=nullptr)
Emit a code for declare reduction construct.
bool isTypeConstant(QualType QTy, bool ExcludeCtor, bool ExcludeDtor)
isTypeConstant - Determine whether an object of this type can be emitted as a constant.
llvm::Constant * EmitNullConstant(QualType T)
Return the result of value-initializing the given type, i.e.
LangAS GetGlobalConstantAddressSpace() const
Return the AST address space of constant literal, which is used to emit the constant literal as globa...
LangAS GetGlobalVarAddressSpace(const VarDecl *D)
Return the AST address space of the underlying global variable for D, as determined by its declaratio...
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=std::nullopt)
llvm::ConstantInt * getSize(CharUnits numChars)
Emit the given number of characters as a value of type size_t.
const CGFunctionInfo & arrangeFunctionDeclaration(const FunctionDecl *FD)
Free functions are functions that are compatible with an ordinary C function pointer type.
llvm::Type * ConvertTypeForMem(QualType T, bool ForBitField=false)
ConvertTypeForMem - Convert type T into a llvm::Type.
llvm::Constant * tryEmitAbstractForInitializer(const VarDecl &D)
Try to emit the initializer of the given declaration as an abstract constant.
Information for lazily generating a cleanup.
ConditionalCleanup stores the saved form of its parameters, then restores them and performs the clean...
stable_iterator stable_begin() const
Create a stable reference to the top of the EH stack.
LValue - This represents an lvalue references.
Address getAddress(CodeGenFunction &CGF) const
llvm::Value * getPointer(CodeGenFunction &CGF) const
void setNonGC(bool Value)
void setAddress(Address address)
Qualifiers::ObjCLifetime getObjCLifetime() const
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
static RValue get(llvm::Value *V)
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
virtual llvm::Value * performAddrSpaceCast(CodeGen::CodeGenFunction &CGF, llvm::Value *V, LangAS SrcAddr, LangAS DestAddr, llvm::Type *DestTy, bool IsNonNull=false) const
Perform address space cast of an expression of pointer type.
bool IsBypassed(const VarDecl *D) const
Returns true if the variable declaration was by bypassed by any goto or switch statement.
CompoundStmt - This represents a group of statements like { stmt stmt }.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
A reference to a declared variable, function, enum, etc.
Decl - This represents one declaration (or definition), e.g.
const DeclContext * getParentFunctionOrMethod(bool LexicalParent=false) const
If this decl is defined inside a function/method/block it returns the corresponding DeclContext,...
Decl * getNonClosureContext()
Find the innermost non-closure ancestor of this declaration, walking up through blocks,...
SourceLocation getLocation() const
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
DeclContext * getDeclContext()
This represents one expression.
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
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,...
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Represents a function declaration or definition.
GlobalDecl - represents a global declaration.
const Decl * getDecl() const
One of these records is kept for each identifier that is lexed.
IdentifierInfo & getOwn(StringRef Name)
Gets an IdentifierInfo for the given name without consulting external sources.
@ ThreadPrivateVar
Parameter for Thread private variable.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
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...
bool isExternallyVisible() const
This represents '#pragma omp allocate ...' directive.
This represents '#pragma omp declare mapper ...' directive.
This represents '#pragma omp declare reduction ...' directive.
This represents '#pragma omp requires...' directive.
A (possibly-)qualified type.
@ DK_objc_strong_lifetime
@ PDIK_Struct
The type is a struct containing a field whose type is not PCK_Trivial.
LangAS getAddressSpace() const
Return the address space of this type.
bool isConstant(const ASTContext &Ctx) const
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
The collection of all-type qualifiers we support.
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
@ OCL_None
There is no lifetime qualification on this type.
@ OCL_Weak
Reading or writing from this object requires a barrier call.
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
ObjCLifetime getObjCLifetime() const
bool isParamDestroyedInCallee() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
RecordDecl * getDecl() const
Scope - A scope is a transient data structure that is used while parsing the program.
static const uint64_t MaximumAlignment
Encodes a location in the source.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Stmt - This represents one statement.
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6....
const T * castAs() const
Member-template castAs<specific type>.
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
std::optional< NullabilityKind > getNullability() const
Determine the nullability of the given type.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
TLSKind getTLSKind() const
bool hasFlexibleArrayInit(const ASTContext &Ctx) const
Whether this variable has a flexible array member initialized with one or more elements.
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
CharUnits getFlexibleArrayInitChars(const ASTContext &Ctx) const
If hasFlexibleArrayInit is true, compute the number of additional bytes necessary to store those elem...
bool mightBeUsableInConstantExpressions(const ASTContext &C) const
Determine whether this variable's value might be usable in a constant expression, according to the re...
bool isNRVOVariable() const
Determine whether this local variable can be used with the named return value optimization (NRVO).
bool isExceptionVariable() const
Determine whether this variable is the exception variable in a C++ catch statememt or an Objective-C ...
QualType::DestructionKind needsDestruction(const ASTContext &Ctx) const
Would the destruction of this variable have any effect, and if so, what kind?
const Expr * getInit() const
bool hasExternalStorage() const
Returns true if a variable has extern or private_extern storage.
bool isARCPseudoStrong() const
Determine whether this variable is an ARC pseudo-__strong variable.
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
StorageDuration getStorageDuration() const
Get the storage duration of this variable, per C++ [basic.stc].
bool isEscapingByref() const
Indicates the capture is a __block variable that is captured by a block that can potentially escape (...
Defines the clang::TargetInfo interface.
llvm::Constant * initializationPatternFor(CodeGenModule &, llvm::Type *)
@ NormalCleanup
Denotes a cleanup that should run when a scope is exited using normal control flow (falling off the e...
@ EHCleanup
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
ARCPreciseLifetime_t
Does an ARC strong l-value have precise lifetime?
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< ArrayType > arrayType
Matches all kinds of arrays.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, CastExpr > castExpr
Matches any cast nodes of Clang's AST.
bool Zero(InterpState &S, CodePtr OpPC)
bool Null(InterpState &S, CodePtr OpPC)
@ Ctor_Base
Base object ctor.
@ NonNull
Values of this type can never be null.
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
@ C
Languages that the frontend can parse and compile.
@ SD_Automatic
Automatic storage duration (most local variables).
@ Dtor_Base
Base object dtor.
@ Dtor_Complete
Complete object dtor.
LangAS
Defines the address space values used by the address space qualifier of QualType.
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
float __ovld __cnfn length(float)
Return the length of vector p, i.e., sqrt(p.x2 + p.y 2 + ...)
static Address getAddressOfLocalVariable(CodeGenFunction &CGF, const VarDecl *VD)
Gets the OpenMP-specific address of the local variable /p VD.
llvm::IntegerType * Int64Ty
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
llvm::IntegerType * SizeTy
llvm::IntegerType * IntPtrTy
llvm::PointerType * Int8PtrTy
CharUnits getPointerAlign() const
llvm::PointerType * AllocaInt8PtrTy
LangAS getASTAllocaAddressSpace() const
A metaprogramming class for ensuring that a value will dominate an arbitrary position in a function.
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.