26#include "llvm/IR/IRBuilder.h"
27#include "llvm/IR/Intrinsics.h"
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;
88 const auto *
Base = I.getType()->castAsCXXRecordDecl();
89 if (
Base->hasTrivialDestructor())
continue;
93 if (UniqueBase)
return true;
124 if (!llvm::GlobalAlias::isValidLinkage(
Linkage))
127 llvm::GlobalValue::LinkageTypes TargetLinkage =
133 if (Entry && !Entry->isDeclaration())
135 if (Replacements.count(MangledName))
145 if (llvm::GlobalValue::isDiscardableIfUnused(
Linkage) &&
146 !(TargetLinkage == llvm::GlobalValue::AvailableExternallyLinkage &&
162 if (llvm::GlobalValue::isWeakForLinker(
Linkage) &&
170 if (Aliasee->isDeclarationForLinker())
177 if (llvm::GlobalValue::isWeakForLinker(TargetLinkage))
180 auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0,
Linkage,
"",
184 Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
188 assert(Entry->getValueType() == AliasValueType &&
189 Entry->getAddressSpace() == Alias->getAddressSpace() &&
190 "declaration exists with different type");
191 Alias->takeName(Entry);
192 Entry->replaceAllUsesWith(Alias);
193 Entry->eraseFromParent();
195 Alias->setName(MangledName);
212 if (Entry && !Entry->isDeclaration())
220 auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0,
Linkage,
"",
223 Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
226 assert(Entry->getValueType() == AliasValueType &&
227 Entry->getAddressSpace() == Alias->getAddressSpace() &&
228 "declaration exists with different type");
229 Alias->takeName(Entry);
230 Entry->replaceAllUsesWith(Alias);
231 Entry->eraseFromParent();
233 Alias->setName(MangledName);
248 llvm::Function *Fn) {
251 const auto *FD = dyn_cast<FunctionDecl>(GD.
getDecl());
252 if (!FD || !
getContext().CUDADeviceInvalidFuncs.count(FD->getCanonicalDecl()))
254 llvm::BasicBlock *BB =
256 llvm::IRBuilder<> Builder(BB);
257 Builder.CreateIntrinsic(llvm::Intrinsic::trap, {});
258 llvm::Type *RetTy = Fn->getReturnType();
259 if (RetTy->isVoidTy())
260 Builder.CreateRetVoid();
262 Builder.CreateRet(llvm::PoisonValue::get(RetTy));
276 setNonAliasAttributes(GD, Fn);
291 MD->getParent()->getNumVBases() == 0)
301 llvm::Constant *Ptr = GetOrCreateLLVMFunction(
303 false, llvm::AttributeList(), IsForDefinition);
304 return {FnType, Ptr};
312 "No kext in Microsoft ABI");
316 assert(VTable &&
"BuildVirtualCall = kext vtbl pointer is null");
323 llvm::Value *VFuncPtr =
324 CGF.
Builder.CreateConstInBoundsGEP1_64(Ty, VTable, VTableIndex,
"vfnkxt");
336 CGCallee Callee(GD, VFunc, PointerAuth);
347 assert(RD &&
"BuildAppleKextVirtualCall - Qual must be record");
348 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(MD))
351 return ::BuildAppleKextVirtualCall(*
this, MD, Ty, RD);
365 llvm::Type *Ty =
CGM.getTypes().GetFunctionType(FInfo);
366 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....
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.
This is an opaque type for sizes expressed in character units.
bool isZero() const
Test whether the quantity equals zero.
static CharUnits 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)
CGPointerAuthInfo EmitPointerAuthInfo(const PointerAuthSchema &Schema, llvm::Value *StorageAddress, llvm::ConstantInt *Discriminator)
CGCallee BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD, CXXDtorType Type, const CXXRecordDecl *RD)
BuildVirtualCall - This routine makes indirect vtable call for call to virtual destructors.
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.
const LangOptions & getLangOpts() const
CodeGenTypes & getTypes()
const TargetInfo & getTarget() const
bool tryEmitCUDADeviceInvalidFunctionBody(GlobalDecl GD, llvm::Function *Fn)
Emit a trap stub body for functions in ASTContext::CUDADeviceInvalidFuncs.
bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D)
Try to emit a base destructor as an alias to its primary base-class destructor.
CGCXXABI & getCXXABI() const
void EmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target)
Emit a definition as a global alias for another definition, unconditionally.
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()
ASTContext & getContext() const
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)
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 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.
const T * castAs() const
Member-template castAs<specific type>.
size_t getVTableOffset(size_t i) const
AddressPointLocation getAddressPoint(BaseSubobject Base) const
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
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.
U cast(CodeGen::Address addr)
@ 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