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;
131 if (!llvm::GlobalAlias::isValidLinkage(Linkage))
134 llvm::GlobalValue::LinkageTypes TargetLinkage =
139 if (TargetLinkage == llvm::GlobalValue::AvailableExternallyLinkage)
145 if (Entry && !Entry->isDeclaration())
147 if (Replacements.count(MangledName))
152 llvm::PointerType *AliasType = AliasValueType->getPointerTo();
158 llvm::Constant *Aliasee = Ref;
159 if (Ref->getType() != AliasType)
160 Aliasee = llvm::ConstantExpr::getBitCast(Ref, AliasType);
164 if (llvm::GlobalValue::isDiscardableIfUnused(Linkage)) {
174 if (llvm::GlobalValue::isWeakForLinker(Linkage) &&
183 if (Ref->isDeclaration())
191 if (llvm::GlobalValue::isWeakForLinker(TargetLinkage))
200 assert(Entry->getType() == AliasType &&
201 "declaration exists with different type");
202 Alias->takeName(Entry);
203 Entry->replaceAllUsesWith(Alias);
204 Entry->eraseFromParent();
206 Alias->setName(MangledName);
219 auto *Fn = cast<llvm::Function>(
224 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(MD)) {
227 const auto *CD = cast<CXXConstructorDecl>(MD);
242 llvm::FunctionType *FnType,
bool DontDefer,
245 if (
auto *CD = dyn_cast<CXXConstructorDecl>(MD)) {
257 return GetOrCreateLLVMFunction(
259 false, llvm::AttributeList(), IsForDefinition);
267 "No kext in Microsoft ABI");
271 Ty = Ty->getPointerTo()->getPointerTo();
273 assert(VTable &&
"BuildVirtualCall = kext vtbl pointer is null");
281 CGF.
Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex,
"vfnkxt");
284 CGCallee Callee(GD.getDecl(), VFunc);
296 "BuildAppleKextVirtualCall - bad Qual kind");
301 assert(RT &&
"BuildAppleKextVirtualCall - Qual type must be record");
302 const auto *RD = cast<CXXRecordDecl>(RT->
getDecl());
304 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(MD))
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)
llvm::Module & getModule() const
FunctionType - C99 6.7.5.3 - Function Declarators.
void setAliasAttributes(const Decl *D, llvm::GlobalValue *GV)
Set attributes which must be preserved by an alias.
The base class of the type hierarchy.
void setFunctionLinkage(GlobalDecl GD, llvm::Function *F)
void GenerateCode(GlobalDecl GD, llvm::Function *Fn, const CGFunctionInfo &FnInfo)
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.
void setFunctionDLLStorageClass(GlobalDecl GD, llvm::Function *F)
Set the DLL storage class on F.
const CGFunctionInfo & arrangeCXXStructorDeclaration(const CXXMethodDecl *MD, StructorType Type)
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
GlobalDecl getCanonicalDecl() const
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)
BuildVirtualCall - This routine makes indirect vtable call for call to virtual destructors.
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.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
llvm::Function * codegenCXXStructor(const CXXMethodDecl *MD, StructorType Type)
const Decl * getDecl() const
CharUnits - This is an opaque type for sizes expressed in character units.
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
field_range fields() const
RecordDecl * getDecl() const
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D...
uint64_t getMethodVTableIndex(GlobalDecl GD)
Locate a virtual function in the vtable.
detail::InMemoryDirectory::const_iterator I
const TargetInfo & getTarget() const
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
CXXDtorType
C++ destructor types.
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
CGCXXABI & getCXXABI() const
Represents a C++ destructor within a class.
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD)
AddressPointLocation getAddressPoint(BaseSubobject Base) const
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
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.
Address CreateBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
bool mayInsertExtraPadding(bool EmitRemark=false) const
Whether we are allowed to insert extra padding between fields.
Represents a static or instance method of a struct/union/class.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
const CodeGenOptions & getCodeGenOpts() const
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)
bool isZero() const
isZero - Test whether the quantity equals zero.
unsigned char PointerAlignInBytes
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
size_t getVTableOffset(size_t i) const
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)
bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target, bool InEveryTU)
Try to emit a definition as a global alias for another definition.
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.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
const T * getAs() const
Member-template getAs<specific type>'.
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.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
const llvm::Triple & getTriple() const
CXXCtorType toCXXCtorType(StructorType T)
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
bool hasTrivialBody() const
hasTrivialBody - Returns whether the function has a trivial body that does not require any specific c...
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.