clang: lib/CodeGen/CGCXX.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
26using namespace clang;
27using namespace CodeGen;
28
29
30
31
34 return true;
35
36
37
39 return true;
40
41
42
44 return true;
45
46
47
49 ->getParent()->field_empty())
50 return true;
51
52
53
54 if (->hasTrivialBody())
55 return true;
56
58
59
60
61 if (Class->mayInsertExtraPadding())
62 return true;
63
64
65 if (Class->getNumVBases()) {
66
67
68
69 return true;
70 }
71
72
73
74 for (const auto *I : Class->fields())
75 if (I->getType().isDestructedType())
76 return true;
77
78
80 for (const auto &I : Class->bases()) {
81
82
83 if (I.isVirtual()) continue;
84
85
86 const auto *Base =
87 cast(I.getType()->castAs<RecordType>()->getDecl());
88 if (Base->hasTrivialDestructor()) continue;
89
90
91
92 if (UniqueBase) return true;
93 UniqueBase = Base;
94 }
95
96
97
98
99
100 if (!UniqueBase)
101 return true;
102
103
106 return true;
107
108
109
113 return true;
114
117
118
119
121
122
123 if (!llvm::GlobalAlias::isValidLinkage(Linkage))
124 return true;
125
126 llvm::GlobalValue::LinkageTypes TargetLinkage =
128
129
131 llvm::GlobalValue *Entry = GetGlobalValue(MangledName);
132 if (Entry && !Entry->isDeclaration())
133 return false;
134 if (Replacements.count(MangledName))
135 return false;
136
138
139
140 auto *Aliasee = castllvm::GlobalValue(GetAddrOfGlobal(TargetDecl));
141
142
143
144 if (llvm::GlobalValue::isDiscardableIfUnused(Linkage) &&
145 !(TargetLinkage == llvm::GlobalValue::AvailableExternallyLinkage &&
146 TargetDecl.getDecl()->hasAttr())) {
147
148
149
150
151
153 return false;
154 }
155
156
157
158
159
160
161 if (llvm::GlobalValue::isWeakForLinker(Linkage) &&
162 getTriple().isOSBinFormatCOFF()) {
163 return true;
164 }
165
166
167
168
169 if (Aliasee->isDeclarationForLinker())
170 return true;
171
172
173
174
175
176 if (llvm::GlobalValue::isWeakForLinker(TargetLinkage))
177 return true;
178
179
180 auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0, Linkage, "",
182
183
184 Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
185
186
187 if (Entry) {
188 assert(Entry->getValueType() == AliasValueType &&
189 Entry->getAddressSpace() == Alias->getAddressSpace() &&
190 "declaration exists with different type");
191 Alias->takeName(Entry);
192 Entry->replaceAllUsesWith(Alias);
193 Entry->eraseFromParent();
194 } else {
195 Alias->setName(MangledName);
196 }
197
198
200
201 return false;
202}
203
206 auto *Fn = castllvm::Function(
209
211
213 setNonAliasAttributes(GD, Fn);
215 return Fn;
216}
217
221 auto *MD = cast(GD.getDecl());
222
223 if (isa(MD)) {
224
225
228 MD->getParent()->getNumVBases() == 0)
230 }
231
232 if (!FnType) {
233 if (!FnInfo)
236 }
237
238 llvm::Constant *Ptr = GetOrCreateLLVMFunction(
239 getMangledName(GD), FnType, GD, false, DontDefer,
240 false, llvm::AttributeList(), IsForDefinition);
241 return {FnType, Ptr};
242}
243
246 llvm::Type *Ty,
249 "No kext in Microsoft ABI");
252 Ty = llvm::PointerType::getUnqual(CGM.getLLVMContext());
253 assert(VTable && "BuildVirtualCall = kext vtbl pointer is null");
260 llvm::Value *VFuncPtr =
261 CGF.Builder.CreateConstInBoundsGEP1_64(Ty, VTable, VTableIndex, "vfnkxt");
264
266 if (auto &Schema =
271 }
272
273 CGCallee Callee(GD, VFunc, PointerAuth);
274 return Callee;
275}
276
277
278
279
283 llvm::Type *Ty) {
285 "BuildAppleKextVirtualCall - bad Qual kind");
286
290 assert(RT && "BuildAppleKextVirtualCall - Qual type must be record");
291 const auto *RD = cast(RT->getDecl());
292
293 if (const auto *DD = dyn_cast(MD))
295
296 return ::BuildAppleKextVirtualCall(*this, MD, Ty, RD);
297}
298
299
300
307
311 return ::BuildAppleKextVirtualCall(*this, GlobalDecl(DD, Type), Ty, RD);
312}
Defines the clang::ASTContext interface.
static CGCallee BuildAppleKextVirtualCall(CodeGenFunction &CGF, GlobalDecl GD, llvm::Type *Ty, const CXXRecordDecl *RD)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
Represents a C++ destructor within a class.
Represents a static or instance method of a struct/union/class.
Represents a C++ struct/union/class.
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
CharUnits - This is an opaque type for sizes expressed in character units.
bool isZero() const
isZero - Test whether the quantity equals zero.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
PointerAuthOptions PointerAuth
Configuration for pointer-signing.
llvm::LoadInst * CreateAlignedLoad(llvm::Type *Ty, llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
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...
All available information about a concrete callee.
CGFunctionInfo - Class to encapsulate the information about a function definition.
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)
CGCallee BuildAppleKextVirtualCall(const CXXMethodDecl *MD, NestedNameSpecifier *Qual, llvm::Type *Ty)
void GenerateCode(GlobalDecl GD, llvm::Function *Fn, const CGFunctionInfo &FnInfo)
CGPointerAuthInfo EmitPointerAuthInfo(const PointerAuthSchema &Schema, llvm::Value *StorageAddress, GlobalDecl SchemaDecl, QualType SchemaType)
This class organizes the cross-function state that is used while generating LLVM code.
llvm::Module & getModule() const
llvm::FunctionCallee getAddrAndTypeOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
llvm::Constant * getAddrOfCXXStructor(GlobalDecl GD, 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.
CodeGenTypes & getTypes()
const TargetInfo & getTarget() const
bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D)
Try to emit a base destructor as an alias to its primary base-class destructor.
CGCXXABI & getCXXABI() const
llvm::Function * codegenCXXStructor(GlobalDecl GD)
const llvm::Triple & getTriple() const
llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD)
void setFunctionLinkage(GlobalDecl GD, llvm::Function *F)
llvm::Constant * GetAddrOfGlobal(GlobalDecl GD, ForDefinition_t IsForDefinition=NotForDefinition)
ItaniumVTableContext & getItaniumVTableContext()
const CodeGenOptions & getCodeGenOpts() const
StringRef getMangledName(GlobalDecl GD)
void SetCommonAttributes(GlobalDecl GD, llvm::GlobalValue *GV)
Set attributes which are common to any form of a global definition (alias, Objective-C method,...
llvm::LLVMContext & getLLVMContext()
llvm::GlobalValue * GetGlobalValue(StringRef Ref)
void addReplacement(StringRef Name, llvm::Constant *C)
void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F)
Set the LLVM function attributes which only apply to a function definition.
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
const CGFunctionInfo & arrangeCXXStructorDeclaration(GlobalDecl GD)
FunctionType - C99 6.7.5.3 - Function Declarators.
CallingConv getCallConv() const
GlobalDecl - represents a global declaration.
GlobalDecl getCanonicalDecl() const
GlobalDecl getWithDtorType(CXXDtorType Type)
CXXDtorType getDtorType() const
const Decl * getDecl() const
uint64_t getMethodVTableIndex(GlobalDecl GD)
Locate a virtual function in the vtable.
const VTableLayout & getVTableLayout(const CXXRecordDecl *RD)
GlobalDecl findOriginalMethod(GlobalDecl GD)
Return the method that added the v-table slot that will be used to call the given method.
Represents a C++ nested name specifier, such as "\::std::vector::".
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
@ TypeSpec
A type, stored as a Type*.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
A (possibly-)qualified type.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
RecordDecl * getDecl() const
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
The base class of the type hierarchy.
const T * castAs() const
Member-template castAs.
const T * getAs() const
Member-template getAs'.
size_t getVTableOffset(size_t i) const
AddressPointLocation getAddressPoint(BaseSubobject Base) const
The JSON file list parser is used to communicate input to InstallAPI.
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
CXXDtorType
C++ destructor types.
@ Dtor_Base
Base object dtor.
@ Dtor_Complete
Complete object dtor.
const FunctionProtoType * T
@ Class
The "class" keyword introduces the elaborated-type-specifier.
unsigned char PointerAlignInBytes
PointerAuthSchema CXXVirtualFunctionPointers
The ABI for most C++ virtual function pointers, i.e. v-table entries.
unsigned AddressPointIndex