27#include "llvm/ADT/StringExtras.h"
29using namespace CodeGen;
51 !
D->getParent()->field_empty())
56 if (!
D->hasTrivialBody())
63 if (
Class->mayInsertExtraPadding())
67 if (
Class->getNumVBases()) {
76 for (
const auto *I :
Class->fields())
77 if (I->getType().isDestructedType())
82 for (
const auto &I :
Class->bases()) {
85 if (I.isVirtual())
continue;
90 if (
Base->hasTrivialDestructor())
continue;
94 if (UniqueBase)
return true;
125 if (!llvm::GlobalAlias::isValidLinkage(
Linkage))
128 llvm::GlobalValue::LinkageTypes TargetLinkage =
134 if (Entry && !Entry->isDeclaration())
136 if (Replacements.count(MangledName))
146 if (llvm::GlobalValue::isDiscardableIfUnused(
Linkage) &&
147 !(TargetLinkage == llvm::GlobalValue::AvailableExternallyLinkage &&
163 if (llvm::GlobalValue::isWeakForLinker(
Linkage) &&
171 if (Aliasee->isDeclarationForLinker())
178 if (llvm::GlobalValue::isWeakForLinker(TargetLinkage))
182 auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0,
Linkage,
"",
186 Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
190 assert(Entry->getValueType() == AliasValueType &&
191 Entry->getAddressSpace() == Alias->getAddressSpace() &&
192 "declaration exists with different type");
193 Alias->takeName(Entry);
194 Entry->replaceAllUsesWith(Alias);
195 Entry->eraseFromParent();
197 Alias->setName(MangledName);
208 auto *Fn = cast<llvm::Function>(
215 setNonAliasAttributes(GD, Fn);
223 auto *MD = cast<CXXMethodDecl>(GD.
getDecl());
225 if (isa<CXXDestructorDecl>(MD)) {
230 MD->getParent()->getNumVBases() == 0)
240 llvm::Constant *Ptr = GetOrCreateLLVMFunction(
242 false, llvm::AttributeList(), IsForDefinition);
243 return {FnType, Ptr};
251 "No kext in Microsoft ABI");
255 assert(VTable &&
"BuildVirtualCall = kext vtbl pointer is null");
262 llvm::Value *VFuncPtr =
263 CGF.
Builder.CreateConstInBoundsGEP1_64(Ty, VTable, VTableIndex,
"vfnkxt");
275 CGCallee Callee(GD, VFunc, PointerAuth);
287 "BuildAppleKextVirtualCall - bad Qual kind");
292 assert(RT &&
"BuildAppleKextVirtualCall - Qual type must be record");
293 const auto *RD = cast<CXXRecordDecl>(RT->
getDecl());
295 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(MD))
298 return ::BuildAppleKextVirtualCall(*
this, MD, Ty, RD);
313 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...
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)
CGPointerAuthInfo EmitPointerAuthInfo(const PointerAuthSchema &Schema, llvm::Value *StorageAddress, GlobalDecl SchemaDecl, QualType SchemaType)
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>::".
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
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.
const FunctionProtoType * T
@ 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