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;
28
29
30
31
34 return true;
35
36
37
39 return true;
40
41
42
44 return true;
45
46
47
50 return true;
51
52
53
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 = I.getType()->castAsCXXRecordDecl();
87 if (Base->hasTrivialDestructor()) continue;
88
89
90
91 if (UniqueBase) return true;
92 UniqueBase = Base;
93 }
94
95
96
97
98
99 if (!UniqueBase)
100 return true;
101
102
105 return true;
106
107
108
112 return true;
113
116
117
118
120
121
122 if (!llvm::GlobalAlias::isValidLinkage(Linkage))
123 return true;
124
125 llvm::GlobalValue::LinkageTypes TargetLinkage =
127
128
130 llvm::GlobalValue *Entry = GetGlobalValue(MangledName);
131 if (Entry && !Entry->isDeclaration())
132 return false;
133 if (Replacements.count(MangledName))
134 return false;
135
137
138
140
141
142
143 if (llvm::GlobalValue::isDiscardableIfUnused(Linkage) &&
144 !(TargetLinkage == llvm::GlobalValue::AvailableExternallyLinkage &&
145 TargetDecl.getDecl()->hasAttr())) {
146
147
148
149
150
152 return false;
153 }
154
155
156
157
158
159
160 if (llvm::GlobalValue::isWeakForLinker(Linkage) &&
161 getTriple().isOSBinFormatCOFF()) {
162 return true;
163 }
164
165
166
167
168 if (Aliasee->isDeclarationForLinker())
169 return true;
170
171
172
173
174
175 if (llvm::GlobalValue::isWeakForLinker(TargetLinkage))
176 return true;
177
178 auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0, Linkage, "",
180
181
182 Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
183
184
185 if (Entry) {
186 assert(Entry->getValueType() == AliasValueType &&
187 Entry->getAddressSpace() == Alias->getAddressSpace() &&
188 "declaration exists with different type");
189 Alias->takeName(Entry);
190 Entry->replaceAllUsesWith(Alias);
191 Entry->eraseFromParent();
192 } else {
193 Alias->setName(MangledName);
194 }
195
196
198
199 return false;
200}
201
202
205
207
209 llvm::GlobalValue *Entry = GetGlobalValue(MangledName);
210 if (Entry && !Entry->isDeclaration())
211 return;
213
214
216
217
218 auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0, Linkage, "",
220
221 Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
222
223 if (Entry) {
224 assert(Entry->getValueType() == AliasValueType &&
225 Entry->getAddressSpace() == Alias->getAddressSpace() &&
226 "declaration exists with different type");
227 Alias->takeName(Entry);
228 Entry->replaceAllUsesWith(Alias);
229 Entry->eraseFromParent();
230 } else {
231 Alias->setName(MangledName);
232 }
233
234
236}
237
243
245
247 setNonAliasAttributes(GD, Fn);
249 return Fn;
250}
251
256
258
259
262 MD->getParent()->getNumVBases() == 0)
264 }
265
266 if (!FnType) {
267 if (!FnInfo)
270 }
271
272 llvm::Constant *Ptr = GetOrCreateLLVMFunction(
273 getMangledName(GD), FnType, GD, false, DontDefer,
274 false, llvm::AttributeList(), IsForDefinition);
275 return {FnType, Ptr};
276}
277
280 llvm::Type *Ty,
283 "No kext in Microsoft ABI");
286 Ty = llvm::PointerType::getUnqual(CGM.getLLVMContext());
287 assert(VTable && "BuildVirtualCall = kext vtbl pointer is null");
294 llvm::Value *VFuncPtr =
295 CGF.Builder.CreateConstInBoundsGEP1_64(Ty, VTable, VTableIndex, "vfnkxt");
298
300 if (auto &Schema =
305 }
306
307 CGCallee Callee(GD, VFunc, PointerAuth);
308 return Callee;
309}
310
311
312
313
316 llvm::Type *Ty) {
318 assert(RD && "BuildAppleKextVirtualCall - Qual must be record");
319 if (const auto *DD = dyn_cast(MD))
321
322 return ::BuildAppleKextVirtualCall(*this, MD, Ty, RD);
323}
324
325
326
333
334 const CGFunctionInfo &FInfo = CGM.getTypes().arrangeCXXStructorDeclaration(
336 llvm::Type *Ty = CGM.getTypes().GetFunctionType(FInfo);
337 return ::BuildAppleKextVirtualCall(*this, GlobalDecl(DD, Type), Ty, RD);
338}
Defines the clang::ASTContext interface.
static CGCallee BuildAppleKextVirtualCall(CodeGenFunction &CGF, GlobalDecl GD, llvm::Type *Ty, const CXXRecordDecl *RD)
Definition CGCXX.cpp:278
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
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.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
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...
void GenerateCode(GlobalDecl GD, llvm::Function *Fn, const CGFunctionInfo &FnInfo)
CGCallee BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD, CXXDtorType Type, const CXXRecordDecl *RD)
BuildVirtualCall - This routine makes indirect vtable call for call to virtual destructors.
Definition CGCXX.cpp:328
CGPointerAuthInfo EmitPointerAuthInfo(const PointerAuthSchema &Schema, llvm::Value *StorageAddress, GlobalDecl SchemaDecl, QualType SchemaType)
Emit the concrete pointer authentication informaton for the given authentication schema.
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...
Definition CGCXX.cpp:314
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)
Definition CGCXX.cpp:252
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.
Definition CGCXX.cpp:32
CGCXXABI & getCXXABI() const
void EmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target)
Emit a definition as a global alias for another definition, unconditionally.
Definition CGCXX.cpp:203
llvm::Function * codegenCXXStructor(GlobalDecl GD)
Definition CGCXX.cpp:238
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)
bool hasTrivialBody() const
Returns whether the function has a trivial body that does not require any specific codegen.
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::".
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier, or null.
A (possibly-)qualified type.
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
const T * castAs() const
Member-template castAs.
size_t getVTableOffset(size_t i) const
AddressPointLocation getAddressPoint(BaseSubobject Base) const
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
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.
U cast(CodeGen::Address addr)
@ 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