27 #include "llvm/ADT/StringExtras.h" 28 using namespace clang;
29 using namespace CodeGen;
71 for (
const auto *I : Class->
fields())
72 if (I->getType().isDestructedType())
77 for (
const auto &I : Class->
bases()) {
80 if (I.isVirtual())
continue;
84 cast<CXXRecordDecl>(I.getType()->getAs<
RecordType>()->getDecl());
85 if (
Base->hasTrivialDestructor())
continue;
89 if (UniqueBase)
return true;
129 if (!llvm::GlobalAlias::isValidLinkage(Linkage))
132 llvm::GlobalValue::LinkageTypes TargetLinkage =
138 if (Entry && !Entry->isDeclaration())
140 if (Replacements.count(MangledName))
145 llvm::PointerType *AliasType = AliasValueType->getPointerTo();
151 llvm::Constant *Aliasee = Ref;
152 if (Ref->getType() != AliasType)
153 Aliasee = llvm::ConstantExpr::getBitCast(Ref, AliasType);
157 if (llvm::GlobalValue::isDiscardableIfUnused(Linkage) &&
158 !(TargetLinkage == llvm::GlobalValue::AvailableExternallyLinkage &&
174 if (llvm::GlobalValue::isWeakForLinker(Linkage) &&
182 if (Ref->isDeclarationForLinker())
189 if (llvm::GlobalValue::isWeakForLinker(TargetLinkage))
198 assert(Entry->getType() == AliasType &&
199 "declaration exists with different type");
200 Alias->takeName(Entry);
201 Entry->replaceAllUsesWith(Alias);
202 Entry->eraseFromParent();
204 Alias->setName(MangledName);
217 auto *Fn = cast<llvm::Function>(
222 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(MD)) {
225 const auto *CD = cast<CXXConstructorDecl>(MD);
240 llvm::FunctionType *FnType,
bool DontDefer,
243 if (
auto *CD = dyn_cast<CXXConstructorDecl>(MD)) {
255 return GetOrCreateLLVMFunction(
257 false, llvm::AttributeList(), IsForDefinition);
265 "No kext in Microsoft ABI");
269 Ty = Ty->getPointerTo()->getPointerTo();
271 assert(VTable &&
"BuildVirtualCall = kext vtbl pointer is null");
279 CGF.
Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex,
"vfnkxt");
282 CGCallee Callee(GD.getDecl(), VFunc);
294 "BuildAppleKextVirtualCall - bad Qual kind");
299 assert(RT &&
"BuildAppleKextVirtualCall - Qual type must be record");
300 const auto *RD = cast<CXXRecordDecl>(RT->
getDecl());
302 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(MD))
303 return BuildAppleKextVirtualDestructorCall(DD,
Dtor_Complete, RD);
317 const CGFunctionInfo &FInfo = CGM.getTypes().arrangeCXXStructorDeclaration(
319 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
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.
void setAliasAttributes(const Decl *D, llvm::GlobalValue *GV)
Set attributes which must be preserved by an alias.
GlobalDecl getCanonicalDecl() const
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
void setFunctionDefinitionAttributes(const FunctionDecl *D, llvm::Function *F)
Set attributes for a global definition.
const T * getAs() const
Member-template getAs<specific type>'.
void setFunctionDLLStorageClass(GlobalDecl GD, llvm::Function *F)
Set the DLL storage class on F.
const CGFunctionInfo & arrangeCXXStructorDeclaration(const CXXMethodDecl *MD, StructorType 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
llvm::Constant * getAddrOfCXXStructor(const CXXMethodDecl *MD, StructorType Type, 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 Type * getAsType() const
Retrieve the type stored in this nested name specifier.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
llvm::Function * codegenCXXStructor(const CXXMethodDecl *MD, StructorType Type)
CharUnits - This is an opaque type for sizes expressed in character units.
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
uint64_t getMethodVTableIndex(GlobalDecl GD)
Locate a virtual function in the vtable.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
CXXDtorType
C++ destructor types.
const FunctionProtoType * T
Represents a C++ destructor within a class.
llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD)
const TargetInfo & getTarget() const
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
bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target)
Try to emit a definition as a global alias for another definition.
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.
ItaniumVTableContext & getItaniumVTableContext()
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
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...
CXXDtorType toCXXDtorType(StructorType T)
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
Returns 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)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
const VTableLayout & getVTableLayout(const CXXRecordDecl *RD)
Represents a C++ struct/union/class.
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
CGCXXABI & getCXXABI() const
CXXCtorType toCXXCtorType(StructorType T)
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