27 #include "llvm/ADT/StringExtras.h"
28 using namespace clang;
29 using namespace CodeGen;
64 for (
const auto *I : Class->
fields())
65 if (I->getType().isDestructedType())
70 for (
const auto &I : Class->
bases()) {
73 if (I.isVirtual())
continue;
77 cast<CXXRecordDecl>(I.getType()->getAs<
RecordType>()->getDecl());
78 if (
Base->hasTrivialDestructor())
continue;
82 if (UniqueBase)
return true;
124 if (!llvm::GlobalAlias::isValidLinkage(Linkage))
129 llvm::GlobalValue::isWeakForLinker(Linkage))
132 llvm::GlobalValue::LinkageTypes TargetLinkage =
138 if (Entry && !Entry->isDeclaration())
140 if (Replacements.count(MangledName))
144 llvm::PointerType *AliasType
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 ||
165 Replacements[MangledName] = Aliasee;
173 if (Ref->isDeclaration())
181 if (llvm::GlobalValue::isWeakForLinker(TargetLinkage))
190 assert(Entry->getType() == AliasType &&
191 "declaration exists with different type");
192 Alias->takeName(Entry);
193 Entry->replaceAllUsesWith(Alias);
194 Entry->eraseFromParent();
196 Alias->setName(MangledName);
209 auto *Fn = cast<llvm::Function>(
213 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(MD)) {
216 const auto *CD = cast<CXXConstructorDecl>(MD);
231 llvm::FunctionType *FnType,
bool DontDefer) {
233 if (
auto *CD = dyn_cast<CXXConstructorDecl>(MD)) {
249 return cast<llvm::Function>(GetOrCreateLLVMFunction(Name, FnType, GD,
259 "No kext in Microsoft ABI");
263 Ty = Ty->getPointerTo()->getPointerTo();
264 VTable = CGF.
Builder.CreateBitCast(VTable, Ty);
265 assert(VTable &&
"BuildVirtualCall = kext vtbl pointer is null");
267 uint64_t AddressPoint =
270 VTableIndex += AddressPoint;
272 CGF.
Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex,
"vfnkxt");
273 return CGF.
Builder.CreateLoad(VFuncPtr);
284 "BuildAppleKextVirtualCall - bad Qual kind");
289 assert(RT &&
"BuildAppleKextVirtualCall - Qual type must be record");
290 const auto *RD = cast<CXXRecordDecl>(RT->
getDecl());
292 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(MD))
305 const auto *MD = cast<CXXMethodDecl>(DD);
309 if (MD->isVirtual() && Type !=
Dtor_Base) {
Defines the clang::ASTContext interface.
CodeGenTypes & getTypes()
llvm::Module & getModule() const
void setAliasAttributes(const Decl *D, llvm::GlobalValue *GV)
void setFunctionLinkage(GlobalDecl GD, llvm::Function *F)
void GenerateCode(GlobalDecl GD, llvm::Function *Fn, const CGFunctionInfo &FnInfo)
bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D)
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
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
llvm::Function * codegenCXXStructor(const CXXMethodDecl *MD, StructorType Type)
const Decl * getDecl() const
uint64_t getAddressPoint(BaseSubobject Base) const
const CXXRecordDecl * getParent() const
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.
llvm::GlobalValue * getAddrOfCXXStructor(const CXXMethodDecl *MD, StructorType Type, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false)
Return the address of the constructor/destructor of the given type.
const TargetInfo & getTarget() const
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)
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
A type, stored as a Type*.
bool mayInsertExtraPadding(bool EmitRemark=false) const
Whether we are allowed to insert extra padding between fields. These padding are added to help Addres...
static llvm::Value * BuildAppleKextVirtualCall(CodeGenFunction &CGF, GlobalDecl GD, llvm::Type *Ty, const CXXRecordDecl *RD)
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)
ItaniumVTableContext & getItaniumVTableContext()
llvm::GlobalValue * GetGlobalValue(StringRef Ref)
bool isZero() const
isZero - Test whether the quantity equals zero.
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
virtual llvm::GlobalVariable * getAddrOfVTable(const CXXRecordDecl *RD, CharUnits VPtrOffset)=0
CXXDtorType toCXXDtorType(StructorType T)
bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target, bool InEveryTU)
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
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)
llvm::Value * BuildAppleKextVirtualCall(const CXXMethodDecl *MD, NestedNameSpecifier *Qual, llvm::Type *Ty)
Represents a C++ struct/union/class.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
llvm::Constant * GetAddrOfGlobal(GlobalDecl GD)
CXXCtorType toCXXCtorType(StructorType T)
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
bool hasTrivialBody() const
llvm::Value * BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD, CXXDtorType Type, const CXXRecordDecl *RD)
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.