27#include "llvm/ADT/StringExtras.h"
29using namespace CodeGen;
58 if (Class->mayInsertExtraPadding())
62 if (Class->getNumVBases()) {
71 for (
const auto *I : Class->fields())
72 if (I->getType().isDestructedType())
77 for (
const auto &I : Class->bases()) {
80 if (I.isVirtual())
continue;
85 if (
Base->hasTrivialDestructor())
continue;
89 if (UniqueBase)
return true;
120 if (!llvm::GlobalAlias::isValidLinkage(
Linkage))
123 llvm::GlobalValue::LinkageTypes TargetLinkage =
129 if (Entry && !Entry->isDeclaration())
131 if (Replacements.count(MangledName))
136 llvm::PointerType *AliasType = AliasValueType->getPointerTo();
142 llvm::Constant *Aliasee = Ref;
143 if (Ref->getType() != AliasType)
144 Aliasee = llvm::ConstantExpr::getBitCast(Ref, AliasType);
148 if (llvm::GlobalValue::isDiscardableIfUnused(
Linkage) &&
149 !(TargetLinkage == llvm::GlobalValue::AvailableExternallyLinkage &&
165 if (llvm::GlobalValue::isWeakForLinker(
Linkage) &&
173 if (Ref->isDeclarationForLinker())
180 if (llvm::GlobalValue::isWeakForLinker(TargetLinkage))
184 auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0,
Linkage,
"",
188 Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
192 assert(Entry->getType() == AliasType &&
193 "declaration exists with different type");
194 Alias->takeName(Entry);
195 Entry->replaceAllUsesWith(Alias);
196 Entry->eraseFromParent();
198 Alias->setName(MangledName);
209 auto *Fn = cast<llvm::Function>(
216 setNonAliasAttributes(GD, Fn);
224 auto *MD = cast<CXXMethodDecl>(GD.
getDecl());
226 if (isa<CXXDestructorDecl>(MD)) {
231 MD->getParent()->getNumVBases() == 0)
241 llvm::Constant *Ptr = GetOrCreateLLVMFunction(
243 false, llvm::AttributeList(), IsForDefinition);
244 return {FnType, Ptr};
252 "No kext in Microsoft ABI");
255 Ty = Ty->getPointerTo();
256 VTable = CGF.
Builder.CreateBitCast(VTable, Ty->getPointerTo());
257 assert(VTable &&
"BuildVirtualCall = kext vtbl pointer is null");
264 llvm::Value *VFuncPtr =
265 CGF.
Builder.CreateConstInBoundsGEP1_64(Ty, VTable, VTableIndex,
"vfnkxt");
280 "BuildAppleKextVirtualCall - bad Qual kind");
285 assert(RT &&
"BuildAppleKextVirtualCall - Qual type must be record");
286 const auto *RD = cast<CXXRecordDecl>(RT->
getDecl());
288 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(MD))
291 return ::BuildAppleKextVirtualCall(*
this, MD, Ty, RD);
306 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.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
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.
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...
CGCallee BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD, CXXDtorType Type, const CXXRecordDecl *RD)
CGCallee BuildAppleKextVirtualCall(const CXXMethodDecl *MD, NestedNameSpecifier *Qual, llvm::Type *Ty)
void GenerateCode(GlobalDecl GD, llvm::Function *Fn, const CGFunctionInfo &FnInfo)
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::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)
bool hasTrivialBody() const
Returns whether the function has a trivial body that does not require any specific codegen.
FunctionType - C99 6.7.5.3 - Function Declarators.
CallingConv getCallConv() const
GlobalDecl - represents a global declaration.
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)
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
@ TypeSpec
A type, stored as a Type*.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
A (possibly-)qualified type.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
RecordDecl * getDecl() const
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>.
const T * getAs() const
Member-template getAs<specific type>'.
size_t getVTableOffset(size_t i) const
AddressPointLocation getAddressPoint(BaseSubobject Base) const
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.
unsigned char PointerAlignInBytes
unsigned AddressPointIndex