27 #include "llvm/IR/DataLayout.h"
28 #include "llvm/IR/GlobalVariable.h"
29 #include "llvm/IR/Intrinsics.h"
30 #include "llvm/IR/Type.h"
31 using namespace clang;
32 using namespace CodeGen;
37 case Decl::TranslationUnit:
38 case Decl::ExternCContext:
40 case Decl::UnresolvedUsingTypename:
41 case Decl::ClassTemplateSpecialization:
42 case Decl::ClassTemplatePartialSpecialization:
43 case Decl::VarTemplateSpecialization:
44 case Decl::VarTemplatePartialSpecialization:
45 case Decl::TemplateTypeParm:
46 case Decl::UnresolvedUsingValue:
47 case Decl::NonTypeTemplateParm:
49 case Decl::CXXConstructor:
50 case Decl::CXXDestructor:
51 case Decl::CXXConversion:
53 case Decl::MSProperty:
54 case Decl::IndirectField:
56 case Decl::ObjCAtDefsField:
58 case Decl::ImplicitParam:
59 case Decl::ClassTemplate:
60 case Decl::VarTemplate:
61 case Decl::FunctionTemplate:
62 case Decl::TypeAliasTemplate:
63 case Decl::TemplateTemplateParm:
64 case Decl::ObjCMethod:
65 case Decl::ObjCCategory:
66 case Decl::ObjCProtocol:
67 case Decl::ObjCInterface:
68 case Decl::ObjCCategoryImpl:
69 case Decl::ObjCImplementation:
70 case Decl::ObjCProperty:
71 case Decl::ObjCCompatibleAlias:
72 case Decl::AccessSpec:
73 case Decl::LinkageSpec:
74 case Decl::ObjCPropertyImpl:
75 case Decl::FileScopeAsm:
77 case Decl::FriendTemplate:
80 case Decl::ClassScopeFunctionSpecialization:
81 case Decl::UsingShadow:
82 case Decl::ObjCTypeParam:
83 llvm_unreachable(
"Declaration should not be in declstmts!");
87 case Decl::EnumConstant:
89 case Decl::StaticAssert:
92 case Decl::OMPThreadPrivate:
97 case Decl::NamespaceAlias:
99 DI->EmitNamespaceAlias(cast<NamespaceAliasDecl>(D));
103 DI->EmitUsingDecl(cast<UsingDecl>(D));
105 case Decl::UsingDirective:
107 DI->EmitUsingDirective(cast<UsingDirectiveDecl>(D));
110 const VarDecl &VD = cast<VarDecl>(D);
112 "Should not see file-scope variables inside a function!");
117 case Decl::TypeAlias: {
121 if (Ty->isVariablyModifiedType())
131 llvm::GlobalValue::LinkageTypes
Linkage =
158 std::string ContextName;
160 if (
auto *CD = dyn_cast<CapturedDecl>(DC))
161 DC = cast<DeclContext>(CD->getNonClosureContext());
162 if (
const auto *FD = dyn_cast<FunctionDecl>(DC))
164 else if (
const auto *BD = dyn_cast<BlockDecl>(DC))
166 else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(DC))
167 ContextName = OMD->getSelector().getAsString();
169 llvm_unreachable(
"Unknown context for static var decl");
181 if (llvm::Constant *ExistingGV = StaticLocalDeclMap[&D])
189 if (D.hasAttr<AsmLabelAttr>())
199 llvm::Constant *Init =
nullptr;
203 Init = llvm::UndefValue::get(LTy);
205 llvm::GlobalVariable *GV =
206 new llvm::GlobalVariable(
getModule(), LTy,
209 llvm::GlobalVariable::NotThreadLocal,
211 GV->setAlignment(
getContext().getDeclAlign(&D).getQuantity());
215 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
220 if (D.isExternallyVisible()) {
221 if (D.hasAttr<DLLImportAttr>())
222 GV->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass);
223 else if (D.hasAttr<DLLExportAttr>())
224 GV->setDLLStorageClass(llvm::GlobalVariable::DLLExportStorageClass);
229 llvm::Constant *Addr = GV;
230 if (AddrSpace != ExpectedAddrSpace) {
231 llvm::PointerType *PTy = llvm::PointerType::get(LTy, ExpectedAddrSpace);
232 Addr = llvm::ConstantExpr::getAddrSpaceCast(GV, PTy);
239 const Decl *DC = cast<Decl>(D.getDeclContext());
243 if (isa<BlockDecl>(DC) || isa<CapturedDecl>(DC)) {
251 if (
const auto *CD = dyn_cast<CXXConstructorDecl>(DC))
253 else if (
const auto *DD = dyn_cast<CXXDestructorDecl>(DC))
255 else if (
const auto *FD = dyn_cast<FunctionDecl>(DC))
260 assert(isa<ObjCMethodDecl>(DC) &&
"unexpected parent code decl");
280 llvm::GlobalVariable *
282 llvm::GlobalVariable *GV) {
290 else if (
Builder.GetInsertBlock()) {
293 GV->setConstant(
false);
304 if (GV->getType()->getElementType() != Init->getType()) {
305 llvm::GlobalVariable *OldGV = GV;
307 GV =
new llvm::GlobalVariable(
CGM.
getModule(), Init->getType(),
309 OldGV->getLinkage(), Init,
"",
311 OldGV->getThreadLocalMode(),
313 GV->setVisibility(OldGV->getVisibility());
319 llvm::Constant *NewPtrForOldDecl =
320 llvm::ConstantExpr::getBitCast(GV, OldGV->getType());
321 OldGV->replaceAllUsesWith(NewPtrForOldDecl);
324 OldGV->eraseFromParent();
328 GV->setInitializer(Init);
341 llvm::GlobalValue::LinkageTypes
Linkage) {
343 assert(!DMEntry &&
"Decl already exists in localdeclmap!");
361 llvm::Type *expectedType = addr->getType();
363 llvm::GlobalVariable *var =
364 cast<llvm::GlobalVariable>(addr->stripPointerCasts());
369 var->setAlignment(
getContext().getDeclAlign(&D).getQuantity());
374 if (
const SectionAttr *SA = D.
getAttr<SectionAttr>())
375 var->setSection(SA->getName());
385 llvm::Constant *castedAddr =
386 llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(var, expectedType);
387 DMEntry = castedAddr;
405 bool useEHCleanupForArray)
406 : addr(addr), type(type), destroyer(destroyer),
407 useEHCleanupForArray(useEHCleanupForArray) {}
412 bool useEHCleanupForArray;
416 bool useEHCleanupForArray =
417 flags.isForNormalCleanup() && this->useEHCleanupForArray;
427 : Dtor(Dtor), NRVOFlag(NRVOFlag), Loc(addr) {}
435 bool NRVO = flags.isForNormalCleanup() && NRVOFlag;
437 llvm::BasicBlock *SkipDtorBB =
nullptr;
443 CGF.
Builder.CreateCondBr(DidNRVO, SkipDtorBB, RunDtorBB);
468 ExtendGCLifetime(
const VarDecl *var) : Var(*var) {}
482 llvm::Constant *CleanupFn;
486 CallCleanupFunction(llvm::Constant *CleanupFn,
const CGFunctionInfo *Info,
488 : CleanupFn(CleanupFn), FnInfo(*Info), Var(*Var) {}
503 QualType ArgTy = FnInfo.arg_begin()->type;
520 : Addr(addr), Size(size) {}
535 llvm_unreachable(
"present but none");
543 (var.
hasAttr<ObjCPreciseLifetimeAttr>()
567 if (
const Expr *e = dyn_cast<Expr>(s)) {
570 s = e = e->IgnoreParenCasts();
572 if (
const DeclRefExpr *ref = dyn_cast<DeclRefExpr>(e))
573 return (ref->getDecl() == &var);
574 if (
const BlockExpr *be = dyn_cast<BlockExpr>(e)) {
575 const BlockDecl *block = be->getBlockDecl();
576 for (
const auto &I : block->
captures()) {
577 if (I.getVariable() == &var)
583 for (
const Stmt *SubStmt : s->children())
592 if (!decl)
return false;
593 if (!isa<VarDecl>(decl))
return false;
605 LValue lvalue,
bool capturedByInit) {
616 init = DIE->getExpr();
622 init = ewc->getSubExpr();
630 bool accessedByInit =
false;
632 accessedByInit = (capturedByInit ||
isAccessedBy(D, init));
633 if (accessedByInit) {
636 if (capturedByInit) {
644 llvm::PointerType *ty
645 = cast<llvm::PointerType>(tempLV.
getAddress()->getType());
646 ty = cast<llvm::PointerType>(ty->getElementType());
648 llvm::Value *zero = llvm::ConstantPointerNull::get(ty);
664 llvm_unreachable(
"present but none");
718 llvm_unreachable(
"present but none");
747 if (isa<llvm::ConstantAggregateZero>(Init) ||
748 isa<llvm::ConstantPointerNull>(Init) ||
749 isa<llvm::UndefValue>(Init))
751 if (isa<llvm::ConstantInt>(Init) || isa<llvm::ConstantFP>(Init) ||
752 isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) ||
753 isa<llvm::ConstantExpr>(Init))
754 return Init->isNullValue() || NumStores--;
757 if (isa<llvm::ConstantArray>(Init) || isa<llvm::ConstantStruct>(Init)) {
758 for (
unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) {
759 llvm::Constant *Elt = cast<llvm::Constant>(Init->getOperand(i));
766 if (llvm::ConstantDataSequential *CDS =
767 dyn_cast<llvm::ConstantDataSequential>(Init)) {
768 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
769 llvm::Constant *Elt = CDS->getElementAsConstant(i);
785 assert(!Init->isNullValue() && !isa<llvm::UndefValue>(Init) &&
786 "called emitStoresForInitAfterMemset for zero or undef value.");
788 if (isa<llvm::ConstantInt>(Init) || isa<llvm::ConstantFP>(Init) ||
789 isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) ||
790 isa<llvm::ConstantExpr>(Init)) {
791 Builder.CreateStore(Init, Loc, isVolatile);
795 if (llvm::ConstantDataSequential *CDS =
796 dyn_cast<llvm::ConstantDataSequential>(Init)) {
797 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
798 llvm::Constant *Elt = CDS->getElementAsConstant(i);
801 if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt))
803 Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
804 isVolatile, Builder);
809 assert((isa<llvm::ConstantStruct>(Init) || isa<llvm::ConstantArray>(Init)) &&
810 "Unknown value type!");
812 for (
unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) {
813 llvm::Constant *Elt = cast<llvm::Constant>(Init->getOperand(i));
816 if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt))
818 Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
819 isVolatile, Builder);
829 uint64_t GlobalSize) {
831 if (isa<llvm::ConstantAggregateZero>(Init))
return true;
837 unsigned StoreBudget = 6;
838 uint64_t SizeLimit = 32;
840 return GlobalSize > SizeLimit &&
871 C->setDoesNotThrow();
879 C->setDoesNotThrow();
890 bool isByRef = D.
hasAttr<BlocksAttr>();
891 emission.IsByRef = isByRef;
894 emission.Alignment = alignment;
926 emission.Address =
nullptr;
927 assert(emission.wasEmittedAsGlobal());
932 emission.IsConstantAggregate =
true;
946 if (!cast<CXXRecordDecl>(RecordTy->getDecl())->hasTrivialDestructor()) {
953 Builder.CreateStore(Zero, NRVOFlag);
957 emission.NRVOFlag = NRVOFlag;
969 allocaAlignment = std::max(allocaAlignment,
971 Alloc->setAlignment(allocaAlignment.
getQuantity());
986 if (!DidCallStackSave) {
995 DidCallStackSave =
true;
1004 std::tie(elementCount, elementType) =
getVLASize(Ty);
1009 llvm::AllocaInst *vla =
Builder.CreateAlloca(llvmTy, elementCount,
"vla");
1016 assert(!DMEntry &&
"Decl already exists in localdeclmap!");
1018 emission.Address = DeclPtr;
1026 DI->EmitDeclareOfAutoVariable(&D, DeclPtr,
Builder);
1030 if (D.
hasAttr<AnnotateAttr>())
1043 if (
const BlockExpr *be = dyn_cast<BlockExpr>(e)) {
1044 const BlockDecl *block = be->getBlockDecl();
1045 for (
const auto &I : block->
captures()) {
1046 if (I.getVariable() == &var)
1054 if (
const StmtExpr *SE = dyn_cast<StmtExpr>(e)) {
1056 for (
const auto *BI : CS->
body())
1057 if (
const auto *E = dyn_cast<Expr>(BI)) {
1061 else if (
const auto *DS = dyn_cast<DeclStmt>(BI)) {
1063 for (
const auto *I : DS->decls()) {
1064 if (
const auto *VD = dyn_cast<VarDecl>((I))) {
1065 const Expr *Init = VD->getInit();
1078 for (
const Stmt *SubStmt : e->children())
1093 if (Constructor->isTrivial() &&
1094 Constructor->isDefaultConstructor() &&
1095 !Construct->requiresZeroInitialization())
1101 assert(emission.Variable &&
"emission was not valid!");
1104 if (emission.wasEmittedAsGlobal())
return;
1106 const VarDecl &D = *emission.Variable;
1121 if (emission.IsByRef)
1127 CharUnits alignment = emission.Alignment;
1132 bool capturedByInit = emission.IsByRef &&
isCapturedBy(D, Init);
1137 llvm::Constant *constant =
nullptr;
1138 if (emission.IsConstantAggregate || D.
isConstexpr()) {
1139 assert(!capturedByInit &&
"constant init contains a capturing block?");
1149 if (!emission.IsConstantAggregate) {
1158 bool isVolatile = type.isVolatileQualified();
1162 getContext().getTypeSizeInChars(type).getQuantity());
1165 if (Loc->getType() != BP)
1166 Loc =
Builder.CreateBitCast(Loc, BP);
1172 Builder.CreateMemSet(Loc, llvm::ConstantInt::get(
Int8Ty, 0), SizeVal,
1175 if (!constant->isNullValue() && !isa<llvm::UndefValue>(constant)) {
1176 Loc =
Builder.CreateBitCast(Loc, constant->getType()->getPointerTo());
1183 llvm::GlobalVariable *GV =
1184 new llvm::GlobalVariable(
CGM.
getModule(), constant->getType(),
true,
1185 llvm::GlobalValue::PrivateLinkage,
1188 GV->setUnnamedAddr(
true);
1191 if (SrcPtr->getType() != BP)
1192 SrcPtr =
Builder.CreateBitCast(SrcPtr, BP);
1212 LValue lvalue,
bool capturedByInit) {
1245 llvm_unreachable(
"bad evaluation kind");
1258 const VarDecl *var = emission.Variable;
1266 llvm_unreachable(
"no cleanup for trivially-destructible variable");
1271 if (emission.NRVOFlag) {
1274 EHStack.pushCleanup<DestroyNRVOVariable>(cleanupKind, addr, dtor,
1288 if (!var->
hasAttr<ObjCPreciseLifetimeAttr>())
1301 bool useEHCleanup = (cleanupKind &
EHCleanup);
1302 EHStack.pushCleanup<DestroyObject>(cleanupKind, addr,
type, destroyer,
1307 assert(emission.Variable &&
"emission was not valid!");
1310 if (emission.wasEmittedAsGlobal())
return;
1316 const VarDecl &D = *emission.Variable;
1334 D.
hasAttr<ObjCPreciseLifetimeAttr>()) {
1339 if (
const CleanupAttr *CA = D.
getAttr<CleanupAttr>()) {
1343 assert(F &&
"Could not find function!");
1351 if (emission.IsByRef)
1366 llvm_unreachable(
"Unknown DestructionKind");
1373 assert(dtorKind &&
"cannot push destructor for trivial type");
1383 assert(dtorKind &&
"cannot push destructor for trivial type");
1392 bool useEHCleanupForArray) {
1393 pushFullExprCleanup<DestroyObject>(cleanupKind, addr,
type,
1394 destroyer, useEHCleanupForArray);
1398 EHStack.pushCleanup<CallStackRestore>(
Kind, SPMem);
1403 Destroyer *destroyer,
bool useEHCleanupForArray) {
1405 "performing lifetime extension from within conditional");
1411 EHStack.pushCleanup<DestroyObject>(
1413 destroyer, useEHCleanupForArray);
1417 pushCleanupAfterFullExpr<DestroyObject>(
1418 cleanupKind, addr,
type, destroyer, useEHCleanupForArray);
1433 Destroyer *destroyer,
1434 bool useEHCleanupForArray) {
1437 return destroyer(*
this, addr, type);
1443 bool checkZeroLength =
true;
1446 if (llvm::ConstantInt *constLength = dyn_cast<llvm::ConstantInt>(length)) {
1448 if (constLength->isZero())
return;
1449 checkZeroLength =
false;
1454 checkZeroLength, useEHCleanupForArray);
1470 Destroyer *destroyer,
1471 bool checkZeroLength,
1472 bool useEHCleanup) {
1480 if (checkZeroLength) {
1482 "arraydestroy.isempty");
1483 Builder.CreateCondBr(isEmpty, doneBB, bodyBB);
1487 llvm::BasicBlock *entryBB =
Builder.GetInsertBlock();
1489 llvm::PHINode *elementPast =
1490 Builder.CreatePHI(begin->getType(), 2,
"arraydestroy.elementPast");
1491 elementPast->addIncoming(end, entryBB);
1496 "arraydestroy.element");
1502 destroyer(*
this, element, type);
1509 Builder.CreateCondBr(done, doneBB, bodyBB);
1510 elementPast->addIncoming(element,
Builder.GetInsertBlock());
1523 unsigned arrayDepth = 0;
1526 if (!isa<VariableArrayType>(arrayType))
1528 type = arrayType->getElementType();
1535 begin = CGF.
Builder.CreateInBoundsGEP(begin, gepIndices,
"pad.arraybegin");
1536 end = CGF.
Builder.CreateInBoundsGEP(end, gepIndices,
"pad.arrayend");
1559 : ArrayBegin(arrayBegin), ArrayEnd(arrayEnd),
1560 ElementType(elementType), Destroyer(destroyer) {}
1564 ElementType, Destroyer);
1577 IrregularPartialArrayDestroy(
llvm::Value *arrayBegin,
1581 : ArrayBegin(arrayBegin), ArrayEndPointer(arrayEndPointer),
1582 ElementType(elementType), Destroyer(destroyer) {}
1587 ElementType, Destroyer);
1601 Destroyer *destroyer) {
1602 pushFullExprCleanup<IrregularPartialArrayDestroy>(
EHCleanup,
1603 arrayBegin, arrayEndPointer,
1604 elementType, destroyer);
1616 Destroyer *destroyer) {
1617 pushFullExprCleanup<RegularPartialArrayDestroy>(
EHCleanup,
1618 arrayBegin, arrayEnd,
1619 elementType, destroyer);
1624 if (LifetimeStartFn)
return LifetimeStartFn;
1625 LifetimeStartFn = llvm::Intrinsic::getDeclaration(&
getModule(),
1626 llvm::Intrinsic::lifetime_start);
1627 return LifetimeStartFn;
1632 if (LifetimeEndFn)
return LifetimeEndFn;
1633 LifetimeEndFn = llvm::Intrinsic::getDeclaration(&
getModule(),
1634 llvm::Intrinsic::lifetime_end);
1635 return LifetimeEndFn;
1646 : Param(param), Precise(precise) {}
1660 bool ArgIsPointer,
unsigned ArgNo) {
1662 assert((isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D)) &&
1663 "Invalid argument to EmitParmDecl");
1670 if (isa<ImplicitParamDecl>(D)) {
1673 LocalDeclMap[&D] = Arg;
1679 Alloc->setAlignment(
getContext().getDeclAlign(&D).getQuantity());
1682 LocalAddr =
Builder.CreateLoad(Alloc);
1689 DI->EmitDeclareOfBlockLiteralArgVariable(*
BlockInfo, Arg, ArgNo,
1699 bool DoStore =
false;
1705 unsigned AS = cast<llvm::PointerType>(Arg->getType())->getAddressSpace();
1707 DeclPtr = Arg->getType() == IRTy ? Arg :
Builder.CreateBitCast(Arg, IRTy,
1735 bool isConsumed = D.
hasAttr<NSConsumedAttr>();
1791 assert(!DMEntry &&
"Decl already exists in localdeclmap!");
1798 DI->EmitDeclareOfArgVariable(&D, DeclPtr, ArgNo,
Builder);
1802 if (D.
hasAttr<AnnotateAttr>())
unsigned getAddressSpace() const
getAddressSpace - Return the address space of this type.
CGOpenCLRuntime & getOpenCLRuntime()
Return a reference to the configured OpenCL runtime.
Defines the clang::ASTContext interface.
StringRef getName() const
void EmitStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
llvm::Value * EmitARCRetainAutoreleaseScalarExpr(const Expr *expr)
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
void EmitExtendGCLifetime(llvm::Value *object)
CodeGenTypes & getTypes()
llvm::Type * ConvertTypeForMem(QualType T)
void EmitVarDecl(const VarDecl &D)
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
DestructionKind isDestructedType() const
llvm::Module & getModule() const
static AggValueSlot forLValue(const LValue &LV, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, IsZeroed_t isZeroed=IsNotZeroed)
bool isInConditionalBranch() const
const TargetInfo & getTarget() const
SanitizerSet Sanitize
Set of enabled sanitizers.
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
Defines the SourceManager interface.
static bool canEmitInitWithFewStoresAfterMemset(llvm::Constant *Init, unsigned &NumStores)
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
bool isRecordType() const
void emitAutoVarTypeCleanup(const AutoVarEmission &emission, QualType::DestructionKind dtorKind)
Enter a destroy cleanup for the given local variable.
QualType getUnderlyingType() const
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
bool hasNonTrivialDestructor() const
Determine whether this class has a non-trivial destructor (C++ [class.dtor]p3)
void EmitAutoVarDecl(const VarDecl &D)
const llvm::DataLayout & getDataLayout() const
static Destroyer destroyARCStrongPrecise
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
const Expr * getInit() const
Represents a call to a C++ constructor.
const LangOptions & getLangOpts() const
llvm::Value * EmitARCRetainNonBlock(llvm::Value *value)
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating, llvm::Value *This)
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Represents a C++ constructor within a class.
llvm::Value * getAddress() const
static Destroyer destroyARCWeak
void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin, llvm::Value *arrayEndPointer, QualType elementType, Destroyer *destroyer)
bool areArgsDestroyedLeftToRightInCallee() const
ObjCLifetime getObjCLifetime() const
void EmitVariablyModifiedType(QualType Ty)
llvm::Value * ReturnValue
llvm::Type * ConvertTypeForMem(QualType T)
void setAddress(llvm::Value *address)
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
void emitByrefStructureInit(const AutoVarEmission &emission)
CGDebugInfo * getDebugInfo()
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
void EmitExprAsInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
llvm::IntegerType * Int64Ty
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
bool isReferenceType() const
llvm::IntegerType * SizeTy
void EmitARCInitWeak(llvm::Value *value, llvm::Value *addr)
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
CleanupKind getCleanupKind(QualType::DestructionKind kind)
const Decl * getDecl() const
StorageClass getStorageClass() const
Returns the storage class as written in the source. For the computed linkage of symbol, see getLinkage.
bool hasExternalStorage() const
Returns true if a variable has extern or private_extern storage.
void setNonGC(bool Value)
LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment=CharUnits())
llvm::Constant * getLLVMLifetimeStartFn()
Lazily declare the .lifetime.start intrinsic.
static bool hasScalarEvaluationKind(QualType T)
void Destroyer(CodeGenFunction &CGF, llvm::Value *addr, QualType ty)
iterator begin() const
Returns an iterator pointing to the innermost EH scope.
static void drillIntoBlockVariable(CodeGenFunction &CGF, LValue &lvalue, const VarDecl *var)
RValue EmitCall(const CGFunctionInfo &FnInfo, llvm::Value *Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, const Decl *TargetDecl=nullptr, llvm::Instruction **callOrInvoke=nullptr)
static bool shouldUseMemSetPlusStoresToInitialize(llvm::Constant *Init, uint64_t GlobalSize)
Qualifiers::ObjCLifetime getObjCLifetime() const
ObjCMethodFamily getMethodFamily() const
Determines the family of this method.
void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin, llvm::Value *arrayEnd, QualType elementType, Destroyer *destroyer)
void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl)
Emit information about a global variable.
void setStaticLocalDeclAddress(const VarDecl *D, llvm::Constant *C)
const ArrayType * getAsArrayType(QualType T) const
bool needsEHCleanup(QualType::DestructionKind kind)
void pushDestroy(QualType::DestructionKind dtorKind, llvm::Value *addr, QualType type)
llvm::Value * getObjectAddress(CodeGenFunction &CGF) const
std::string getNameAsString() const
Expr * IgnoreParenCasts() LLVM_READONLY
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
llvm::Value * EmitARCRetainScalarExpr(const Expr *expr)
void EmitAtomicInit(Expr *E, LValue lvalue)
bool isStaticLocal() const
static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts=false)
llvm::Type * BuildByRefType(const VarDecl *var)
void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const
Set the visibility for the given LLVM GlobalValue.
bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor)
std::pair< llvm::Value *, llvm::Value * > ComplexPairTy
AutoVarEmission EmitAutoVarAlloca(const VarDecl &var)
void emitDestroy(llvm::Value *addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
const CodeGen::CGBlockInfo * BlockInfo
CleanupKind getARCCleanupKind()
llvm::Value * getSizeForLifetimeMarkers() const
StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD)
std::vector< bool > & Stack
void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr, bool PerformInit)
static TypeEvaluationKind getEvaluationKind(QualType T)
llvm::Value * EmitARCStoreWeak(llvm::Value *value, llvm::Value *addr, bool ignored)
void EmitAutoVarInit(const AutoVarEmission &emission)
static void EmitAutoVarWithLifetime(CodeGenFunction &CGF, const VarDecl &var, llvm::Value *addr, Qualifiers::ObjCLifetime lifetime)
void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV)
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited...
bool isAtomicType() const
virtual void EmitWorkGroupLocalVarDecl(CodeGenFunction &CGF, const VarDecl &D)
Represents a C++ destructor within a class.
llvm::Value * emitArrayLength(const ArrayType *arrayType, QualType &baseType, llvm::Value *&addr)
DeclContext * getDeclContext()
ASTContext & getContext() const
ImplicitParamDecl * getSelfDecl() const
void add(RValue rvalue, QualType type, bool needscopy=false)
std::pair< llvm::Type *, unsigned > getByRefValueLLVMField(const ValueDecl *VD) const
llvm::GlobalValue::LinkageTypes getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant)
Returns LLVM linkage for a declarator.
bool isExternallyVisible() const
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=None)
static bool hasNontrivialDestruction(QualType T)
static bool isCapturedBy(const VarDecl &var, const Expr *e)
llvm::IRBuilder< PreserveNames, llvm::ConstantFolder, CGBuilderInserterTy > CGBuilderTy
void EmitParmDecl(const VarDecl &D, llvm::Value *Arg, bool ArgIsPointer, unsigned ArgNo)
EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
void enterByrefCleanup(const AutoVarEmission &emission)
llvm::Constant * getOrCreateStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
bool HaveInsertPoint() const
There is no lifetime qualification on this type.
llvm::GlobalVariable * AddInitializerToStaticVarDecl(const VarDecl &D, llvm::GlobalVariable *GV)
ASTContext & getContext() const
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise)
LValue EmitDeclRefLValue(const DeclRefExpr *E)
static std::string getStaticDeclName(CodeGenModule &CGM, const VarDecl &D)
bool isConstant(ASTContext &Ctx) const
bool isConstantSizeType() const
bool isLocalVarDecl() const
llvm::Value * EmitLifetimeStart(uint64_t Size, llvm::Value *Addr)
static bool isAccessedBy(const VarDecl &var, const Stmt *s)
void pushEHDestroy(QualType::DestructionKind dtorKind, llvm::Value *addr, QualType type)
bool isTrivialInitializer(const Expr *Init)
Determine whether the given initializer is trivial in the sense that it requires no code to be genera...
const CodeGenOptions & getCodeGenOpts() const
const Type * getBaseElementTypeUnsafe() const
const LangOptions & getLangOpts() const
Assigning into this object requires a lifetime extension.
llvm::Value * EmitARCRetain(QualType type, llvm::Value *value)
llvm::Constant * getLLVMLifetimeEndFn()
Lazily declare the .lifetime.end intrinsic.
void enterFullExpression(const ExprWithCleanups *E)
void EmitDecl(const Decl &D)
static Destroyer destroyARCStrongImprecise
SourceLocation getExprLoc() const LLVM_READONLY
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
void addUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.used metadata.
Base class for declarations which introduce a typedef-name.
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
static ApplyDebugLocation CreateDefaultArtificial(CodeGenFunction &CGF, SourceLocation TemporaryLocation)
Apply TemporaryLocation if it is valid. Otherwise switch to an artificial debug location that has a v...
llvm::Constant * GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty=0, bool ForVTable=false, bool DontDefer=false)
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const CGFunctionInfo & arrangeFunctionDeclaration(const FunctionDecl *FD)
void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const
llvm::IntegerType * IntPtrTy
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
void emitArrayDestroy(llvm::Value *begin, llvm::Value *end, QualType type, Destroyer *destroyer, bool checkZeroLength, bool useEHCleanup)
static void emitPartialArrayDestroy(CodeGenFunction &CGF, llvm::Value *begin, llvm::Value *end, QualType type, CodeGenFunction::Destroyer *destroyer)
Decl * getNonClosureContext()
llvm::Constant * EmitNullConstant(QualType T)
unsigned GetGlobalVarAddressSpace(const VarDecl *D, unsigned AddrSpace)
void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr, bool Volatile, unsigned Alignment, QualType Ty, llvm::MDNode *TBAAInfo=nullptr, bool isInit=false, QualType TBAABaseTy=QualType(), uint64_t TBAAOffset=0)
void EmitAggExpr(const Expr *E, AggValueSlot AS)
bool isConstantInitializer(ASTContext &Ctx, bool ForRef, const Expr **Culprit=nullptr) const
llvm::Value * getAllocatedAddress() const
void EmitAutoVarCleanups(const AutoVarEmission &emission)
void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
llvm::Value * BuildBlockByrefAddress(llvm::Value *BaseAddr, const VarDecl *V)
llvm::PointerType * Int8PtrTy
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
bool isNRVOVariable() const
Determine whether this local variable can be used with the named return value optimization (NRVO)...
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
llvm::Value * EmitARCRetainAutorelease(QualType type, llvm::Value *value)
StringRef getMangledName(GlobalDecl GD)
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
ARCPreciseLifetime_t
Does an ARC strong l-value have precise lifetime?
ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal=false, bool IgnoreImag=false)
llvm::Constant * EmitConstantInit(const VarDecl &D, CodeGenFunction *CGF=nullptr)
A use of a default initializer in a constructor or in aggregate initialization.
Reading or writing from this object requires a barrier call.
bool isPODType(ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
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...
static void emitStoresForInitAfterMemset(llvm::Constant *Init, llvm::Value *Loc, bool isVolatile, CGBuilderTy &Builder)
bool isARCPseudoStrong() const
Determine whether this variable is an ARC pseudo-__strong variable. A pseudo-__strong variable has a ...
Represents a C++ struct/union/class.
BoundNodesTreeBuilder *const Builder
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
bool isObjCObjectPointerType() const
llvm::Type * ConvertType(QualType T)
static Destroyer destroyCXXObject
llvm::Constant * GetAddrOfGlobal(GlobalDecl GD)
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
A cleanup scope which generates the cleanup blocks lazily.
llvm::Value * EmitARCStoreStrongCall(llvm::Value *addr, llvm::Value *value, bool resultIgnored)
std::pair< llvm::Value *, QualType > getVLASize(const VariableArrayType *vla)
Defines the clang::TargetInfo interface.
void setLocation(SourceLocation Loc)
bool useLifetimeMarkers() const
void pushStackRestore(CleanupKind kind, llvm::Value *SPMem)
unsigned getTargetAddressSpace(QualType T) const
A reference to a declared variable, function, enum, etc. [C99 6.5.1p2].
static RValue get(llvm::Value *V)
llvm::Value * EmitLoadOfScalar(llvm::Value *Addr, bool Volatile, unsigned Alignment, QualType Ty, SourceLocation Loc, llvm::MDNode *TBAAInfo=nullptr, QualType TBAABaseTy=QualType(), uint64_t TBAAOffset=0)
void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr)
An l-value expression is a reference to an object with independent storage.
void pushLifetimeExtendedDestroy(CleanupKind kind, llvm::Value *addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
SourceLocation getLocation() const
void EmitVarAnnotations(const VarDecl *D, llvm::Value *V)
Emit local annotations for the local variable V, declared by D.
SanitizerMetadata * getSanitizerMetadata()
void PopCleanupBlock(bool FallThroughIsBranchThrough=false)
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
bool supportsCOMDAT() const
bool hasLocalStorage() const
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.