26 #include "llvm/ADT/StringExtras.h" 27 using namespace clang;
28 using namespace CodeGen;
70 for (
const auto *I : Class->
fields())
71 if (I->getType().isDestructedType())
76 for (
const auto &I : Class->
bases()) {
79 if (I.isVirtual())
continue;
83 cast<CXXRecordDecl>(I.getType()->castAs<
RecordType>()->getDecl());
84 if (
Base->hasTrivialDestructor())
continue;
88 if (UniqueBase)
return true;
119 if (!llvm::GlobalAlias::isValidLinkage(Linkage))
122 llvm::GlobalValue::LinkageTypes TargetLinkage =
128 if (Entry && !Entry->isDeclaration())
130 if (Replacements.count(MangledName))
135 llvm::PointerType *AliasType = AliasValueType->getPointerTo();
141 llvm::Constant *Aliasee = Ref;
142 if (Ref->getType() != AliasType)
143 Aliasee = llvm::ConstantExpr::getBitCast(Ref, AliasType);
147 if (llvm::GlobalValue::isDiscardableIfUnused(Linkage) &&
148 !(TargetLinkage == llvm::GlobalValue::AvailableExternallyLinkage &&
164 if (llvm::GlobalValue::isWeakForLinker(Linkage) &&
172 if (Ref->isDeclarationForLinker())
179 if (llvm::GlobalValue::isWeakForLinker(TargetLinkage))
187 Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
191 assert(Entry->getType() == AliasType &&
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");
254 Ty = Ty->getPointerTo()->getPointerTo();
256 assert(VTable &&
"BuildVirtualCall = kext vtbl pointer is null");
257 uint64_t VTableIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
258 const VTableLayout &VTLayout = CGM.getItaniumVTableContext().getVTableLayout(RD);
264 CGF.
Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex,
"vfnkxt");
279 "BuildAppleKextVirtualCall - bad Qual kind");
284 assert(RT &&
"BuildAppleKextVirtualCall - Qual type must be record");
285 const auto *RD = cast<CXXRecordDecl>(RT->
getDecl());
287 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(MD))
288 return BuildAppleKextVirtualDestructorCall(DD,
Dtor_Complete, RD);
302 const CGFunctionInfo &FInfo = CGM.getTypes().arrangeCXXStructorDeclaration(
304 llvm::Type *Ty = CGM.getTypes().GetFunctionType(FInfo);
Defines the clang::ASTContext interface.
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...
A (possibly-)qualified type.
CodeGenTypes & getTypes()
static CGCallee BuildAppleKextVirtualCall(CodeGenFunction &CGF, GlobalDecl GD, llvm::Type *Ty, const CXXRecordDecl *RD)
const CodeGenOptions & getCodeGenOpts() const
CXXDtorType getDtorType() const
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D...
FunctionType - C99 6.7.5.3 - Function Declarators.
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
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.
The base class of the type hierarchy.
void setFunctionLinkage(GlobalDecl GD, llvm::Function *F)
void GenerateCode(GlobalDecl GD, llvm::Function *Fn, const CGFunctionInfo &FnInfo)
AddressPointLocation getAddressPoint(BaseSubobject Base) const
bool isZero() const
isZero - Test whether the quantity equals zero.
bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D)
Try to emit a base destructor as an alias to its primary base-class destructor.
unsigned AddressPointIndex
const T * getAs() const
Member-template getAs<specific type>'.
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
bool mayInsertExtraPadding(bool EmitRemark=false) const
Whether we are allowed to insert extra padding between fields.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
bool hasTrivialBody() const
Returns whether the function has a trivial body that does not require any specific codegen...
CGCallee BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD, CXXDtorType Type, const CXXRecordDecl *RD)
BuildVirtualCall - This routine makes indirect vtable call for call to virtual destructors.
field_range fields() const
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
CharUnits - This is an opaque type for sizes expressed in character units.
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
GlobalDecl getWithDtorType(CXXDtorType Type)
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
const CGFunctionInfo & arrangeCXXStructorDeclaration(GlobalDecl GD)
CXXDtorType
C++ destructor types.
const T * castAs() const
Member-template castAs<specific type>.
Represents a C++ destructor within a class.
llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD)
const TargetInfo & getTarget() const
void SetCommonAttributes(GlobalDecl GD, llvm::GlobalValue *GV)
Set attributes which are common to any form of a global definition (alias, Objective-C method...
A type, stored as a Type*.
GlobalDecl - represents a global declaration.
The l-value was considered opaque, so the alignment was determined from a type.
RecordDecl * getDecl() const
Address CreateBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
const Decl * getDecl() const
Represents a static or instance method of a struct/union/class.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F)
Set the LLVM function attributes which only apply to a function definition.
All available information about a concrete callee.
void addReplacement(StringRef Name, llvm::Constant *C)
llvm::Constant * GetAddrOfGlobal(GlobalDecl GD, ForDefinition_t IsForDefinition=NotForDefinition)
CGFunctionInfo - Class to encapsulate the information about a function definition.
This class organizes the cross-function state that is used while generating LLVM code.
llvm::GlobalValue * GetGlobalValue(StringRef Ref)
Dataflow Directional Tag Classes.
unsigned char PointerAlignInBytes
llvm::LoadInst * CreateAlignedLoad(llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined...
llvm::Module & getModule() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
StringRef getMangledName(GlobalDecl GD)
llvm::FunctionCallee getAddrAndTypeOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
Represents a C++ struct/union/class.
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
llvm::Function * codegenCXXStructor(GlobalDecl GD)
size_t getVTableOffset(size_t i) const
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
const llvm::Triple & getTriple() const