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 =
140 if (Entry && !Entry->isDeclaration())
142 if (Replacements.count(MangledName))
147 llvm::PointerType *AliasType = AliasValueType->getPointerTo();
153 llvm::Constant *Aliasee = Ref;
154 if (Ref->getType() != AliasType)
155 Aliasee = llvm::ConstantExpr::getBitCast(Ref, AliasType);
159 if (llvm::GlobalValue::isDiscardableIfUnused(Linkage) &&
160 (TargetLinkage != llvm::GlobalValue::AvailableExternallyLinkage ||
161 !TargetDecl.
getDecl()->hasAttr<AlwaysInlineAttr>())) {
176 if (llvm::GlobalValue::isWeakForLinker(Linkage) &&
185 if (Ref->isDeclaration())
193 if (llvm::GlobalValue::isWeakForLinker(TargetLinkage))
202 assert(Entry->getType() == AliasType &&
203 "declaration exists with different type");
204 Alias->takeName(Entry);
205 Entry->replaceAllUsesWith(Alias);
206 Entry->eraseFromParent();
208 Alias->setName(MangledName);
221 auto *Fn = cast<llvm::Function>(
226 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(MD)) {
229 const auto *CD = cast<CXXConstructorDecl>(MD);
244 llvm::FunctionType *FnType,
bool DontDefer,
bool IsForDefinition) {
246 if (
auto *CD = dyn_cast<CXXConstructorDecl>(MD)) {
258 return GetOrCreateLLVMFunction(
260 false, llvm::AttributeSet(), IsForDefinition);
268 "No kext in Microsoft ABI");
272 Ty = Ty->getPointerTo()->getPointerTo();
274 assert(VTable &&
"BuildVirtualCall = kext vtbl pointer is null");
276 uint64_t AddressPoint =
279 VTableIndex += AddressPoint;
281 CGF.
Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex,
"vfnkxt");
293 "BuildAppleKextVirtualCall - bad Qual kind");
298 assert(RT &&
"BuildAppleKextVirtualCall - Qual type must be record");
299 const auto *RD = cast<CXXRecordDecl>(RT->
getDecl());
301 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(MD))
314 const auto *MD = cast<CXXMethodDecl>(DD);
318 if (MD->isVirtual() && Type !=
Dtor_Base) {
Defines the clang::ASTContext interface.
A (possibly-)qualified type.
CodeGenTypes & getTypes()
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.
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...
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
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...
llvm::Constant * GetAddrOfGlobal(GlobalDecl GD, bool IsForDefinition=false)
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)
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.
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)
Set the LLVM function attributes which only apply to a function definition.
llvm::Constant * getAddrOfCXXStructor(const CXXMethodDecl *MD, StructorType Type, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, bool IsForDefinition=false)
Return the address of the constructor/destructor of the given type.
ItaniumVTableContext & getItaniumVTableContext()
void addReplacement(StringRef Name, llvm::Constant *C)
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.
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.
const llvm::Triple & getTriple() const
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)
llvm::Value * BuildAppleKextVirtualCall(const CXXMethodDecl *MD, NestedNameSpecifier *Qual, llvm::Type *Ty)
BuildAppleKextVirtualCall - This routine is to support gcc's kext ABI making indirect call to virtual...
Represents a C++ struct/union/class.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
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::Value * BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD, CXXDtorType Type, const CXXRecordDecl *RD)
BuildVirtualCall - This routine makes indirect vtable call for call to virtual destructors.
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.