27using namespace CodeGen;
49 !
D->getParent()->field_empty())
54 if (!
D->hasTrivialBody())
61 if (
Class->mayInsertExtraPadding())
65 if (
Class->getNumVBases()) {
74 for (
const auto *I :
Class->fields())
75 if (I->getType().isDestructedType())
80 for (
const auto &I :
Class->bases()) {
83 if (I.isVirtual())
continue;
86 const auto *
Base = I.getType()->castAsCXXRecordDecl();
87 if (
Base->hasTrivialDestructor())
continue;
91 if (UniqueBase)
return true;
122 if (!llvm::GlobalAlias::isValidLinkage(
Linkage))
125 llvm::GlobalValue::LinkageTypes TargetLinkage =
131 if (Entry && !Entry->isDeclaration())
133 if (Replacements.count(MangledName))
143 if (llvm::GlobalValue::isDiscardableIfUnused(
Linkage) &&
144 !(TargetLinkage == llvm::GlobalValue::AvailableExternallyLinkage &&
160 if (llvm::GlobalValue::isWeakForLinker(
Linkage) &&
168 if (Aliasee->isDeclarationForLinker())
175 if (llvm::GlobalValue::isWeakForLinker(TargetLinkage))
179 auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0,
Linkage,
"",
183 Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
187 assert(Entry->getValueType() == AliasValueType &&
188 Entry->getAddressSpace() == Alias->getAddressSpace() &&
189 "declaration exists with different type");
190 Alias->takeName(Entry);
191 Entry->replaceAllUsesWith(Alias);
192 Entry->eraseFromParent();
194 Alias->setName(MangledName);
205 auto *Fn = cast<llvm::Function>(
212 setNonAliasAttributes(GD, Fn);
220 auto *MD = cast<CXXMethodDecl>(GD.
getDecl());
222 if (isa<CXXDestructorDecl>(MD)) {
227 MD->getParent()->getNumVBases() == 0)
237 llvm::Constant *Ptr = GetOrCreateLLVMFunction(
239 false, llvm::AttributeList(), IsForDefinition);
240 return {FnType, Ptr};
248 "No kext in Microsoft ABI");
252 assert(VTable &&
"BuildVirtualCall = kext vtbl pointer is null");
259 llvm::Value *VFuncPtr =
260 CGF.
Builder.CreateConstInBoundsGEP1_64(Ty, VTable, VTableIndex,
"vfnkxt");
272 CGCallee Callee(GD, VFunc, PointerAuth);
283 assert(RD &&
"BuildAppleKextVirtualCall - Qual must be record");
284 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(MD))
287 return ::BuildAppleKextVirtualCall(*
this, MD, Ty, RD);
302 return ::BuildAppleKextVirtualCall(*
this,
GlobalDecl(DD,
Type), Ty, RD);
Defines the clang::ASTContext interface.
static CGCallee BuildAppleKextVirtualCall(CodeGenFunction &CGF, GlobalDecl GD, llvm::Type *Ty, const CXXRecordDecl *RD)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
Represents a C++ destructor within a class.
Represents a static or instance method of a struct/union/class.
Represents a C++ struct/union/class.
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
CharUnits - This is an opaque type for sizes expressed in character units.
bool isZero() const
isZero - Test whether the quantity equals zero.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
PointerAuthOptions PointerAuth
Configuration for pointer-signing.
llvm::LoadInst * CreateAlignedLoad(llvm::Type *Ty, llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
virtual llvm::GlobalVariable * getAddrOfVTable(const CXXRecordDecl *RD, CharUnits VPtrOffset)=0
Get the address of the vtable for the given record decl which should be used for the vptr at the give...
All available information about a concrete callee.
CGFunctionInfo - Class to encapsulate the information about a function definition.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
void GenerateCode(GlobalDecl GD, llvm::Function *Fn, const CGFunctionInfo &FnInfo)
CGCallee BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD, CXXDtorType Type, const CXXRecordDecl *RD)
BuildVirtualCall - This routine makes indirect vtable call for call to virtual destructors.
CGPointerAuthInfo EmitPointerAuthInfo(const PointerAuthSchema &Schema, llvm::Value *StorageAddress, GlobalDecl SchemaDecl, QualType SchemaType)
Emit the concrete pointer authentication informaton for the given authentication schema.
CGCallee BuildAppleKextVirtualCall(const CXXMethodDecl *MD, NestedNameSpecifier Qual, llvm::Type *Ty)
BuildAppleKextVirtualCall - This routine is to support gcc's kext ABI making indirect call to virtual...
This class organizes the cross-function state that is used while generating LLVM code.
llvm::Module & getModule() const
llvm::FunctionCallee getAddrAndTypeOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
llvm::Constant * getAddrOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the constructor/destructor of the given type.
CodeGenTypes & getTypes()
const TargetInfo & getTarget() const
bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D)
Try to emit a base destructor as an alias to its primary base-class destructor.
CGCXXABI & getCXXABI() const
llvm::Function * codegenCXXStructor(GlobalDecl GD)
const llvm::Triple & getTriple() const
llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD)
void setFunctionLinkage(GlobalDecl GD, llvm::Function *F)
llvm::Constant * GetAddrOfGlobal(GlobalDecl GD, ForDefinition_t IsForDefinition=NotForDefinition)
ItaniumVTableContext & getItaniumVTableContext()
const CodeGenOptions & getCodeGenOpts() const
StringRef getMangledName(GlobalDecl GD)
void SetCommonAttributes(GlobalDecl GD, llvm::GlobalValue *GV)
Set attributes which are common to any form of a global definition (alias, Objective-C method,...
llvm::LLVMContext & getLLVMContext()
llvm::GlobalValue * GetGlobalValue(StringRef Ref)
void addReplacement(StringRef Name, llvm::Constant *C)
void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F)
Set the LLVM function attributes which only apply to a function definition.
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
const CGFunctionInfo & arrangeCXXStructorDeclaration(GlobalDecl GD)
FunctionType - C99 6.7.5.3 - Function Declarators.
CallingConv getCallConv() const
GlobalDecl - represents a global declaration.
GlobalDecl getCanonicalDecl() const
GlobalDecl getWithDtorType(CXXDtorType Type)
CXXDtorType getDtorType() const
const Decl * getDecl() const
uint64_t getMethodVTableIndex(GlobalDecl GD)
Locate a virtual function in the vtable.
const VTableLayout & getVTableLayout(const CXXRecordDecl *RD)
GlobalDecl findOriginalMethod(GlobalDecl GD)
Return the method that added the v-table slot that will be used to call the given method.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier, or null.
A (possibly-)qualified type.
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
The base class of the type hierarchy.
const T * castAs() const
Member-template castAs<specific type>.
size_t getVTableOffset(size_t i) const
AddressPointLocation getAddressPoint(BaseSubobject Base) const
The JSON file list parser is used to communicate input to InstallAPI.
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
CXXDtorType
C++ destructor types.
@ Dtor_Base
Base object dtor.
@ Dtor_Complete
Complete object dtor.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
unsigned char PointerAlignInBytes
PointerAuthSchema CXXVirtualFunctionPointers
The ABI for most C++ virtual function pointers, i.e. v-table entries.
unsigned AddressPointIndex