35#include "llvm/Analysis/ConstantFolding.h"
36#include "llvm/Analysis/ValueTracking.h"
37#include "llvm/IR/DataLayout.h"
38#include "llvm/IR/GlobalVariable.h"
39#include "llvm/IR/Instructions.h"
40#include "llvm/IR/Intrinsics.h"
41#include "llvm/IR/Type.h"
45using namespace CodeGen;
48 "Clang max alignment greater than what LLVM supports?");
50void CodeGenFunction::EmitDecl(
const Decl &
D) {
52 case Decl::BuiltinTemplate:
53 case Decl::TranslationUnit:
54 case Decl::ExternCContext:
56 case Decl::UnresolvedUsingTypename:
57 case Decl::ClassTemplateSpecialization:
58 case Decl::ClassTemplatePartialSpecialization:
59 case Decl::VarTemplateSpecialization:
60 case Decl::VarTemplatePartialSpecialization:
61 case Decl::TemplateTypeParm:
62 case Decl::UnresolvedUsingValue:
63 case Decl::NonTypeTemplateParm:
64 case Decl::CXXDeductionGuide:
66 case Decl::CXXConstructor:
67 case Decl::CXXDestructor:
68 case Decl::CXXConversion:
70 case Decl::MSProperty:
71 case Decl::IndirectField:
73 case Decl::ObjCAtDefsField:
75 case Decl::ImplicitParam:
76 case Decl::ClassTemplate:
77 case Decl::VarTemplate:
78 case Decl::FunctionTemplate:
79 case Decl::TypeAliasTemplate:
80 case Decl::TemplateTemplateParm:
81 case Decl::ObjCMethod:
82 case Decl::ObjCCategory:
83 case Decl::ObjCProtocol:
84 case Decl::ObjCInterface:
85 case Decl::ObjCCategoryImpl:
86 case Decl::ObjCImplementation:
87 case Decl::ObjCProperty:
88 case Decl::ObjCCompatibleAlias:
89 case Decl::PragmaComment:
90 case Decl::PragmaDetectMismatch:
91 case Decl::AccessSpec:
92 case Decl::LinkageSpec:
94 case Decl::ObjCPropertyImpl:
95 case Decl::FileScopeAsm:
96 case Decl::TopLevelStmt:
98 case Decl::FriendTemplate:
101 case Decl::UsingShadow:
102 case Decl::ConstructorUsingShadow:
103 case Decl::ObjCTypeParam:
105 case Decl::UnresolvedUsingIfExists:
106 case Decl::HLSLBuffer:
107 llvm_unreachable(
"Declaration should not be in declstmts!");
109 case Decl::CXXRecord:
117 DI->EmitAndRetainType(
getContext().getEnumType(cast<EnumDecl>(&
D)));
120 case Decl::EnumConstant:
121 case Decl::StaticAssert:
125 case Decl::UnnamedGlobalConstant:
126 case Decl::TemplateParamObject:
127 case Decl::OMPThreadPrivate:
128 case Decl::OMPAllocate:
129 case Decl::OMPCapturedExpr:
130 case Decl::OMPRequires:
133 case Decl::ImplicitConceptSpecialization:
134 case Decl::LifetimeExtendedTemporary:
135 case Decl::RequiresExprBody:
139 case Decl::NamespaceAlias:
141 DI->EmitNamespaceAlias(cast<NamespaceAliasDecl>(
D));
145 DI->EmitUsingDecl(cast<UsingDecl>(
D));
147 case Decl::UsingEnum:
149 DI->EmitUsingEnumDecl(cast<UsingEnumDecl>(
D));
151 case Decl::UsingPack:
152 for (
auto *Using : cast<UsingPackDecl>(
D).expansions())
155 case Decl::UsingDirective:
157 DI->EmitUsingDirective(cast<UsingDirectiveDecl>(
D));
160 case Decl::Decomposition: {
161 const VarDecl &VD = cast<VarDecl>(
D);
163 "Should not see file-scope variables inside a function!");
165 if (
auto *DD = dyn_cast<DecompositionDecl>(&VD))
166 for (
auto *B : DD->bindings())
167 if (
auto *HD = B->getHoldingVar())
172 case Decl::OMPDeclareReduction:
175 case Decl::OMPDeclareMapper:
179 case Decl::TypeAlias: {
180 QualType Ty = cast<TypedefNameDecl>(
D).getUnderlyingType();
182 DI->EmitAndRetainType(Ty);
193 if (
D.hasExternalStorage())
202 if (
D.getType()->isSamplerT())
205 llvm::GlobalValue::LinkageTypes
Linkage =
218 assert(
D.hasLocalStorage());
227 assert(!
D.isExternallyVisible() &&
"name shouldn't matter");
228 std::string ContextName;
230 if (
auto *CD = dyn_cast<CapturedDecl>(DC))
231 DC = cast<DeclContext>(CD->getNonClosureContext());
232 if (
const auto *FD = dyn_cast<FunctionDecl>(DC))
234 else if (
const auto *BD = dyn_cast<BlockDecl>(DC))
236 else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(DC))
237 ContextName = OMD->getSelector().getAsString();
239 llvm_unreachable(
"Unknown context for static var decl");
241 ContextName +=
"." +
D.getNameAsString();
251 if (llvm::Constant *ExistingGV = StaticLocalDeclMap[&
D])
270 llvm::Constant *
Init =
nullptr;
273 Init = llvm::UndefValue::get(LTy);
277 llvm::GlobalVariable *GV =
new llvm::GlobalVariable(
279 nullptr, llvm::GlobalVariable::NotThreadLocal, TargetAS);
280 GV->setAlignment(
getContext().getDeclAlign(&
D).getAsAlign());
283 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
293 llvm::Constant *Addr = GV;
294 if (AS != ExpectedAS) {
296 *
this, GV, AS, ExpectedAS,
298 getContext().getTargetAddressSpace(ExpectedAS)));
309 if (isa<BlockDecl>(DC) || isa<CapturedDecl>(DC)) {
317 if (
const auto *CD = dyn_cast<CXXConstructorDecl>(DC))
319 else if (
const auto *DD = dyn_cast<CXXDestructorDecl>(DC))
321 else if (
const auto *FD = dyn_cast<FunctionDecl>(DC))
326 assert(isa<ObjCMethodDecl>(DC) &&
"unexpected parent code decl");
341llvm::GlobalVariable *
343 llvm::GlobalVariable *GV) {
345 llvm::Constant *
Init = emitter.tryEmitForInitializer(
D);
357 GV->setConstant(
false);
369 assert(VarSize == CstSize &&
"Emitted constant has unexpected size");
376 D.getType().isConstantStorage(
getContext(),
true, !NeedsDtor));
377 GV->replaceInitializer(
Init);
379 emitter.finalize(GV);
392 llvm::GlobalValue::LinkageTypes
Linkage) {
402 setAddrOfLocalVar(&
D,
Address(addr, elemTy, alignment));
407 if (
D.getType()->isVariablyModifiedType())
411 llvm::Type *expectedType = addr->getType();
413 llvm::GlobalVariable *
var =
414 cast<llvm::GlobalVariable>(addr->stripPointerCasts());
423 if (
D.getInit() && !isCudaSharedVar)
431 if (
auto *SA =
D.
getAttr<PragmaClangBSSSectionAttr>())
432 var->addAttribute(
"bss-section", SA->getName());
433 if (
auto *SA =
D.
getAttr<PragmaClangDataSectionAttr>())
434 var->addAttribute(
"data-section", SA->getName());
435 if (
auto *SA =
D.
getAttr<PragmaClangRodataSectionAttr>())
436 var->addAttribute(
"rodata-section", SA->getName());
437 if (
auto *SA =
D.
getAttr<PragmaClangRelroSectionAttr>())
438 var->addAttribute(
"relro-section", SA->getName());
440 if (
const SectionAttr *SA =
D.
getAttr<SectionAttr>())
441 var->setSection(SA->getName());
456 llvm::Constant *castedAddr =
457 llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(var, expectedType);
458 LocalDeclMap.find(&
D)->second =
Address(castedAddr, elemTy, alignment);
474 CodeGenFunction::Destroyer *destroyer,
475 bool useEHCleanupForArray)
476 : addr(addr),
type(
type), destroyer(destroyer),
477 useEHCleanupForArray(useEHCleanupForArray) {}
481 CodeGenFunction::Destroyer *destroyer;
482 bool useEHCleanupForArray;
486 bool useEHCleanupForArray =
487 flags.isForNormalCleanup() && this->useEHCleanupForArray;
493 template <
class Derived>
496 : NRVOFlag(NRVOFlag),
Loc(addr), Ty(
type) {}
498 llvm::Value *NRVOFlag;
504 bool NRVO = flags.isForNormalCleanup() && NRVOFlag;
506 llvm::BasicBlock *SkipDtorBB =
nullptr;
511 llvm::Value *DidNRVO =
513 CGF.
Builder.CreateCondBr(DidNRVO, SkipDtorBB, RunDtorBB);
517 static_cast<Derived *
>(
this)->emitDestructorCall(CGF);
522 virtual ~DestroyNRVOVariable() =
default;
525 struct DestroyNRVOVariableCXX final
526 : DestroyNRVOVariable<DestroyNRVOVariableCXX> {
529 : DestroyNRVOVariable<DestroyNRVOVariableCXX>(addr,
type, NRVOFlag),
541 struct DestroyNRVOVariableC final
542 : DestroyNRVOVariable<DestroyNRVOVariableC> {
544 : DestroyNRVOVariable<DestroyNRVOVariableC>(addr, Ty, NRVOFlag) {}
553 CallStackRestore(
Address Stack) : Stack(Stack) {}
554 bool isRedundantBeforeReturn()
override {
return true; }
562 std::pair<llvm::Value *, llvm::Value *> AddrSizePair;
563 KmpcAllocFree(
const std::pair<llvm::Value *, llvm::Value *> &AddrSizePair)
564 : AddrSizePair(AddrSizePair) {}
573 ExtendGCLifetime(
const VarDecl *var) : Var(*
var) {}
587 llvm::Constant *CleanupFn;
591 CallCleanupFunction(llvm::Constant *CleanupFn,
const CGFunctionInfo *Info,
593 : CleanupFn(CleanupFn), FnInfo(*Info), Var(*Var) {}
628 llvm_unreachable(
"present but none");
636 (var.hasAttr<ObjCPreciseLifetimeAttr>()
641 CGF.
pushDestroy(cleanupKind, addr, var.getType(), destroyer,
660 if (
const Expr *e = dyn_cast<Expr>(
s)) {
663 s = e = e->IgnoreParenCasts();
665 if (
const DeclRefExpr *ref = dyn_cast<DeclRefExpr>(e))
666 return (ref->getDecl() == &var);
667 if (
const BlockExpr *be = dyn_cast<BlockExpr>(e)) {
668 const BlockDecl *block = be->getBlockDecl();
669 for (
const auto &I : block->
captures()) {
670 if (I.getVariable() == &var)
676 for (
const Stmt *SubStmt :
s->children())
685 if (!
decl)
return false;
686 if (!isa<VarDecl>(
decl))
return false;
693 bool needsCast =
false;
700 case CK_BlockPointerToObjCPointerCast:
706 case CK_LValueToRValue: {
748 if (!
SanOpts.
has(SanitizerKind::NullabilityAssign))
757 SanitizerScope SanScope(
this);
759 llvm::Constant *StaticData[] = {
761 llvm::ConstantInt::get(
Int8Ty, 0),
764 SanitizerHandler::TypeMismatch, StaticData, RHS);
768 LValue lvalue,
bool capturedByInit) {
780 init = DIE->getExpr();
784 if (
auto *EWC = dyn_cast<ExprWithCleanups>(init)) {
785 CodeGenFunction::RunCleanupsScope
Scope(*
this);
793 bool accessedByInit =
false;
796 if (accessedByInit) {
799 if (capturedByInit) {
820 llvm::Value *value =
nullptr;
824 llvm_unreachable(
"present but none");
827 if (!
D || !isa<VarDecl>(
D) || !cast<VarDecl>(
D)->isARCPseudoStrong()) {
886 unsigned &NumStores) {
888 if (isa<llvm::ConstantAggregateZero>(
Init) ||
889 isa<llvm::ConstantPointerNull>(
Init) ||
890 isa<llvm::UndefValue>(
Init))
892 if (isa<llvm::ConstantInt>(
Init) || isa<llvm::ConstantFP>(
Init) ||
893 isa<llvm::ConstantVector>(
Init) || isa<llvm::BlockAddress>(
Init) ||
894 isa<llvm::ConstantExpr>(
Init))
895 return Init->isNullValue() || NumStores--;
898 if (isa<llvm::ConstantArray>(
Init) || isa<llvm::ConstantStruct>(
Init)) {
899 for (
unsigned i = 0, e =
Init->getNumOperands(); i != e; ++i) {
900 llvm::Constant *Elt = cast<llvm::Constant>(
Init->getOperand(i));
907 if (llvm::ConstantDataSequential *CDS =
908 dyn_cast<llvm::ConstantDataSequential>(
Init)) {
909 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
910 llvm::Constant *Elt = CDS->getElementAsConstant(i);
927 assert(!
Init->isNullValue() && !isa<llvm::UndefValue>(
Init) &&
928 "called emitStoresForInitAfterBZero for zero or undef value.");
930 if (isa<llvm::ConstantInt>(
Init) || isa<llvm::ConstantFP>(
Init) ||
931 isa<llvm::ConstantVector>(
Init) || isa<llvm::BlockAddress>(
Init) ||
932 isa<llvm::ConstantExpr>(
Init)) {
933 auto *I = Builder.CreateStore(
Init,
Loc, isVolatile);
935 I->addAnnotationMetadata(
"auto-init");
939 if (llvm::ConstantDataSequential *CDS =
940 dyn_cast<llvm::ConstantDataSequential>(
Init)) {
941 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
942 llvm::Constant *Elt = CDS->getElementAsConstant(i);
945 if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt))
947 CGM, Elt, Builder.CreateConstInBoundsGEP2_32(
Loc, 0, i), isVolatile,
948 Builder, IsAutoInit);
953 assert((isa<llvm::ConstantStruct>(
Init) || isa<llvm::ConstantArray>(
Init)) &&
954 "Unknown value type!");
956 for (
unsigned i = 0, e =
Init->getNumOperands(); i != e; ++i) {
957 llvm::Constant *Elt = cast<llvm::Constant>(
Init->getOperand(i));
960 if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt))
962 Builder.CreateConstInBoundsGEP2_32(
Loc, 0, i),
963 isVolatile, Builder, IsAutoInit);
971 uint64_t GlobalSize) {
973 if (isa<llvm::ConstantAggregateZero>(
Init))
return true;
979 unsigned StoreBudget = 6;
980 uint64_t SizeLimit = 32;
982 return GlobalSize > SizeLimit &&
993 const llvm::DataLayout &DL) {
994 uint64_t SizeLimit = 32;
995 if (GlobalSize <= SizeLimit)
997 return llvm::isBytewiseValue(
Init, DL);
1004 uint64_t GlobalByteSize) {
1006 uint64_t ByteSizeLimit = 64;
1009 if (GlobalByteSize <= ByteSizeLimit)
1019 if (isPattern == IsPattern::Yes)
1022 return llvm::Constant::getNullValue(Ty);
1026 llvm::Constant *constant);
1031 llvm::StructType *STy,
1032 llvm::Constant *constant) {
1034 const llvm::StructLayout *Layout = DL.getStructLayout(STy);
1035 llvm::Type *Int8Ty = llvm::IntegerType::getInt8Ty(CGM.
getLLVMContext());
1036 unsigned SizeSoFar = 0;
1038 bool NestedIntact =
true;
1039 for (
unsigned i = 0, e = STy->getNumElements(); i != e; i++) {
1040 unsigned CurOff = Layout->getElementOffset(i);
1041 if (SizeSoFar < CurOff) {
1042 assert(!STy->isPacked());
1043 auto *PadTy = llvm::ArrayType::get(Int8Ty, CurOff - SizeSoFar);
1046 llvm::Constant *CurOp;
1047 if (constant->isZeroValue())
1048 CurOp = llvm::Constant::getNullValue(STy->getElementType(i));
1050 CurOp = cast<llvm::Constant>(constant->getAggregateElement(i));
1053 NestedIntact =
false;
1054 Values.push_back(NewOp);
1055 SizeSoFar = CurOff + DL.getTypeAllocSize(CurOp->getType());
1057 unsigned TotalSize = Layout->getSizeInBytes();
1058 if (SizeSoFar < TotalSize) {
1059 auto *PadTy = llvm::ArrayType::get(Int8Ty, TotalSize - SizeSoFar);
1062 if (NestedIntact && Values.size() == STy->getNumElements())
1064 return llvm::ConstantStruct::getAnon(Values, STy->isPacked());
1070 llvm::Constant *constant) {
1071 llvm::Type *OrigTy = constant->getType();
1072 if (
const auto STy = dyn_cast<llvm::StructType>(OrigTy))
1074 if (
auto *ArrayTy = dyn_cast<llvm::ArrayType>(OrigTy)) {
1076 uint64_t Size = ArrayTy->getNumElements();
1079 llvm::Type *ElemTy = ArrayTy->getElementType();
1080 bool ZeroInitializer = constant->isNullValue();
1081 llvm::Constant *OpValue, *PaddedOp;
1082 if (ZeroInitializer) {
1083 OpValue = llvm::Constant::getNullValue(ElemTy);
1086 for (
unsigned Op = 0; Op != Size; ++Op) {
1087 if (!ZeroInitializer) {
1088 OpValue = constant->getAggregateElement(Op);
1091 Values.push_back(PaddedOp);
1093 auto *NewElemTy = Values[0]->getType();
1094 if (NewElemTy == ElemTy)
1096 auto *NewArrayTy = llvm::ArrayType::get(NewElemTy, Size);
1097 return llvm::ConstantArray::get(NewArrayTy, Values);
1106 llvm::Constant *Constant,
1108 auto FunctionName = [&](
const DeclContext *DC) -> std::string {
1109 if (
const auto *FD = dyn_cast<FunctionDecl>(DC)) {
1110 if (
const auto *CC = dyn_cast<CXXConstructorDecl>(FD))
1111 return CC->getNameAsString();
1112 if (
const auto *CD = dyn_cast<CXXDestructorDecl>(FD))
1113 return CD->getNameAsString();
1115 }
else if (
const auto *OM = dyn_cast<ObjCMethodDecl>(DC)) {
1116 return OM->getNameAsString();
1117 }
else if (isa<BlockDecl>(DC)) {
1119 }
else if (isa<CapturedDecl>(DC)) {
1120 return "<captured>";
1122 llvm_unreachable(
"expected a function or method");
1128 llvm::GlobalVariable *&CacheEntry = InitializerConstants[&
D];
1129 if (!CacheEntry || CacheEntry->getInitializer() != Constant) {
1130 auto *Ty = Constant->getType();
1131 bool isConstant =
true;
1132 llvm::GlobalVariable *InsertBefore =
nullptr;
1136 if (
D.hasGlobalStorage())
1139 Name = (
"__const." + FunctionName(DC) +
"." +
D.getName()).str();
1141 llvm_unreachable(
"local variable has no parent function or method");
1142 llvm::GlobalVariable *GV =
new llvm::GlobalVariable(
1143 getModule(), Ty, isConstant, llvm::GlobalValue::PrivateLinkage,
1144 Constant, Name, InsertBefore, llvm::GlobalValue::NotThreadLocal, AS);
1146 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
1148 }
else if (CacheEntry->getAlignment() < uint64_t(Align.
getQuantity())) {
1149 CacheEntry->setAlignment(Align.
getAsAlign());
1152 return Address(CacheEntry, CacheEntry->getValueType(), Align);
1158 llvm::Constant *Constant,
1167 llvm::Constant *constant,
bool IsAutoInit) {
1168 auto *Ty = constant->getType();
1169 uint64_t ConstantSize = CGM.
getDataLayout().getTypeAllocSize(Ty);
1173 bool canDoSingleStore = Ty->isIntOrIntVectorTy() ||
1174 Ty->isPtrOrPtrVectorTy() || Ty->isFPOrFPVectorTy();
1175 if (canDoSingleStore) {
1176 auto *I = Builder.CreateStore(constant,
Loc, isVolatile);
1178 I->addAnnotationMetadata(
"auto-init");
1182 auto *SizeVal = llvm::ConstantInt::get(CGM.
IntPtrTy, ConstantSize);
1187 auto *I = Builder.CreateMemSet(
Loc, llvm::ConstantInt::get(CGM.
Int8Ty, 0),
1188 SizeVal, isVolatile);
1190 I->addAnnotationMetadata(
"auto-init");
1192 bool valueAlreadyCorrect =
1193 constant->isNullValue() || isa<llvm::UndefValue>(constant);
1194 if (!valueAlreadyCorrect) {
1195 Loc =
Loc.withElementType(Ty);
1203 llvm::Value *Pattern =
1206 uint64_t
Value = 0x00;
1207 if (!isa<llvm::UndefValue>(Pattern)) {
1208 const llvm::APInt &AP = cast<llvm::ConstantInt>(Pattern)->getValue();
1209 assert(AP.getBitWidth() <= 8);
1210 Value = AP.getLimitedValue();
1212 auto *I = Builder.CreateMemSet(
1213 Loc, llvm::ConstantInt::get(CGM.
Int8Ty,
Value), SizeVal, isVolatile);
1215 I->addAnnotationMetadata(
"auto-init");
1221 bool IsTrivialAutoVarInitPattern =
1225 if (
auto *STy = dyn_cast<llvm::StructType>(Ty)) {
1226 if (STy ==
Loc.getElementType() ||
1227 (STy !=
Loc.getElementType() && IsTrivialAutoVarInitPattern)) {
1228 const llvm::StructLayout *Layout =
1230 for (
unsigned i = 0; i != constant->getNumOperands(); i++) {
1233 Address EltPtr = Builder.CreateConstInBoundsByteGEP(
1234 Loc.withElementType(CGM.
Int8Ty), CurOff);
1236 constant->getAggregateElement(i), IsAutoInit);
1240 }
else if (
auto *ATy = dyn_cast<llvm::ArrayType>(Ty)) {
1241 if (ATy ==
Loc.getElementType() ||
1242 (ATy !=
Loc.getElementType() && IsTrivialAutoVarInitPattern)) {
1243 for (
unsigned i = 0; i != ATy->getNumElements(); i++) {
1244 Address EltPtr = Builder.CreateConstGEP(
1245 Loc.withElementType(ATy->getElementType()), i);
1247 constant->getAggregateElement(i), IsAutoInit);
1256 Builder.CreateMemCpy(
Loc,
1258 CGM,
D, Builder, constant,
Loc.getAlignment()),
1259 SizeVal, isVolatile);
1261 I->addAnnotationMetadata(
"auto-init");
1267 llvm::Type *ElTy =
Loc.getElementType();
1268 llvm::Constant *constant =
1277 llvm::Type *ElTy =
Loc.getElementType();
1280 assert(!isa<llvm::UndefValue>(constant));
1286 auto *Ty = constant->getType();
1287 if (isa<llvm::UndefValue>(constant))
1289 if (Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy())
1290 for (llvm::Use &Op : constant->operands())
1297 llvm::Constant *constant) {
1298 auto *Ty = constant->getType();
1299 if (isa<llvm::UndefValue>(constant))
1301 if (!(Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy()))
1306 for (
unsigned Op = 0, NumOp = constant->getNumOperands(); Op != NumOp; ++Op) {
1307 auto *OpValue = cast<llvm::Constant>(constant->getOperand(Op));
1310 if (Ty->isStructTy())
1311 return llvm::ConstantStruct::get(cast<llvm::StructType>(Ty), Values);
1312 if (Ty->isArrayTy())
1313 return llvm::ConstantArray::get(cast<llvm::ArrayType>(Ty), Values);
1314 assert(Ty->isVectorTy());
1315 return llvm::ConstantVector::get(Values);
1331 llvm::Value *Addr) {
1332 if (!ShouldEmitLifetimeMarkers)
1335 assert(Addr->getType()->getPointerAddressSpace() ==
1337 "Pointer should be in alloca address space");
1338 llvm::Value *SizeV = llvm::ConstantInt::get(
1342 C->setDoesNotThrow();
1347 assert(Addr->getType()->getPointerAddressSpace() ==
1349 "Pointer should be in alloca address space");
1352 C->setDoesNotThrow();
1364 while (
getContext().getAsVariableArrayType(Type1D)) {
1366 if (
auto *
C = dyn_cast<llvm::ConstantInt>(VlaSize.NumElts))
1370 Twine Name = Twine(
"__vla_expr") + Twine(VLAExprCounter++);
1372 StringRef NameRef = Name.toStringRef(Buffer);
1374 VLAExprNames.push_back(&Ident);
1378 Dimensions.emplace_back(SizeExprAddr.getPointer(),
1381 Type1D = VlaSize.Type;
1390 unsigned NameIdx = 0;
1391 for (
auto &VlaSize : Dimensions) {
1393 if (
auto *
C = dyn_cast<llvm::ConstantInt>(VlaSize.NumElts))
1394 MD = llvm::ConstantAsMetadata::get(
C);
1399 SizeTy->getScalarSizeInBits(),
false);
1404 ArtificialDecl->setImplicit();
1409 assert(MD &&
"No Size expression debug node created");
1416CodeGenFunction::AutoVarEmission
1423 AutoVarEmission emission(
D);
1425 bool isEscapingByRef =
D.isEscapingByref();
1426 emission.IsEscapingByRef = isEscapingByRef;
1448 bool NRVO =
getLangOpts().ElideConstructors &&
D.isNRVOVariable();
1451 address = OpenMPLocalAddr;
1452 AllocaAddr = OpenMPLocalAddr;
1465 getContext().getBaseElementType(Ty)->isObjCObjectPointerType()) &&
1466 D.getInit()->isConstantInitializer(
getContext(),
false)))) {
1484 assert(emission.wasEmittedAsGlobal());
1489 emission.IsConstantAggregate =
true;
1507 const auto *RD = RecordTy->getDecl();
1508 const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1509 if ((CXXRD && !CXXRD->hasTrivialDestructor()) ||
1510 RD->isNonTrivialToPrimitiveDestroy()) {
1527 llvm::Type *allocaTy;
1528 if (isEscapingByRef) {
1530 allocaTy = byrefInfo.Type;
1531 allocaAlignment = byrefInfo.ByrefAlignment;
1534 allocaAlignment = alignment;
1541 nullptr, &AllocaAddr);
1546 bool IsMSCatchParam =
1568 emission.SizeForLifetimeMarkers =
1572 assert(!emission.useLifetimeMarkers());
1583 bool VarAllocated =
false;
1586 if (RT.isDelayedVariableLengthDecl(*
this, &
D)) {
1588 std::pair<llvm::Value *, llvm::Value *> AddrSizePair =
1595 address =
Base.getAddress();
1603 VarAllocated =
true;
1607 if (!VarAllocated) {
1608 if (!DidCallStackSave) {
1613 llvm::Value *
V =
Builder.CreateStackSave();
1617 DidCallStackSave =
true;
1638 setAddrOfLocalVar(&
D, address);
1639 emission.Addr = address;
1640 emission.AllocaAddr = AllocaAddr;
1649 if (UsePointerValue) {
1661 if (emission.useLifetimeMarkers())
1663 emission.getOriginalAllocatedAddress(),
1664 emission.getSizeForLifetimeMarkers());
1674 if (
const Expr *
E = dyn_cast<Expr>(S))
1676 for (
const Stmt *SubStmt : S->children())
1689 if (
const BlockExpr *BE = dyn_cast<BlockExpr>(
E)) {
1691 for (
const auto &I :
Block->captures()) {
1692 if (I.getVariable() == &Var)
1700 if (
const StmtExpr *SE = dyn_cast<StmtExpr>(
E)) {
1702 for (
const auto *BI : CS->
body())
1703 if (
const auto *BIE = dyn_cast<Expr>(BI)) {
1707 else if (
const auto *DS = dyn_cast<DeclStmt>(BI)) {
1709 for (
const auto *I : DS->decls()) {
1710 if (
const auto *VD = dyn_cast<VarDecl>((I))) {
1741 !Construct->requiresZeroInitialization())
1747void CodeGenFunction::emitZeroOrPatternForAutoVarInit(
QualType type,
1751 auto trivialAutoVarInitMaxSize =
1754 bool isVolatile =
type.isVolatileQualified();
1755 if (!
Size.isZero()) {
1762 switch (trivialAutoVarInit) {
1764 llvm_unreachable(
"Uninitialized handled by caller");
1768 if (trivialAutoVarInitMaxSize > 0 &&
1769 allocSize > trivialAutoVarInitMaxSize)
1776 if (trivialAutoVarInitMaxSize > 0 &&
1777 allocSize > trivialAutoVarInitMaxSize)
1794 auto SizeVal = VlaSize.NumElts;
1796 switch (trivialAutoVarInit) {
1798 llvm_unreachable(
"Uninitialized handled by caller");
1803 if (!EltSize.
isOne())
1806 SizeVal, isVolatile);
1807 I->addAnnotationMetadata(
"auto-init");
1814 llvm::Type *ElTy =
Loc.getElementType();
1821 llvm::Value *IsZeroSizedVLA =
Builder.CreateICmpEQ(
1822 SizeVal, llvm::ConstantInt::get(SizeVal->getType(), 0),
1824 Builder.CreateCondBr(IsZeroSizedVLA, ContBB, SetupBB);
1826 if (!EltSize.
isOne())
1828 llvm::Value *BaseSizeInChars =
1832 Begin.emitRawPointer(*
this),
1833 SizeVal,
"vla.end");
1834 llvm::BasicBlock *OriginBB =
Builder.GetInsertBlock();
1836 llvm::PHINode *Cur =
Builder.CreatePHI(
Begin.getType(), 2,
"vla.cur");
1837 Cur->addIncoming(
Begin.emitRawPointer(*
this), OriginBB);
1838 CharUnits CurAlign =
Loc.getAlignment().alignmentOfArrayElement(EltSize);
1843 BaseSizeInChars, isVolatile);
1844 I->addAnnotationMetadata(
"auto-init");
1847 llvm::Value *Done =
Builder.CreateICmpEQ(Next, End,
"vla-init.isdone");
1848 Builder.CreateCondBr(Done, ContBB, LoopBB);
1849 Cur->addIncoming(Next, LoopBB);
1856 assert(emission.Variable &&
"emission was not valid!");
1859 if (emission.wasEmittedAsGlobal())
return;
1861 const VarDecl &
D = *emission.Variable;
1876 if (emission.IsEscapingByRef)
1883 type.isNonTrivialToPrimitiveDefaultInitialize() ==
1886 if (emission.IsEscapingByRef)
1895 bool capturedByInit =
1898 bool locIsByrefHeader = !capturedByInit;
1900 locIsByrefHeader ? emission.getObjectAddress(*
this) : emission.Addr;
1902 auto hasNoTrivialAutoVarInitAttr = [&](
const Decl *
D) {
1903 return D &&
D->
hasAttr<NoTrivialAutoVarInitAttr>();
1907 ((
D.isConstexpr() ||
D.
getAttr<UninitializedAttr>() ||
1908 hasNoTrivialAutoVarInitAttr(
type->getAsTagDecl()) ||
1913 auto initializeWhatIsTechnicallyUninitialized = [&](
Address Loc) {
1914 if (trivialAutoVarInit ==
1919 if (emission.IsEscapingByRef && !locIsByrefHeader)
1922 return emitZeroOrPatternForAutoVarInit(
type,
D,
Loc);
1926 return initializeWhatIsTechnicallyUninitialized(
Loc);
1928 llvm::Constant *constant =
nullptr;
1929 if (emission.IsConstantAggregate ||
1930 D.mightBeUsableInConstantExpressions(
getContext())) {
1931 assert(!capturedByInit &&
"constant init contains a capturing block?");
1933 if (constant && !constant->isZeroValue() &&
1934 (trivialAutoVarInit !=
1950 if (constant &&
type->isBitIntType() &&
1955 llvm::Type *LoadType =
1957 constant = llvm::ConstantFoldLoadFromConst(
1963 if (trivialAutoVarInit !=
1974 initializeWhatIsTechnicallyUninitialized(
Loc);
1982 if (!emission.IsConstantAggregate) {
2005 LValue lvalue,
bool capturedByInit) {
2008 if (
type->isReferenceType()) {
2027 if (
type->isAtomicType()) {
2031 if (isa<VarDecl>(
D))
2033 else if (
auto *FD = dyn_cast<FieldDecl>(
D))
2043 llvm_unreachable(
"bad evaluation kind");
2048 const CodeGenFunction::AutoVarEmission &emission,
2054 Address addr = emission.getObjectAddress(*
this);
2064 llvm_unreachable(
"no cleanup for trivially-destructible variable");
2069 if (emission.NRVOFlag) {
2070 assert(!
type->isArrayType());
2072 EHStack.pushCleanup<DestroyNRVOVariableCXX>(cleanupKind, addr,
type, dtor,
2080 if (
var->isARCPseudoStrong())
return;
2086 if (!
var->hasAttr<ObjCPreciseLifetimeAttr>())
2095 if (emission.NRVOFlag) {
2096 assert(!
type->isArrayType());
2097 EHStack.pushCleanup<DestroyNRVOVariableC>(cleanupKind, addr,
2098 emission.NRVOFlag,
type);
2109 bool useEHCleanup = (cleanupKind &
EHCleanup);
2110 EHStack.pushCleanup<DestroyObject>(cleanupKind, addr,
type, destroyer,
2115 assert(emission.Variable &&
"emission was not valid!");
2118 if (emission.wasEmittedAsGlobal())
return;
2124 const VarDecl &
D = *emission.Variable;
2132 D.
hasAttr<ObjCPreciseLifetimeAttr>()) {
2137 if (
const CleanupAttr *CA =
D.
getAttr<CleanupAttr>()) {
2141 assert(F &&
"Could not find function!");
2150 if (emission.IsEscapingByRef &&
2153 if (emission.Variable->getType().isObjCGCWeak())
2174 llvm_unreachable(
"Unknown DestructionKind");
2181 assert(dtorKind &&
"cannot push destructor for trivial type");
2191 assert(dtorKind &&
"cannot push destructor for trivial type");
2200 bool useEHCleanupForArray) {
2201 pushFullExprCleanup<DestroyObject>(cleanupKind, addr,
type,
2202 destroyer, useEHCleanupForArray);
2209 assert(dtorKind &&
"cannot push destructor for trivial type");
2218 bool useEHCleanupForArray) {
2219 llvm::Instruction *DominatingIP =
2221 pushDestroy(cleanupKind, addr,
type, destroyer, useEHCleanupForArray);
2227 EHStack.pushCleanup<CallStackRestore>(
Kind, SPMem);
2231 CleanupKind Kind, std::pair<llvm::Value *, llvm::Value *> AddrSizePair) {
2232 EHStack.pushCleanup<KmpcAllocFree>(
Kind, AddrSizePair);
2237 Destroyer *destroyer,
2238 bool useEHCleanupForArray) {
2248 useEHCleanupForArray);
2252 return pushCleanupAfterFullExprWithActiveFlag<DestroyObject>(
2254 useEHCleanupForArray);
2259 using ConditionalCleanupType =
2266 AllocaTrackerRAII DeactivationAllocas(*
this);
2269 pushCleanupAndDeferDeactivation<ConditionalCleanupType>(
2270 cleanupKind, SavedAddr,
type, destroyer, useEHCleanupForArray);
2274 cleanup.AddAuxAllocas(std::move(DeactivationAllocas).Take());
2282 pushCleanupAfterFullExprWithActiveFlag<ConditionalCleanupType>(
2283 cleanupKind, ActiveFlagForLifetimeExt, SavedAddr,
type, destroyer,
2284 useEHCleanupForArray);
2299 Destroyer *destroyer,
2300 bool useEHCleanupForArray) {
2303 return destroyer(*
this, addr,
type);
2312 bool checkZeroLength =
true;
2315 if (llvm::ConstantInt *constLength = dyn_cast<llvm::ConstantInt>(
length)) {
2317 if (constLength->isZero())
return;
2318 checkZeroLength =
false;
2325 checkZeroLength, useEHCleanupForArray);
2342 Destroyer *destroyer,
2343 bool checkZeroLength,
2344 bool useEHCleanup) {
2352 if (checkZeroLength) {
2353 llvm::Value *isEmpty =
Builder.CreateICmpEQ(begin, end,
2354 "arraydestroy.isempty");
2355 Builder.CreateCondBr(isEmpty, doneBB, bodyBB);
2359 llvm::BasicBlock *entryBB =
Builder.GetInsertBlock();
2361 llvm::PHINode *elementPast =
2362 Builder.CreatePHI(begin->getType(), 2,
"arraydestroy.elementPast");
2363 elementPast->addIncoming(end, entryBB);
2366 llvm::Value *negativeOne = llvm::ConstantInt::get(
SizeTy, -1,
true);
2369 llvmElementType, elementPast, negativeOne,
"arraydestroy.element");
2376 destroyer(*
this,
Address(element, llvmElementType, elementAlign),
2383 llvm::Value *done =
Builder.CreateICmpEQ(element, begin,
"arraydestroy.done");
2384 Builder.CreateCondBr(done, doneBB, bodyBB);
2385 elementPast->addIncoming(element,
Builder.GetInsertBlock());
2394 llvm::Value *begin, llvm::Value *end,
2400 unsigned arrayDepth = 0;
2409 llvm::Value *zero = llvm::ConstantInt::get(CGF.
SizeTy, 0);
2413 elemTy, begin, gepIndices,
"pad.arraybegin");
2415 elemTy, end, gepIndices,
"pad.arrayend");
2430 llvm::Value *ArrayBegin;
2431 llvm::Value *ArrayEnd;
2433 CodeGenFunction::Destroyer *Destroyer;
2436 RegularPartialArrayDestroy(llvm::Value *arrayBegin, llvm::Value *arrayEnd,
2438 CodeGenFunction::Destroyer *destroyer)
2439 : ArrayBegin(arrayBegin), ArrayEnd(arrayEnd),
2440 ElementType(elementType), Destroyer(destroyer),
2441 ElementAlign(elementAlign) {}
2445 ElementType, ElementAlign, Destroyer);
2453 llvm::Value *ArrayBegin;
2456 CodeGenFunction::Destroyer *Destroyer;
2459 IrregularPartialArrayDestroy(llvm::Value *arrayBegin,
2463 CodeGenFunction::Destroyer *destroyer)
2464 : ArrayBegin(arrayBegin), ArrayEndPointer(arrayEndPointer),
2465 ElementType(elementType), Destroyer(destroyer),
2466 ElementAlign(elementAlign) {}
2471 ElementType, ElementAlign, Destroyer);
2486 Destroyer *destroyer) {
2487 pushFullExprCleanup<IrregularPartialArrayDestroy>(
2489 elementAlign, destroyer);
2499 llvm::Value *arrayEnd,
2502 Destroyer *destroyer) {
2503 pushFullExprCleanup<RegularPartialArrayDestroy>(
EHCleanup,
2504 arrayBegin, arrayEnd,
2505 elementType, elementAlign,
2511 if (LifetimeStartFn)
2512 return LifetimeStartFn;
2513 LifetimeStartFn = llvm::Intrinsic::getOrInsertDeclaration(
2515 return LifetimeStartFn;
2521 return LifetimeEndFn;
2522 LifetimeEndFn = llvm::Intrinsic::getOrInsertDeclaration(
2524 return LifetimeEndFn;
2533 ConsumeARCParameter(llvm::Value *param,
2535 : Param(param), Precise(precise) {}
2550 bool NoDebugInfo =
false;
2552 assert((isa<ParmVarDecl>(
D) || isa<ImplicitParamDecl>(
D)) &&
2553 "Invalid argument to EmitParmDecl");
2557 if (!isa<llvm::GlobalValue>(Arg.getAnyValue()))
2558 Arg.getAnyValue()->setName(
D.getName());
2563 if (
auto IPD = dyn_cast<ImplicitParamDecl>(&
D)) {
2567 llvm::Value *
V = Arg.isIndirect()
2569 : Arg.getDirectValue();
2581 bool DoStore =
false;
2583 bool UseIndirectDebugAddress =
false;
2586 if (Arg.isIndirect()) {
2587 DeclPtr = Arg.getIndirectAddress();
2600 if (UseIndirectDebugAddress) {
2603 D.getName() +
".indirect_addr");
2610 if (SrcLangAS != DestLangAS) {
2611 assert(
getContext().getTargetAddressSpace(SrcLangAS) ==
2617 *
this,
V, SrcLangAS, DestLangAS,
T,
true),
2630 "unexpected destructor type");
2632 CalleeDestructedParamCleanups[cast<ParmVarDecl>(&
D)] =
2643 DeclPtr = OpenMPLocalAddr;
2644 AllocaPtr = DeclPtr;
2648 D.getName() +
".addr", &AllocaPtr);
2653 llvm::Value *ArgVal = (DoStore ? Arg.getDirectValue() :
nullptr);
2663 bool isConsumed =
D.
hasAttr<NSConsumedAttr>();
2666 if (
D.isARCPseudoStrong()) {
2668 "pseudo-strong variable isn't strong?");
2669 assert(qs.
hasConst() &&
"pseudo-strong variable should be const!");
2674 if (Arg.isIndirect() && !ArgVal)
2718 setAddrOfLocalVar(&
D, DeclPtr);
2726 if (
const auto *Var = dyn_cast_or_null<ParmVarDecl>(&
D))
2737 if (requiresReturnValueNullabilityCheck()) {
2740 SanitizerScope SanScope(
this);
2741 RetValNullabilityPrecondition =
2742 Builder.CreateAnd(RetValNullabilityPrecondition,
2743 Builder.CreateIsNotNull(Arg.getAnyValue()));
2750 if (!LangOpts.OpenMP || (!LangOpts.EmitAllDecls && !
D->
isUsed()))
2757 if (!LangOpts.OpenMP || LangOpts.OpenMPSimd ||
2758 (!LangOpts.EmitAllDecls && !
D->
isUsed()))
2768 for (
const Expr *
E :
D->varlist()) {
2769 const auto *DE = cast<DeclRefExpr>(
E);
2770 const auto *VD = cast<VarDecl>(DE->getDecl());
2793 if (Entry->getType()->getAddressSpace() == TargetAS)
2798 llvm::PointerType *PTy = llvm::PointerType::get(Ty, TargetAS);
2803 llvm::GlobalVariable *DummyGV =
new llvm::GlobalVariable(
2804 getModule(), Entry->getValueType(),
false,
2805 llvm::GlobalValue::CommonLinkage,
nullptr,
"dummy",
nullptr,
2806 llvm::GlobalVariable::NotThreadLocal, Entry->getAddressSpace());
2807 Entry->replaceAllUsesWith(DummyGV);
2809 Entry->mutateType(PTy);
2810 llvm::Constant *NewPtrForOldDecl =
2811 llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
2812 Entry, DummyGV->getType());
2816 DummyGV->replaceAllUsesWith(NewPtrForOldDecl);
2817 DummyGV->eraseFromParent();
2821std::optional<CharUnits>
2823 if (
const auto *AA = VD->
getAttr<OMPAllocateDeclAttr>()) {
2824 if (
Expr *Alignment = AA->getAlignment()) {
2825 unsigned UserAlign =
2826 Alignment->EvaluateKnownConstInt(
getContext()).getExtValue();
2834 std::max<unsigned>(UserAlign, NaturalAlign.
getQuantity()));
2837 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)
__device__ __2f16 float __ockl_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
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
CharUnits getAlignment() const
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.
Address withElementType(llvm::Type *ElemTy) const
Return address with different element type, but same pointer and alignment.
KnownNonNull_t isKnownNonNull() const
Whether the pointer is known not to be null.
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)
static ApplyDebugLocation CreateDefaultArtificial(CodeGenFunction &CGF, SourceLocation TemporaryLocation)
Apply TemporaryLocation if it is valid.
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
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)
Address CreateInBoundsGEP(Address Addr, ArrayRef< llvm::Value * > IdxList, llvm::Type *ElementType, CharUnits Align, const Twine &Name="")
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...
virtual void getKmpcFreeShared(CodeGenFunction &CGF, const std::pair< llvm::Value *, llvm::Value * > &AddrSizePair)
Get call to __kmpc_free_shared.
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 std::pair< llvm::Value *, llvm::Value * > getKmpcAllocShared(CodeGenFunction &CGF, const VarDecl *VD)
Get call to __kmpc_alloc_shared.
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.
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.
RawAddress createCleanupActiveFlag()
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)
RawAddress CreateDefaultAlignTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
CreateDefaultAlignedTempAlloca - This creates an alloca with the default ABI alignment of the given L...
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::SmallVector< DeferredDeactivateCleanup > DeferredDeactivationCleanupStack
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.
void pushDestroyAndDeferDeactivation(QualType::DestructionKind dtorKind, Address addr, QualType type)
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)
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)
RawAddress CreateMemTemp(QualType T, const Twine &Name="tmp", RawAddress *Alloca=nullptr)
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen and cas...
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 initFullExprCleanupWithFlag(RawAddress ActiveFlag)
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.
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.
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **CallOrInvoke, bool IsMustTail, SourceLocation Loc, bool IsVirtualFunctionPointerThunk=false)
EmitCall - Generate a call of the given function, expecting the given result 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...
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)
const Decl * CurFuncDecl
CurFuncDecl - Holds the Decl for the current outermost non-closure context.
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...
void PopCleanupBlock(bool FallThroughIsBranchThrough=false, bool ForDeactivation=false)
PopCleanupBlock - Will pop the cleanup entry on the stack and process all branch fixups.
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
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 pushKmpcAllocFree(CleanupKind Kind, std::pair< llvm::Value *, llvm::Value * > AddrSizePair)
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::LLVMContext & getLLVMContext()
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.
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.
llvm::GlobalValue::LinkageTypes getLLVMLinkageVarDefinition(const VarDecl *VD)
Returns LLVM linkage for a declarator.
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.
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::ConstantInt * getSize(CharUnits numChars)
Emit the given number of characters as a value of type size_t.
llvm::Type * convertTypeForLoadStore(QualType T, llvm::Type *LLVMTy=nullptr)
Given that T is a scalar type, return the IR type that should be used for load and store operations.
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
bool typeRequiresSplitIntoByteArray(QualType ASTTy, llvm::Type *LLVMTy=nullptr)
Check whether the given type needs to be laid out in memory using an opaque byte-array type because i...
const CGFunctionInfo & arrangeFunctionDeclaration(const FunctionDecl *FD)
Free functions are functions that are compatible with an ordinary C function pointer type.
llvm::Constant * tryEmitAbstractForInitializer(const VarDecl &D)
Try to emit the initializer of the given declaration as an abstract constant.
A cleanup scope which generates the cleanup blocks lazily.
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.
iterator begin() const
Returns an iterator pointing to the innermost EH scope.
LValue - This represents an lvalue references.
llvm::Value * getPointer(CodeGenFunction &CGF) const
Address getAddress() 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)
An abstract representation of an aligned address.
llvm::Value * getPointer() const
static RawAddress invalid()
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
Address performAddrSpaceCast(CodeGen::CodeGenFunction &CGF, Address Addr, LangAS SrcAddr, LangAS DestAddr, llvm::Type *DestTy, bool IsNonNull=false) const
virtual void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const
setTargetAttributes - Provides a convenient hook to handle extra target-specific attributes for the g...
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.
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.
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 isConstantStorage(const ASTContext &Ctx, bool ExcludeCtor, bool ExcludeDtor)
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 hasGlobalStorage() const
Returns true for all variables that do not have local storage.
const Expr * getInit() const
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
Defines the clang::TargetInfo interface.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
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.
constexpr Variable var(Literal L)
Returns the variable of L.
bool Null(InterpState &S, CodePtr OpPC, uint64_t Value, const Descriptor *Desc)
bool Zero(InterpState &S, CodePtr OpPC)
The JSON file list parser is used to communicate input to InstallAPI.
@ 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.
@ 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.
const FunctionProtoType * T
@ ThreadPrivateVar
Parameter for Thread private variable.
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
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.