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;
120 if (!llvm::GlobalAlias::isValidLinkage(Linkage))
123 llvm::GlobalValue::LinkageTypes TargetLinkage =
129 if (Entry && !Entry->isDeclaration())
131 if (Replacements.count(MangledName))
136 llvm::PointerType *AliasType = AliasValueType->getPointerTo();
142 llvm::Constant *Aliasee = Ref;
143 if (Ref->getType() != AliasType)
144 Aliasee = llvm::ConstantExpr::getBitCast(Ref, AliasType);
148 if (llvm::GlobalValue::isDiscardableIfUnused(Linkage) &&
149 !(TargetLinkage == llvm::GlobalValue::AvailableExternallyLinkage &&
165 if (llvm::GlobalValue::isWeakForLinker(Linkage) &&
173 if (Ref->isDeclarationForLinker())
180 if (llvm::GlobalValue::isWeakForLinker(TargetLinkage))
188 Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
192 assert(Entry->getType() == AliasType &&
193 "declaration exists with different type");
194 Alias->takeName(Entry);
195 Entry->replaceAllUsesWith(Alias);
196 Entry->eraseFromParent();
198 Alias->setName(MangledName);
211 auto *Fn = cast<llvm::Function>(
216 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(MD)) {
219 const auto *CD = cast<CXXConstructorDecl>(MD);
226 setNonAliasAttributes(GD, Fn);
233 llvm::FunctionType *FnType,
bool DontDefer,
236 if (
auto *CD = dyn_cast<CXXConstructorDecl>(MD)) {
253 return GetOrCreateLLVMFunction(
255 false, llvm::AttributeList(), IsForDefinition);
263 "No kext in Microsoft ABI");
266 Ty = Ty->getPointerTo()->getPointerTo();
268 assert(VTable &&
"BuildVirtualCall = kext vtbl pointer is null");
269 uint64_t VTableIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
270 const VTableLayout &VTLayout = CGM.getItaniumVTableContext().getVTableLayout(RD);
276 CGF.
Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex,
"vfnkxt");
291 "BuildAppleKextVirtualCall - bad Qual kind");
296 assert(RT &&
"BuildAppleKextVirtualCall - Qual type must be record");
297 const auto *RD = cast<CXXRecordDecl>(RT->
getDecl());
299 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(MD))
300 return BuildAppleKextVirtualDestructorCall(DD,
Dtor_Complete, RD);
314 const CGFunctionInfo &FInfo = CGM.getTypes().arrangeCXXStructorDeclaration(
316 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.
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>'.
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.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
CXXDtorType
C++ destructor types.
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
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).
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