clang 8.0.0

CGVTables.cpp
Go to the documentation of this file.
1 //===--- CGVTables.cpp - Emit LLVM Code for C++ vtables -------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This contains code dealing with C++ code generation of virtual tables.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "CGCXXABI.h"
15 #include "CodeGenFunction.h"
16 #include "CodeGenModule.h"
17 #include "clang/AST/CXXInheritance.h"
18 #include "clang/AST/RecordLayout.h"
19 #include "clang/Basic/CodeGenOptions.h"
20 #include "clang/CodeGen/CGFunctionInfo.h"
21 #include "clang/CodeGen/ConstantInitBuilder.h"
22 #include "llvm/IR/IntrinsicInst.h"
23 #include "llvm/Support/Format.h"
24 #include "llvm/Transforms/Utils/Cloning.h"
25 #include <algorithm>
26 #include <cstdio>
27
28 using namespace clang;
29 using namespace CodeGen;
30
31 CodeGenVTables::CodeGenVTables(CodeGenModule &CGM)
32 : CGM(CGM), VTContext(CGM.getContext().getVTableContext()) {}
33
34 llvm::Constant *CodeGenModule::GetAddrOfThunk(StringRef Name, llvm::Type *FnTy,
35 GlobalDecl GD) {
36 return GetOrCreateLLVMFunction(Name, FnTy, GD, /*ForVTable=*/true,
37 /*DontDefer=*/true, /*IsThunk=*/true);
38 }
39
40 static void setThunkProperties(CodeGenModule &CGM, const ThunkInfo &Thunk,
41 llvm::Function *ThunkFn, bool ForVTable,
42 GlobalDecl GD) {
43 CGM.setFunctionLinkage(GD, ThunkFn);
44 CGM.getCXXABI().setThunkLinkage(ThunkFn, ForVTable, GD,
45 !Thunk.Return.isEmpty());
46
47 // Set the right visibility.
48 CGM.setGVProperties(ThunkFn, GD);
49
50 if (!CGM.getCXXABI().exportThunk()) {
51 ThunkFn->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
52 ThunkFn->setDSOLocal(true);
53 }
54
55 if (CGM.supportsCOMDAT() && ThunkFn->isWeakForLinker())
56 ThunkFn->setComdat(CGM.getModule().getOrInsertComdat(ThunkFn->getName()));
57 }
58
59 #ifndef NDEBUG
60 static bool similar(const ABIArgInfo &infoL, CanQualType typeL,
61 const ABIArgInfo &infoR, CanQualType typeR) {
62 return (infoL.getKind() == infoR.getKind() &&
63 (typeL == typeR ||
64 (isa<PointerType>(typeL) && isa<PointerType>(typeR)) ||
65 (isa<ReferenceType>(typeL) && isa<ReferenceType>(typeR))));
66 }
67 #endif
68
69 static RValue PerformReturnAdjustment(CodeGenFunction &CGF,
70 QualType ResultType, RValue RV,
71 const ThunkInfo &Thunk) {
72 // Emit the return adjustment.
73 bool NullCheckValue = !ResultType->isReferenceType();
74
75 llvm::BasicBlock *AdjustNull = nullptr;
76 llvm::BasicBlock *AdjustNotNull = nullptr;
77 llvm::BasicBlock *AdjustEnd = nullptr;
78
79 llvm::Value *ReturnValue = RV.getScalarVal();
80
81 if (NullCheckValue) {
82 AdjustNull = CGF.createBasicBlock("adjust.null");
83 AdjustNotNull = CGF.createBasicBlock("adjust.notnull");
84 AdjustEnd = CGF.createBasicBlock("adjust.end");
85
86 llvm::Value *IsNull = CGF.Builder.CreateIsNull(ReturnValue);
87 CGF.Builder.CreateCondBr(IsNull, AdjustNull, AdjustNotNull);
88 CGF.EmitBlock(AdjustNotNull);
89 }
90
91 auto ClassDecl = ResultType->getPointeeType()->getAsCXXRecordDecl();
92 auto ClassAlign = CGF.CGM.getClassPointerAlignment(ClassDecl);
93 ReturnValue = CGF.CGM.getCXXABI().performReturnAdjustment(CGF,
94 Address(ReturnValue, ClassAlign),
95 Thunk.Return);
96
97 if (NullCheckValue) {
98 CGF.Builder.CreateBr(AdjustEnd);
99 CGF.EmitBlock(AdjustNull);
100 CGF.Builder.CreateBr(AdjustEnd);
101 CGF.EmitBlock(AdjustEnd);
102
103 llvm::PHINode *PHI = CGF.Builder.CreatePHI(ReturnValue->getType(), 2);
104 PHI->addIncoming(ReturnValue, AdjustNotNull);
105 PHI->addIncoming(llvm::Constant::getNullValue(ReturnValue->getType()),
106 AdjustNull);
107 ReturnValue = PHI;
108 }
109
110 return RValue::get(ReturnValue);
111 }
112
113 /// This function clones a function's DISubprogram node and enters it into
114 /// a value map with the intent that the map can be utilized by the cloner
115 /// to short-circuit Metadata node mapping.
116 /// Furthermore, the function resolves any DILocalVariable nodes referenced
117 /// by dbg.value intrinsics so they can be properly mapped during cloning.
118 static void resolveTopLevelMetadata(llvm::Function *Fn,
119 llvm::ValueToValueMapTy &VMap) {
120 // Clone the DISubprogram node and put it into the Value map.
121 auto *DIS = Fn->getSubprogram();
122 if (!DIS)
123 return;
124 auto *NewDIS = DIS->replaceWithDistinct(DIS->clone());
125 VMap.MD()[DIS].reset(NewDIS);
126
127 // Find all llvm.dbg.declare intrinsics and resolve the DILocalVariable nodes
128 // they are referencing.
129 for (auto &BB : Fn->getBasicBlockList()) {
130 for (auto &I : BB) {
131 if (auto *DII = dyn_cast<llvm::DbgVariableIntrinsic>(&I)) {
132 auto *DILocal = DII->getVariable();
133 if (!DILocal->isResolved())
134 DILocal->resolve();
135 }
136 }
137 }
138 }
139
140 // This function does roughly the same thing as GenerateThunk, but in a
141 // very different way, so that va_start and va_end work correctly.
142 // FIXME: This function assumes "this" is the first non-sret LLVM argument of
143 // a function, and that there is an alloca built in the entry block
144 // for all accesses to "this".
145 // FIXME: This function assumes there is only one "ret" statement per function.
146 // FIXME: Cloning isn't correct in the presence of indirect goto!
147 // FIXME: This implementation of thunks bloats codesize by duplicating the
148 // function definition. There are alternatives:
149 // 1. Add some sort of stub support to LLVM for cases where we can
150 // do a this adjustment, then a sibcall.
151 // 2. We could transform the definition to take a va_list instead of an
152 // actual variable argument list, then have the thunks (including a
153 // no-op thunk for the regular definition) call va_start/va_end.
154 // There's a bit of per-call overhead for this solution, but it's
155 // better for codesize if the definition is long.
156 llvm::Function *
157 CodeGenFunction::GenerateVarArgsThunk(llvm::Function *Fn,
158 const CGFunctionInfo &FnInfo,
159 GlobalDecl GD, const ThunkInfo &Thunk) {
160 const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
161 const FunctionProtoType *FPT = MD->getType()->getAs<FunctionProtoType>();
162 QualType ResultType = FPT->getReturnType();
163
164 // Get the original function
165 assert(FnInfo.isVariadic());
166 llvm::Type *Ty = CGM.getTypes().GetFunctionType(FnInfo);
167 llvm::Value *Callee = CGM.GetAddrOfFunction(GD, Ty, /*ForVTable=*/true);
168 llvm::Function *BaseFn = cast<llvm::Function>(Callee);
169
170 // Clone to thunk.
171 llvm::ValueToValueMapTy VMap;
172
173 // We are cloning a function while some Metadata nodes are still unresolved.
174 // Ensure that the value mapper does not encounter any of them.
175 resolveTopLevelMetadata(BaseFn, VMap);
176 llvm::Function *NewFn = llvm::CloneFunction(BaseFn, VMap);
177 Fn->replaceAllUsesWith(NewFn);
178 NewFn->takeName(Fn);
179 Fn->eraseFromParent();
180 Fn = NewFn;
181
182 // "Initialize" CGF (minimally).
183 CurFn = Fn;
184
185 // Get the "this" value
186 llvm::Function::arg_iterator AI = Fn->arg_begin();
187 if (CGM.ReturnTypeUsesSRet(FnInfo))
188 ++AI;
189
190 // Find the first store of "this", which will be to the alloca associated
191 // with "this".
192 Address ThisPtr(&*AI, CGM.getClassPointerAlignment(MD->getParent()));
193 llvm::BasicBlock *EntryBB = &Fn->front();
194 llvm::BasicBlock::iterator ThisStore =
195 std::find_if(EntryBB->begin(), EntryBB->end(), [&](llvm::Instruction &I) {
196 return isa<llvm::StoreInst>(I) &&
197 I.getOperand(0) == ThisPtr.getPointer();
198 });
199 assert(ThisStore != EntryBB->end() &&
200 "Store of this should be in entry block?");
201 // Adjust "this", if necessary.
202 Builder.SetInsertPoint(&*ThisStore);
203 llvm::Value *AdjustedThisPtr =
204 CGM.getCXXABI().performThisAdjustment(*this, ThisPtr, Thunk.This);
205 ThisStore->setOperand(0, AdjustedThisPtr);
206
207 if (!Thunk.Return.isEmpty()) {
208 // Fix up the returned value, if necessary.
209 for (llvm::BasicBlock &BB : *Fn) {
210 llvm::Instruction *T = BB.getTerminator();
211 if (isa<llvm::ReturnInst>(T)) {
212 RValue RV = RValue::get(T->getOperand(0));
213 T->eraseFromParent();
214 Builder.SetInsertPoint(&BB);
215 RV = PerformReturnAdjustment(*this, ResultType, RV, Thunk);
216 Builder.CreateRet(RV.getScalarVal());
217 break;
218 }
219 }
220 }
221
222 return Fn;
223 }
224
225 void CodeGenFunction::StartThunk(llvm::Function *Fn, GlobalDecl GD,
226 const CGFunctionInfo &FnInfo,
227 bool IsUnprototyped) {
228 assert(!CurGD.getDecl() && "CurGD was already set!");
229 CurGD = GD;
230 CurFuncIsThunk = true;
231
232 // Build FunctionArgs.
233 const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
234 QualType ThisType = MD->getThisType();
235 const FunctionProtoType *FPT = MD->getType()->getAs<FunctionProtoType>();
236 QualType ResultType;
237 if (IsUnprototyped)
238 ResultType = CGM.getContext().VoidTy;
239 else if (CGM.getCXXABI().HasThisReturn(GD))
240 ResultType = ThisType;
241 else if (CGM.getCXXABI().hasMostDerivedReturn(GD))
242 ResultType = CGM.getContext().VoidPtrTy;
243 else
244 ResultType = FPT->getReturnType();
245 FunctionArgList FunctionArgs;
246
247 // Create the implicit 'this' parameter declaration.
248 CGM.getCXXABI().buildThisParam(*this, FunctionArgs);
249
250 // Add the rest of the parameters, if we have a prototype to work with.
251 if (!IsUnprototyped) {
252 FunctionArgs.append(MD->param_begin(), MD->param_end());
253
254 if (isa<CXXDestructorDecl>(MD))
255 CGM.getCXXABI().addImplicitStructorParams(*this, ResultType,
256 FunctionArgs);
257 }
258
259 // Start defining the function.
260 auto NL = ApplyDebugLocation::CreateEmpty(*this);
261 StartFunction(GlobalDecl(), ResultType, Fn, FnInfo, FunctionArgs,
262 MD->getLocation());
263 // Create a scope with an artificial location for the body of this function.
264 auto AL = ApplyDebugLocation::CreateArtificial(*this);
265
266 // Since we didn't pass a GlobalDecl to StartFunction, do this ourselves.
267 CGM.getCXXABI().EmitInstanceFunctionProlog(*this);
268 CXXThisValue = CXXABIThisValue;
269 CurCodeDecl = MD;
270 CurFuncDecl = MD;
271 }
272
273 void CodeGenFunction::FinishThunk() {
274 // Clear these to restore the invariants expected by
275 // StartFunction/FinishFunction.
276 CurCodeDecl = nullptr;
277 CurFuncDecl = nullptr;
278
279 FinishFunction();
280 }
281
282 void CodeGenFunction::EmitCallAndReturnForThunk(llvm::Constant *CalleePtr,
283 const ThunkInfo *Thunk,
284 bool IsUnprototyped) {
285 assert(isa<CXXMethodDecl>(CurGD.getDecl()) &&
286 "Please use a new CGF for this thunk");
287 const CXXMethodDecl *MD = cast<CXXMethodDecl>(CurGD.getDecl());
288
289 // Adjust the 'this' pointer if necessary
290 llvm::Value *AdjustedThisPtr =
291 Thunk ? CGM.getCXXABI().performThisAdjustment(
292 *this, LoadCXXThisAddress(), Thunk->This)
293 : LoadCXXThis();
294
295 if (CurFnInfo->usesInAlloca() || IsUnprototyped) {
296 // We don't handle return adjusting thunks, because they require us to call
297 // the copy constructor. For now, fall through and pretend the return
298 // adjustment was empty so we don't crash.
299 if (Thunk && !Thunk->Return.isEmpty()) {
300 if (IsUnprototyped)
301 CGM.ErrorUnsupported(
302 MD, "return-adjusting thunk with incomplete parameter type");
303 else
304 CGM.ErrorUnsupported(
305 MD, "non-trivial argument copy for return-adjusting thunk");
306 }
307 EmitMustTailThunk(CurGD, AdjustedThisPtr, CalleePtr);
308 return;
309 }
310
311 // Start building CallArgs.
312 CallArgList CallArgs;
313 QualType ThisType = MD->getThisType();
314 CallArgs.add(RValue::get(AdjustedThisPtr), ThisType);
315
316 if (isa<CXXDestructorDecl>(MD))
317 CGM.getCXXABI().adjustCallArgsForDestructorThunk(*this, CurGD, CallArgs);
318
319 #ifndef NDEBUG
320 unsigned PrefixArgs = CallArgs.size() - 1;
321 #endif
322 // Add the rest of the arguments.
323 for (const ParmVarDecl *PD : MD->parameters())
324 EmitDelegateCallArg(CallArgs, PD, SourceLocation());
325
326 const FunctionProtoType *FPT = MD->getType()->getAs<FunctionProtoType>();
327
328 #ifndef NDEBUG
329 const CGFunctionInfo &CallFnInfo = CGM.getTypes().arrangeCXXMethodCall(
330 CallArgs, FPT, RequiredArgs::forPrototypePlus(FPT, 1, MD), PrefixArgs);
331 assert(CallFnInfo.getRegParm() == CurFnInfo->getRegParm() &&
332 CallFnInfo.isNoReturn() == CurFnInfo->isNoReturn() &&
333 CallFnInfo.getCallingConvention() == CurFnInfo->getCallingConvention());
334 assert(isa<CXXDestructorDecl>(MD) || // ignore dtor return types
335 similar(CallFnInfo.getReturnInfo(), CallFnInfo.getReturnType(),
336 CurFnInfo->getReturnInfo(), CurFnInfo->getReturnType()));
337 assert(CallFnInfo.arg_size() == CurFnInfo->arg_size());
338 for (unsigned i = 0, e = CurFnInfo->arg_size(); i != e; ++i)
339 assert(similar(CallFnInfo.arg_begin()[i].info,
340 CallFnInfo.arg_begin()[i].type,
341 CurFnInfo->arg_begin()[i].info,
342 CurFnInfo->arg_begin()[i].type));
343 #endif
344
345 // Determine whether we have a return value slot to use.
346 QualType ResultType = CGM.getCXXABI().HasThisReturn(CurGD)
347 ? ThisType
348 : CGM.getCXXABI().hasMostDerivedReturn(CurGD)
349 ? CGM.getContext().VoidPtrTy
350 : FPT->getReturnType();
351 ReturnValueSlot Slot;
352 if (!ResultType->isVoidType() &&
353 CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect)
354 Slot = ReturnValueSlot(ReturnValue, ResultType.isVolatileQualified());
355
356 // Now emit our call.
357 llvm::Instruction *CallOrInvoke;
358 CGCallee Callee = CGCallee::forDirect(CalleePtr, CurGD);
359 RValue RV = EmitCall(*CurFnInfo, Callee, Slot, CallArgs, &CallOrInvoke);
360
361 // Consider return adjustment if we have ThunkInfo.
362 if (Thunk && !Thunk->Return.isEmpty())
363 RV = PerformReturnAdjustment(*this, ResultType, RV, *Thunk);
364 else if (llvm::CallInst* Call = dyn_cast<llvm::CallInst>(CallOrInvoke))
365 Call->setTailCallKind(llvm::CallInst::TCK_Tail);
366
367 // Emit return.
368 if (!ResultType->isVoidType() && Slot.isNull())
369 CGM.getCXXABI().EmitReturnFromThunk(*this, RV, ResultType);
370
371 // Disable the final ARC autorelease.
372 AutoreleaseResult = false;
373
374 FinishThunk();
375 }
376
377 void CodeGenFunction::EmitMustTailThunk(GlobalDecl GD,
378 llvm::Value *AdjustedThisPtr,
379 llvm::Value *CalleePtr) {
380 // Emitting a musttail call thunk doesn't use any of the CGCall.cpp machinery
381 // to translate AST arguments into LLVM IR arguments. For thunks, we know
382 // that the caller prototype more or less matches the callee prototype with
383 // the exception of 'this'.
384 SmallVector<llvm::Value *, 8> Args;
385 for (llvm::Argument &A : CurFn->args())
386 Args.push_back(&A);
387
388 // Set the adjusted 'this' pointer.
389 const ABIArgInfo &ThisAI = CurFnInfo->arg_begin()->info;
390 if (ThisAI.isDirect()) {
391 const ABIArgInfo &RetAI = CurFnInfo->getReturnInfo();
392 int ThisArgNo = RetAI.isIndirect() && !RetAI.isSRetAfterThis() ? 1 : 0;
393 llvm::Type *ThisType = Args[ThisArgNo]->getType();
394 if (ThisType != AdjustedThisPtr->getType())
395 AdjustedThisPtr = Builder.CreateBitCast(AdjustedThisPtr, ThisType);
396 Args[ThisArgNo] = AdjustedThisPtr;
397 } else {
398 assert(ThisAI.isInAlloca() && "this is passed directly or inalloca");
399 Address ThisAddr = GetAddrOfLocalVar(CXXABIThisDecl);
400 llvm::Type *ThisType = ThisAddr.getElementType();
401 if (ThisType != AdjustedThisPtr->getType())
402 AdjustedThisPtr = Builder.CreateBitCast(AdjustedThisPtr, ThisType);
403 Builder.CreateStore(AdjustedThisPtr, ThisAddr);
404 }
405
406 // Emit the musttail call manually. Even if the prologue pushed cleanups, we
407 // don't actually want to run them.
408 llvm::CallInst *Call = Builder.CreateCall(CalleePtr, Args);
409 Call->setTailCallKind(llvm::CallInst::TCK_MustTail);
410
411 // Apply the standard set of call attributes.
412 unsigned CallingConv;
413 llvm::AttributeList Attrs;
414 CGM.ConstructAttributeList(CalleePtr->getName(), *CurFnInfo, GD, Attrs,
415 CallingConv, /*AttrOnCallSite=*/true);
416 Call->setAttributes(Attrs);
417 Call->setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv));
418
419 if (Call->getType()->isVoidTy())
420 Builder.CreateRetVoid();
421 else
422 Builder.CreateRet(Call);
423
424 // Finish the function to maintain CodeGenFunction invariants.
425 // FIXME: Don't emit unreachable code.
426 EmitBlock(createBasicBlock());
427 FinishFunction();
428 }
429
430 void CodeGenFunction::generateThunk(llvm::Function *Fn,
431 const CGFunctionInfo &FnInfo, GlobalDecl GD,
432 const ThunkInfo &Thunk,
433 bool IsUnprototyped) {
434 StartThunk(Fn, GD, FnInfo, IsUnprototyped);
435 // Create a scope with an artificial location for the body of this function.
436 auto AL = ApplyDebugLocation::CreateArtificial(*this);
437
438 // Get our callee. Use a placeholder type if this method is unprototyped so
439 // that CodeGenModule doesn't try to set attributes.
440 llvm::Type *Ty;
441 if (IsUnprototyped)
442 Ty = llvm::StructType::get(getLLVMContext());
443 else
444 Ty = CGM.getTypes().GetFunctionType(FnInfo);
445
446 llvm::Constant *Callee = CGM.GetAddrOfFunction(GD, Ty, /*ForVTable=*/true);
447
448 // Fix up the function type for an unprototyped musttail call.
449 if (IsUnprototyped)
450 Callee = llvm::ConstantExpr::getBitCast(Callee, Fn->getType());
451
452 // Make the call and return the result.
453 EmitCallAndReturnForThunk(Callee, &Thunk, IsUnprototyped);
454 }
455
456 static bool shouldEmitVTableThunk(CodeGenModule &CGM, const CXXMethodDecl *MD,
457 bool IsUnprototyped, bool ForVTable) {
458 // Always emit thunks in the MS C++ ABI. We cannot rely on other TUs to
459 // provide thunks for us.
460 if (CGM.getTarget().getCXXABI().isMicrosoft())
461 return true;
462
463 // In the Itanium C++ ABI, vtable thunks are provided by TUs that provide
464 // definitions of the main method. Therefore, emitting thunks with the vtable
465 // is purely an optimization. Emit the thunk if optimizations are enabled and
466 // all of the parameter types are complete.
467 if (ForVTable)
468 return CGM.getCodeGenOpts().OptimizationLevel && !IsUnprototyped;
469
470 // Always emit thunks along with the method definition.
471 return true;
472 }
473
474 llvm::Constant *CodeGenVTables::maybeEmitThunk(GlobalDecl GD,
475 const ThunkInfo &TI,
476 bool ForVTable) {
477 const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
478
479 // First, get a declaration. Compute the mangled name. Don't worry about
480 // getting the function prototype right, since we may only need this
481 // declaration to fill in a vtable slot.
482 SmallString<256> Name;
483 MangleContext &MCtx = CGM.getCXXABI().getMangleContext();
484 llvm::raw_svector_ostream Out(Name);
485 if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD))
486 MCtx.mangleCXXDtorThunk(DD, GD.getDtorType(), TI.This, Out);
487 else
488 MCtx.mangleThunk(MD, TI, Out);
489 llvm::Type *ThunkVTableTy = CGM.getTypes().GetFunctionTypeForVTable(GD);
490 llvm::Constant *Thunk = CGM.GetAddrOfThunk(Name, ThunkVTableTy, GD);
491
492 // If we don't need to emit a definition, return this declaration as is.
493 bool IsUnprototyped = !CGM.getTypes().isFuncTypeConvertible(
494 MD->getType()->castAs<FunctionType>());
495 if (!shouldEmitVTableThunk(CGM, MD, IsUnprototyped, ForVTable))
496 return Thunk;
497
498 // Arrange a function prototype appropriate for a function definition. In some
499 // cases in the MS ABI, we may need to build an unprototyped musttail thunk.
500 const CGFunctionInfo &FnInfo =
501 IsUnprototyped ? CGM.getTypes().arrangeUnprototypedMustTailThunk(MD)
502 : CGM.getTypes().arrangeGlobalDeclaration(GD);
503 llvm::FunctionType *ThunkFnTy = CGM.getTypes().GetFunctionType(FnInfo);
504
505 // If the type of the underlying GlobalValue is wrong, we'll have to replace
506 // it. It should be a declaration.
507 llvm::Function *ThunkFn = cast<llvm::Function>(Thunk->stripPointerCasts());
508 if (ThunkFn->getFunctionType() != ThunkFnTy) {
509 llvm::GlobalValue *OldThunkFn = ThunkFn;
510
511 assert(OldThunkFn->isDeclaration() && "Shouldn't replace non-declaration");
512
513 // Remove the name from the old thunk function and get a new thunk.
514 OldThunkFn->setName(StringRef());
515 ThunkFn = llvm::Function::Create(ThunkFnTy, llvm::Function::ExternalLinkage,
516 Name.str(), &CGM.getModule());
517 CGM.SetLLVMFunctionAttributes(MD, FnInfo, ThunkFn);
518
519 // If needed, replace the old thunk with a bitcast.
520 if (!OldThunkFn->use_empty()) {
521 llvm::Constant *NewPtrForOldDecl =
522 llvm::ConstantExpr::getBitCast(ThunkFn, OldThunkFn->getType());
523 OldThunkFn->replaceAllUsesWith(NewPtrForOldDecl);
524 }
525
526 // Remove the old thunk.
527 OldThunkFn->eraseFromParent();
528 }
529
530 bool ABIHasKeyFunctions = CGM.getTarget().getCXXABI().hasKeyFunctions();
531 bool UseAvailableExternallyLinkage = ForVTable && ABIHasKeyFunctions;
532
533 if (!ThunkFn->isDeclaration()) {
534 if (!ABIHasKeyFunctions || UseAvailableExternallyLinkage) {
535 // There is already a thunk emitted for this function, do nothing.
536 return ThunkFn;
537 }
538
539 setThunkProperties(CGM, TI, ThunkFn, ForVTable, GD);
540 return ThunkFn;
541 }
542
543 // If this will be unprototyped, add the "thunk" attribute so that LLVM knows
544 // that the return type is meaningless. These thunks can be used to call
545 // functions with differing return types, and the caller is required to cast
546 // the prototype appropriately to extract the correct value.
547 if (IsUnprototyped)
548 ThunkFn->addFnAttr("thunk");
549
550 CGM.SetLLVMFunctionAttributesForDefinition(GD.getDecl(), ThunkFn);
551
552 if (!IsUnprototyped && ThunkFn->isVarArg()) {
553 // Varargs thunks are special; we can't just generate a call because
554 // we can't copy the varargs. Our implementation is rather
555 // expensive/sucky at the moment, so don't generate the thunk unless
556 // we have to.
557 // FIXME: Do something better here; GenerateVarArgsThunk is extremely ugly.
558 if (UseAvailableExternallyLinkage)
559 return ThunkFn;
560 ThunkFn = CodeGenFunction(CGM).GenerateVarArgsThunk(ThunkFn, FnInfo, GD,
561 TI);
562 } else {
563 // Normal thunk body generation.
564 CodeGenFunction(CGM).generateThunk(ThunkFn, FnInfo, GD, TI, IsUnprototyped);
565 }
566
567 setThunkProperties(CGM, TI, ThunkFn, ForVTable, GD);
568 return ThunkFn;
569 }
570
571 void CodeGenVTables::EmitThunks(GlobalDecl GD) {
572 const CXXMethodDecl *MD =
573 cast<CXXMethodDecl>(GD.getDecl())->getCanonicalDecl();
574
575 // We don't need to generate thunks for the base destructor.
576 if (isa<CXXDestructorDecl>(MD) && GD.getDtorType() == Dtor_Base)
577 return;
578
579 const VTableContextBase::ThunkInfoVectorTy *ThunkInfoVector =
580 VTContext->getThunkInfo(GD);
581
582 if (!ThunkInfoVector)
583 return;
584
585 for (const ThunkInfo& Thunk : *ThunkInfoVector)
586 maybeEmitThunk(GD, Thunk, /*ForVTable=*/false);
587 }
588
589 void CodeGenVTables::addVTableComponent(
590 ConstantArrayBuilder &builder, const VTableLayout &layout,
591 unsigned idx, llvm::Constant *rtti, unsigned &nextVTableThunkIndex) {
592 auto &component = layout.vtable_components()[idx];
593
594 auto addOffsetConstant = [&](CharUnits offset) {
595 builder.add(llvm::ConstantExpr::getIntToPtr(
596 llvm::ConstantInt::get(CGM.PtrDiffTy, offset.getQuantity()),
597 CGM.Int8PtrTy));
598 };
599
600 switch (component.getKind()) {
601 case VTableComponent::CK_VCallOffset:
602 return addOffsetConstant(component.getVCallOffset());
603
604 case VTableComponent::CK_VBaseOffset:
605 return addOffsetConstant(component.getVBaseOffset());
606
607 case VTableComponent::CK_OffsetToTop:
608 return addOffsetConstant(component.getOffsetToTop());
609
610 case VTableComponent::CK_RTTI:
611 return builder.add(llvm::ConstantExpr::getBitCast(rtti, CGM.Int8PtrTy));
612
613 case VTableComponent::CK_FunctionPointer:
614 case VTableComponent::CK_CompleteDtorPointer:
615 case VTableComponent::CK_DeletingDtorPointer: {
616 GlobalDecl GD;
617
618 // Get the right global decl.
619 switch (component.getKind()) {
620 default:
621 llvm_unreachable("Unexpected vtable component kind");
622 case VTableComponent::CK_FunctionPointer:
623 GD = component.getFunctionDecl();
624 break;
625 case VTableComponent::CK_CompleteDtorPointer:
626 GD = GlobalDecl(component.getDestructorDecl(), Dtor_Complete);
627 break;
628 case VTableComponent::CK_DeletingDtorPointer:
629 GD = GlobalDecl(component.getDestructorDecl(), Dtor_Deleting);
630 break;
631 }
632
633 if (CGM.getLangOpts().CUDA) {
634 // Emit NULL for methods we can't codegen on this
635 // side. Otherwise we'd end up with vtable with unresolved
636 // references.
637 const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
638 // OK on device side: functions w/ __device__ attribute
639 // OK on host side: anything except __device__-only functions.
640 bool CanEmitMethod =
641 CGM.getLangOpts().CUDAIsDevice
642 ? MD->hasAttr<CUDADeviceAttr>()
643 : (MD->hasAttr<CUDAHostAttr>() || !MD->hasAttr<CUDADeviceAttr>());
644 if (!CanEmitMethod)
645 return builder.addNullPointer(CGM.Int8PtrTy);
646 // Method is acceptable, continue processing as usual.
647 }
648
649 auto getSpecialVirtualFn = [&](StringRef name) {
650 llvm::FunctionType *fnTy =
651 llvm::FunctionType::get(CGM.VoidTy, /*isVarArg=*/false);
652 llvm::Constant *fn = CGM.CreateRuntimeFunction(fnTy, name);
653 if (auto f = dyn_cast<llvm::Function>(fn))
654 f->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
655 return llvm::ConstantExpr::getBitCast(fn, CGM.Int8PtrTy);
656 };
657
658 llvm::Constant *fnPtr;
659
660 // Pure virtual member functions.
661 if (cast<CXXMethodDecl>(GD.getDecl())->isPure()) {
662 if (!PureVirtualFn)
663 PureVirtualFn =
664 getSpecialVirtualFn(CGM.getCXXABI().GetPureVirtualCallName());
665 fnPtr = PureVirtualFn;
666
667 // Deleted virtual member functions.
668 } else if (cast<CXXMethodDecl>(GD.getDecl())->isDeleted()) {
669 if (!DeletedVirtualFn)
670 DeletedVirtualFn =
671 getSpecialVirtualFn(CGM.getCXXABI().GetDeletedVirtualCallName());
672 fnPtr = DeletedVirtualFn;
673
674 // Thunks.
675 } else if (nextVTableThunkIndex < layout.vtable_thunks().size() &&
676 layout.vtable_thunks()[nextVTableThunkIndex].first == idx) {
677 auto &thunkInfo = layout.vtable_thunks()[nextVTableThunkIndex].second;
678
679 nextVTableThunkIndex++;
680 fnPtr = maybeEmitThunk(GD, thunkInfo, /*ForVTable=*/true);
681
682 // Otherwise we can use the method definition directly.
683 } else {
684 llvm::Type *fnTy = CGM.getTypes().GetFunctionTypeForVTable(GD);
685 fnPtr = CGM.GetAddrOfFunction(GD, fnTy, /*ForVTable=*/true);
686 }
687
688 fnPtr = llvm::ConstantExpr::getBitCast(fnPtr, CGM.Int8PtrTy);
689 builder.add(fnPtr);
690 return;
691 }
692
693 case VTableComponent::CK_UnusedFunctionPointer:
694 return builder.addNullPointer(CGM.Int8PtrTy);
695 }
696
697 llvm_unreachable("Unexpected vtable component kind");
698 }
699
700 llvm::Type *CodeGenVTables::getVTableType(const VTableLayout &layout) {
701 SmallVector<llvm::Type *, 4> tys;
702 for (unsigned i = 0, e = layout.getNumVTables(); i != e; ++i) {
703 tys.push_back(llvm::ArrayType::get(CGM.Int8PtrTy, layout.getVTableSize(i)));
704 }
705
706 return llvm::StructType::get(CGM.getLLVMContext(), tys);
707 }
708
709 void CodeGenVTables::createVTableInitializer(ConstantStructBuilder &builder,
710 const VTableLayout &layout,
711 llvm::Constant *rtti) {
712 unsigned nextVTableThunkIndex = 0;
713 for (unsigned i = 0, e = layout.getNumVTables(); i != e; ++i) {
714 auto vtableElem = builder.beginArray(CGM.Int8PtrTy);
715 size_t thisIndex = layout.getVTableOffset(i);
716 size_t nextIndex = thisIndex + layout.getVTableSize(i);
717 for (unsigned i = thisIndex; i != nextIndex; ++i) {
718 addVTableComponent(vtableElem, layout, i, rtti, nextVTableThunkIndex);
719 }
720 vtableElem.finishAndAddTo(builder);
721 }
722 }
723
724 llvm::GlobalVariable *
725 CodeGenVTables::GenerateConstructionVTable(const CXXRecordDecl *RD,
726 const BaseSubobject &Base,
727 bool BaseIsVirtual,
728 llvm::GlobalVariable::LinkageTypes Linkage,
729 VTableAddressPointsMapTy& AddressPoints) {
730 if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
731 DI->completeClassData(Base.getBase());
732
733 std::unique_ptr<VTableLayout> VTLayout(
734 getItaniumVTableContext().createConstructionVTableLayout(
735 Base.getBase(), Base.getBaseOffset(), BaseIsVirtual, RD));
736
737 // Add the address points.
738 AddressPoints = VTLayout->getAddressPoints();
739
740 // Get the mangled construction vtable name.
741 SmallString<256> OutName;
742 llvm::raw_svector_ostream Out(OutName);
743 cast<ItaniumMangleContext>(CGM.getCXXABI().getMangleContext())
744 .mangleCXXCtorVTable(RD, Base.getBaseOffset().getQuantity(),
745 Base.getBase(), Out);
746 StringRef Name = OutName.str();
747
748 llvm::Type *VTType = getVTableType(*VTLayout);
749
750 // Construction vtable symbols are not part of the Itanium ABI, so we cannot
751 // guarantee that they actually will be available externally. Instead, when
752 // emitting an available_externally VTT, we provide references to an internal
753 // linkage construction vtable. The ABI only requires complete-object vtables
754 // to be the same for all instances of a type, not construction vtables.
755 if (Linkage == llvm::GlobalVariable::AvailableExternallyLinkage)
756 Linkage = llvm::GlobalVariable::InternalLinkage;
757
758 unsigned Align = CGM.getDataLayout().getABITypeAlignment(VTType);
759
760 // Create the variable that will hold the construction vtable.
761 llvm::GlobalVariable *VTable =
762 CGM.CreateOrReplaceCXXRuntimeVariable(Name, VTType, Linkage, Align);
763 CGM.setGVProperties(VTable, RD);
764
765 // V-tables are always unnamed_addr.
766 VTable->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
767
768 llvm::Constant *RTTI = CGM.GetAddrOfRTTIDescriptor(
769 CGM.getContext().getTagDeclType(Base.getBase()));
770
771 // Create and set the initializer.
772 ConstantInitBuilder builder(CGM);
773 auto components = builder.beginStruct();
774 createVTableInitializer(components, *VTLayout, RTTI);
775 components.finishAndSetAsInitializer(VTable);
776
777 CGM.EmitVTableTypeMetadata(VTable, *VTLayout.get());
778
779 return VTable;
780 }
781
782 static bool shouldEmitAvailableExternallyVTable(const CodeGenModule &CGM,
783 const CXXRecordDecl *RD) {
784 return CGM.getCodeGenOpts().OptimizationLevel > 0 &&
785 CGM.getCXXABI().canSpeculativelyEmitVTable(RD);
786 }
787
788 /// Compute the required linkage of the vtable for the given class.
789 ///
790 /// Note that we only call this at the end of the translation unit.
791 llvm::GlobalVariable::LinkageTypes
792 CodeGenModule::getVTableLinkage(const CXXRecordDecl *RD) {
793 if (!RD->isExternallyVisible())
794 return llvm::GlobalVariable::InternalLinkage;
795
796 // We're at the end of the translation unit, so the current key
797 // function is fully correct.
798 const CXXMethodDecl *keyFunction = Context.getCurrentKeyFunction(RD);
799 if (keyFunction && !RD->hasAttr<DLLImportAttr>()) {
800 // If this class has a key function, use that to determine the
801 // linkage of the vtable.
802 const FunctionDecl *def = nullptr;
803 if (keyFunction->hasBody(def))
804 keyFunction = cast<CXXMethodDecl>(def);
805
806 switch (keyFunction->getTemplateSpecializationKind()) {
807 case TSK_Undeclared:
808 case TSK_ExplicitSpecialization:
809 assert((def || CodeGenOpts.OptimizationLevel > 0 ||
810 CodeGenOpts.getDebugInfo() != codegenoptions::NoDebugInfo) &&
811 "Shouldn't query vtable linkage without key function, "
812 "optimizations, or debug info");
813 if (!def && CodeGenOpts.OptimizationLevel > 0)
814 return llvm::GlobalVariable::AvailableExternallyLinkage;
815
816 if (keyFunction->isInlined())
817 return !Context.getLangOpts().AppleKext ?
818 llvm::GlobalVariable::LinkOnceODRLinkage :
819 llvm::Function::InternalLinkage;
820
821 return llvm::GlobalVariable::ExternalLinkage;
822
823 case TSK_ImplicitInstantiation:
824 return !Context.getLangOpts().AppleKext ?
825 llvm::GlobalVariable::LinkOnceODRLinkage :
826 llvm::Function::InternalLinkage;
827
828 case TSK_ExplicitInstantiationDefinition:
829 return !Context.getLangOpts().AppleKext ?
830 llvm::GlobalVariable::WeakODRLinkage :
831 llvm::Function::InternalLinkage;
832
833 case TSK_ExplicitInstantiationDeclaration:
834 llvm_unreachable("Should not have been asked to emit this");
835 }
836 }
837
838 // -fapple-kext mode does not support weak linkage, so we must use
839 // internal linkage.
840 if (Context.getLangOpts().AppleKext)
841 return llvm::Function::InternalLinkage;
842
843 llvm::GlobalVariable::LinkageTypes DiscardableODRLinkage =
844 llvm::GlobalValue::LinkOnceODRLinkage;
845 llvm::GlobalVariable::LinkageTypes NonDiscardableODRLinkage =
846 llvm::GlobalValue::WeakODRLinkage;
847 if (RD->hasAttr<DLLExportAttr>()) {
848 // Cannot discard exported vtables.
849 DiscardableODRLinkage = NonDiscardableODRLinkage;
850 } else if (RD->hasAttr<DLLImportAttr>()) {
851 // Imported vtables are available externally.
852 DiscardableODRLinkage = llvm::GlobalVariable::AvailableExternallyLinkage;
853 NonDiscardableODRLinkage = llvm::GlobalVariable::AvailableExternallyLinkage;
854 }
855
856 switch (RD->getTemplateSpecializationKind()) {
857 case TSK_Undeclared:
858 case TSK_ExplicitSpecialization:
859 case TSK_ImplicitInstantiation:
860 return DiscardableODRLinkage;
861
862 case TSK_ExplicitInstantiationDeclaration:
863 // Explicit instantiations in MSVC do not provide vtables, so we must emit
864 // our own.
865 if (getTarget().getCXXABI().isMicrosoft())
866 return DiscardableODRLinkage;
867 return shouldEmitAvailableExternallyVTable(*this, RD)
868 ? llvm::GlobalVariable::AvailableExternallyLinkage
869 : llvm::GlobalVariable::ExternalLinkage;
870
871 case TSK_ExplicitInstantiationDefinition:
872 return NonDiscardableODRLinkage;
873 }
874
875 llvm_unreachable("Invalid TemplateSpecializationKind!");
876 }
877
878 /// This is a callback from Sema to tell us that a particular vtable is
879 /// required to be emitted in this translation unit.
880 ///
881 /// This is only called for vtables that _must_ be emitted (mainly due to key
882 /// functions). For weak vtables, CodeGen tracks when they are needed and
883 /// emits them as-needed.
884 void CodeGenModule::EmitVTable(CXXRecordDecl *theClass) {
885 VTables.GenerateClassData(theClass);
886 }
887
888 void
889 CodeGenVTables::GenerateClassData(const CXXRecordDecl *RD) {
890 if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
891 DI->completeClassData(RD);
892
893 if (RD->getNumVBases())
894 CGM.getCXXABI().emitVirtualInheritanceTables(RD);
895
896 CGM.getCXXABI().emitVTableDefinitions(*this, RD);
897 }
898
899 /// At this point in the translation unit, does it appear that can we
900 /// rely on the vtable being defined elsewhere in the program?
901 ///
902 /// The response is really only definitive when called at the end of
903 /// the translation unit.
904 ///
905 /// The only semantic restriction here is that the object file should
906 /// not contain a vtable definition when that vtable is defined
907 /// strongly elsewhere. Otherwise, we'd just like to avoid emitting
908 /// vtables when unnecessary.
909 bool CodeGenVTables::isVTableExternal(const CXXRecordDecl *RD) {
910 assert(RD->isDynamicClass() && "Non-dynamic classes have no VTable.");
911
912 // We always synthesize vtables if they are needed in the MS ABI. MSVC doesn't
913 // emit them even if there is an explicit template instantiation.
914 if (CGM.getTarget().getCXXABI().isMicrosoft())
915 return false;
916
917 // If we have an explicit instantiation declaration (and not a
918 // definition), the vtable is defined elsewhere.
919 TemplateSpecializationKind TSK = RD->getTemplateSpecializationKind();
920 if (TSK == TSK_ExplicitInstantiationDeclaration)
921 return true;
922
923 // Otherwise, if the class is an instantiated template, the
924 // vtable must be defined here.
925 if (TSK == TSK_ImplicitInstantiation ||
926 TSK == TSK_ExplicitInstantiationDefinition)
927 return false;
928
929 // Otherwise, if the class doesn't have a key function (possibly
930 // anymore), the vtable must be defined here.
931 const CXXMethodDecl *keyFunction = CGM.getContext().getCurrentKeyFunction(RD);
932 if (!keyFunction)
933 return false;
934
935 // Otherwise, if we don't have a definition of the key function, the
936 // vtable must be defined somewhere else.
937 return !keyFunction->hasBody();
938 }
939
940 /// Given that we're currently at the end of the translation unit, and
941 /// we've emitted a reference to the vtable for this class, should
942 /// we define that vtable?
943 static bool shouldEmitVTableAtEndOfTranslationUnit(CodeGenModule &CGM,
944 const CXXRecordDecl *RD) {
945 // If vtable is internal then it has to be done.
946 if (!CGM.getVTables().isVTableExternal(RD))
947 return true;
948
949 // If it's external then maybe we will need it as available_externally.
950 return shouldEmitAvailableExternallyVTable(CGM, RD);
951 }
952
953 /// Given that at some point we emitted a reference to one or more
954 /// vtables, and that we are now at the end of the translation unit,
955 /// decide whether we should emit them.
956 void CodeGenModule::EmitDeferredVTables() {
957 #ifndef NDEBUG
958 // Remember the size of DeferredVTables, because we're going to assume
959 // that this entire operation doesn't modify it.
960 size_t savedSize = DeferredVTables.size();
961 #endif
962
963 for (const CXXRecordDecl *RD : DeferredVTables)
964 if (shouldEmitVTableAtEndOfTranslationUnit(*this, RD))
965 VTables.GenerateClassData(RD);
966 else if (shouldOpportunisticallyEmitVTables())
967 OpportunisticVTables.push_back(RD);
968
969 assert(savedSize == DeferredVTables.size() &&
970 "deferred extra vtables during vtable emission?");
971 DeferredVTables.clear();
972 }
973
974 bool CodeGenModule::HasHiddenLTOVisibility(const CXXRecordDecl *RD) {
975 LinkageInfo LV = RD->getLinkageAndVisibility();
976 if (!isExternallyVisible(LV.getLinkage()))
977 return true;
978
979 if (RD->hasAttr<LTOVisibilityPublicAttr>() || RD->hasAttr<UuidAttr>())
980 return false;
981
982 if (getTriple().isOSBinFormatCOFF()) {
983 if (RD->hasAttr<DLLExportAttr>() || RD->hasAttr<DLLImportAttr>())
984 return false;
985 } else {
986 if (LV.getVisibility() != HiddenVisibility)
987 return false;
988 }
989
990 if (getCodeGenOpts().LTOVisibilityPublicStd) {
991 const DeclContext *DC = RD;
992 while (1) {
993 auto *D = cast<Decl>(DC);
994 DC = DC->getParent();
995 if (isa<TranslationUnitDecl>(DC->getRedeclContext())) {
996 if (auto *ND = dyn_cast<NamespaceDecl>(D))
997 if (const IdentifierInfo *II = ND->getIdentifier())
998 if (II->isStr("std") || II->isStr("stdext"))
999 return false;
1000 break;
1001 }
1002 }
1003 }
1004
1005 return true;
1006 }
1007
1008 void CodeGenModule::EmitVTableTypeMetadata(llvm::GlobalVariable *VTable,
1009 const VTableLayout &VTLayout) {
1010 if (!getCodeGenOpts().LTOUnit)
1011 return;
1012
1013 CharUnits PointerWidth =
1014 Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerWidth(0));
1015
1016 typedef std::pair<const CXXRecordDecl *, unsigned> AddressPoint;
1017 std::vector<AddressPoint> AddressPoints;
1018 for (auto &&AP : VTLayout.getAddressPoints())
1019 AddressPoints.push_back(std::make_pair(
1020 AP.first.getBase(), VTLayout.getVTableOffset(AP.second.VTableIndex) +
1021 AP.second.AddressPointIndex));
1022
1023 // Sort the address points for determinism.
1024 llvm::sort(AddressPoints, [this](const AddressPoint &AP1,
1025 const AddressPoint &AP2) {
1026 if (&AP1 == &AP2)
1027 return false;
1028
1029 std::string S1;
1030 llvm::raw_string_ostream O1(S1);
1031 getCXXABI().getMangleContext().mangleTypeName(
1032 QualType(AP1.first->getTypeForDecl(), 0), O1);
1033 O1.flush();
1034
1035 std::string S2;
1036 llvm::raw_string_ostream O2(S2);
1037 getCXXABI().getMangleContext().mangleTypeName(
1038 QualType(AP2.first->getTypeForDecl(), 0), O2);
1039 O2.flush();
1040
1041 if (S1 < S2)
1042 return true;
1043 if (S1 != S2)
1044 return false;
1045
1046 return AP1.second < AP2.second;
1047 });
1048
1049 ArrayRef<VTableComponent> Comps = VTLayout.vtable_components();
1050 for (auto AP : AddressPoints) {
1051 // Create type metadata for the address point.
1052 AddVTableTypeMetadata(VTable, PointerWidth * AP.second, AP.first);
1053
1054 // The class associated with each address point could also potentially be
1055 // used for indirect calls via a member function pointer, so we need to
1056 // annotate the address of each function pointer with the appropriate member
1057 // function pointer type.
1058 for (unsigned I = 0; I != Comps.size(); ++I) {
1059 if (Comps[I].getKind() != VTableComponent::CK_FunctionPointer)
1060 continue;
1061 llvm::Metadata *MD = CreateMetadataIdentifierForVirtualMemPtrType(
1062 Context.getMemberPointerType(
1063 Comps[I].getFunctionDecl()->getType(),
1064 Context.getRecordType(AP.first).getTypePtr()));
1065 VTable->addTypeMetadata((PointerWidth * I).getQuantity(), MD);
1066 }
1067 }
1068 }
clang::CodeGen::CodeGenModule::getDataLayout
const llvm::DataLayout & getDataLayout() const
Definition: CodeGenModule.h:661
clang::VTableLayout::getNumVTables
size_t getNumVTables() const
Definition: VTableBuilder.h:281
clang::CodeGen::ReturnValueSlot
ReturnValueSlot - Contains the address where the return value of a function can be stored...
Definition: CGCall.h:361
getCanonicalDecl
static const Decl * getCanonicalDecl(const Decl *D)
Definition: IndexingContext.cpp:282
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1738
clang::ExternalLinkage
External linkage, which indicates that the entity can be referred to from other translation units...
Definition: Linkage.h:60
clang::CodeGen::CodeGenModule::SetLLVMFunctionAttributes
void SetLLVMFunctionAttributes(GlobalDecl GD, const CGFunctionInfo &Info, llvm::Function *F)
Set the LLVM function attributes (sext, zext, etc).
Definition: CodeGenModule.cpp:1166
clang::ASTContext::VoidPtrTy
CanQualType VoidPtrTy
Definition: ASTContext.h:1044
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:638
clang::CodeGen::CodeGenModule::ReturnTypeUsesSRet
bool ReturnTypeUsesSRet(const CGFunctionInfo &FI)
Return true iff the given type uses &#39;sret&#39; when used as a return type.
Definition: CGCall.cpp:1506
clang::CodeGen::CodeGenModule::getTypes
CodeGenTypes & getTypes()
Definition: CodeGenModule.h:676
clang::CodeGen::CodeGenModule::getCodeGenOpts
const CodeGenOptions & getCodeGenOpts() const
Definition: CodeGenModule.h:658
clang::VTableLayout::getAddressPoints
const AddressPointsMapTy & getAddressPoints() const
Definition: VTableBuilder.h:277
clang::CodeGen::CGCXXABI::EmitReturnFromThunk
virtual void EmitReturnFromThunk(CodeGenFunction &CGF, RValue RV, QualType ResultType)
Definition: CGCXXABI.cpp:163
clang::CodeGen::CodeGenModule::getLLVMContext
llvm::LLVMContext & getLLVMContext()
Definition: CodeGenModule.h:670
clang::GlobalDecl::getDtorType
CXXDtorType getDtorType() const
Definition: GlobalDecl.h:76
clang::CodeGen::CGCXXABI::addImplicitStructorParams
virtual void addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy, FunctionArgList &Params)=0
Insert any ABI-specific implicit parameters into the parameter list for a function.
clang::CodeGen::ConstantInitBuilder
The standard implementation of ConstantInitBuilder used in Clang.
Definition: ConstantInitBuilder.h:517
clang::CodeGen::CodeGenModule::getClassPointerAlignment
CharUnits getClassPointerAlignment(const CXXRecordDecl *CD)
Returns the assumed alignment of an opaque pointer to the given class.
Definition: CGClass.cpp:37
clang::CodeGen::CGFunctionInfo::isVariadic
bool isVariadic() const
Definition: CGFunctionInfo.h:598
clang::FunctionType
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3355
clang::Type::getPointeeType
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:505
clang::CXXRecordDecl::getNumVBases
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
Definition: DeclCXX.h:838
Base
clang::CXXMethodDecl::getThisType
QualType getThisType() const
Returns the type of the this pointer.
Definition: DeclCXX.cpp:2184
clang::ReturnAdjustment::isEmpty
bool isEmpty() const
Definition: ABI.h:87
clang::VTableContextBase::getThunkInfo
virtual const ThunkInfoVectorTy * getThunkInfo(GlobalDecl GD)
Definition: VTableBuilder.h:330
clang::CodeGen::CGCXXABI::performThisAdjustment
virtual llvm::Value * performThisAdjustment(CodeGenFunction &CGF, Address This, const ThisAdjustment &TA)=0
clang::LinkageInfo
Definition: Visibility.h:53
clang::CodeGen::CodeGenModule::setFunctionLinkage
void setFunctionLinkage(GlobalDecl GD, llvm::Function *F)
Definition: CodeGenModule.h:1153
CXXInheritance.h
clang::CodeGen::CGCXXABI::GetDeletedVirtualCallName
virtual StringRef GetDeletedVirtualCallName()=0
Gets the deleted virtual member call name.
clang::ASTContext::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:690
clang::CodeGen::CodeGenFunction::GenerateVarArgsThunk
llvm::Function * GenerateVarArgsThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, GlobalDecl GD, const ThunkInfo &Thunk)
Definition: CGVTables.cpp:157
clang::CodeGen::CodeGenTypes::isFuncTypeConvertible
bool isFuncTypeConvertible(const FunctionType *FT)
isFuncTypeConvertible - Utility to check whether a function type can be converted to an LLVM type (i...
Definition: CodeGenTypes.cpp:229
clang::CodeGen::CodeGenModule::HasHiddenLTOVisibility
bool HasHiddenLTOVisibility(const CXXRecordDecl *RD)
Returns whether the given record has hidden LTO visibility and therefore may participate in (single-m...
Definition: CGVTables.cpp:974
clang::CodeGen::CodeGenFunction::StartThunk
void StartThunk(llvm::Function *Fn, GlobalDecl GD, const CGFunctionInfo &FnInfo, bool IsUnprototyped)
Definition: CGVTables.cpp:225
Value
Value
Definition: UninitializedValues.cpp:102
clang::VTableComponent::CK_VCallOffset
Definition: VTableBuilder.h:33
clang::HiddenVisibility
Objects with "hidden" visibility are not seen by the dynamic linker.
Definition: Visibility.h:37
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6748
clang::LinkageInfo::getVisibility
Visibility getVisibility() const
Definition: Visibility.h:85
clang::CodeGen::CodeGenModule::getModuleDebugInfo
CGDebugInfo * getModuleDebugInfo()
Definition: CodeGenModule.h:644
clang::CodeGen::CodeGenModule::supportsCOMDAT
bool supportsCOMDAT() const
Definition: TargetInfo.cpp:9242
clang::CodeGen::CGDebugInfo
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Definition: CGDebugInfo.h:54
clang::ASTContext::getMemberPointerType
QualType getMemberPointerType(QualType T, const Type *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
Definition: ASTContext.cpp:3040
clang::CodeGen::Address::getPointer
llvm::Value * getPointer() const
Definition: Address.h:38
clang::codegenoptions::NoDebugInfo
Definition: DebugInfoOptions.h:22
clang::CodeGen::CodeGenFunction::EmitMustTailThunk
void EmitMustTailThunk(GlobalDecl GD, llvm::Value *AdjustedThisPtr, llvm::Value *Callee)
Emit a musttail call for a thunk with a potentially adjusted this pointer.
Definition: CGVTables.cpp:377
clang::ParmVarDecl
Represents a parameter to a function.
Definition: Decl.h:1550
clang::Linkage
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
Definition: Linkage.h:24
clang::CodeGen::CallArgList::add
void add(RValue rvalue, QualType type)
Definition: CGCall.h:285
clang::BaseSubobject::getBaseOffset
CharUnits getBaseOffset() const
getBaseOffset - Returns the base class offset.
Definition: BaseSubobject.h:47
clang::TargetInfo::getPointerWidth
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
Definition: TargetInfo.h:349
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:58
clang::TargetInfo::getCXXABI
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
Definition: TargetInfo.h:1022
clang::CodeGen::CodeGenFunction::generateThunk
void generateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, GlobalDecl GD, const ThunkInfo &Thunk, bool IsUnprototyped)
Generate a thunk for the given method.
Definition: CGVTables.cpp:430
clang::CodeGen::ABIArgInfo::Indirect
Indirect - Pass the argument indirectly via a hidden pointer with the specified alignment (0 indicate...
Definition: CGFunctionInfo.h:51
clang::CodeGen::CodeGenFunction
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Definition: CodeGenFunction.h:227
shouldEmitAvailableExternallyVTable
static bool shouldEmitAvailableExternallyVTable(const CodeGenModule &CGM, const CXXRecordDecl *RD)
Definition: CGVTables.cpp:782
clang::Type::isReferenceType
bool isReferenceType() const
Definition: Type.h:6308
resolveTopLevelMetadata
static void resolveTopLevelMetadata(llvm::Function *Fn, llvm::ValueToValueMapTy &VMap)
This function clones a function&#39;s DISubprogram node and enters it into a value map with the intent th...
Definition: CGVTables.cpp:118
clang::CodeGen::CodeGenFunction::Builder
CGBuilderTy Builder
Definition: CodeGenFunction.h:263
clang::CodeGen::CodeGenVTables::getVTableType
llvm::Type * getVTableType(const VTableLayout &layout)
Returns the type of a vtable with the given layout.
Definition: CGVTables.cpp:700
clang::ThunkInfo
The this pointer adjustment as well as an optional return adjustment for a thunk. ...
Definition: ABI.h:179
clang::CodeGen::ABIArgInfo::isInAlloca
bool isInAlloca() const
Definition: CGFunctionInfo.h:262
clang::CodeGen::ApplyDebugLocation::CreateArtificial
static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF)
Apply TemporaryLocation if it is valid.
Definition: CGDebugInfo.h:715
clang::FunctionDecl::parameters
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2262
clang::VTableComponent::CK_RTTI
Definition: VTableBuilder.h:36
clang::CodeGen::CGCXXABI::EmitInstanceFunctionProlog
virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF)=0
Emit the ABI-specific prolog for the function.
clang::VTableLayout::vtable_components
ArrayRef< VTableComponent > vtable_components() const
Definition: VTableBuilder.h:264
clang::CodeGen::CGCXXABI::emitVTableDefinitions
virtual void emitVTableDefinitions(CodeGenVTables &CGVT, const CXXRecordDecl *RD)=0
Emits the VTable definitions required for the given record type.
clang::CharUnits
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
clang::Dtor_Deleting
Deleting dtor.
Definition: ABI.h:35
clang::CodeGen::CGCXXABI::hasMostDerivedReturn
virtual bool hasMostDerivedReturn(GlobalDecl GD) const
Definition: CGCXXABI.h:109
clang::VTableComponent::CK_VBaseOffset
Definition: VTableBuilder.h:34
clang::QualType::isVolatileQualified
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition: Type.h:6142
clang::CodeGen::CodeGenModule::ConstructAttributeList
void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info, CGCalleeInfo CalleeInfo, llvm::AttributeList &Attrs, unsigned &CallingConv, bool AttrOnCallSite)
Get the LLVM attributes and calling convention to use for a particular function type.
Definition: CGCall.cpp:1835
clang::CodeGen::ABIArgInfo
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
Definition: CGFunctionInfo.h:34
clang::CodeGen::CGCXXABI::canSpeculativelyEmitVTable
virtual bool canSpeculativelyEmitVTable(const CXXRecordDecl *RD) const =0
Determine whether it&#39;s possible to emit a vtable for RD, even though we do not know that the vtable h...
clang::QualType::getTypePtr
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6072
clang::CodeGen::CodeGenFunction::createBasicBlock
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
Definition: CodeGenFunction.h:2037
clang::CodeGen::CodeGenVTables::getItaniumVTableContext
ItaniumVTableContext & getItaniumVTableContext()
Definition: CGVTables.h:79
CGFunctionInfo.h
clang::CodeGen::CodeGenTypeCache::VoidTy
llvm::Type * VoidTy
void
Definition: CodeGenTypeCache.h:35
llvm::ArrayRef
Definition: LLVM.h:32
llvm::SmallString
Definition: LLVM.h:35
shouldEmitVTableThunk
static bool shouldEmitVTableThunk(CodeGenModule &CGM, const CXXMethodDecl *MD, bool IsUnprototyped, bool ForVTable)
Definition: CGVTables.cpp:456
clang::CodeGen::CodeGenTypes::arrangeGlobalDeclaration
const CGFunctionInfo & arrangeGlobalDeclaration(GlobalDecl GD)
Definition: CGCall.cpp:516
clang::FunctionDecl::param_begin
param_iterator param_begin()
Definition: Decl.h:2274
clang::CodeGen::CodeGenModule::CreateRuntimeFunction
llvm::Constant * CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList(), bool Local=false)
Create a new runtime function with the specified type and name.
Definition: CodeGenModule.cpp:2957
clang::Decl::hasAttr
bool hasAttr() const
Definition: DeclBase.h:531
clang::Type::getAsCXXRecordDecl
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1613
clang::FunctionProtoType
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3687
clang::CXXRecordDecl::isDynamicClass
bool isDynamicClass() const
Definition: DeclCXX.h:789
clang::CodeGen::ConstantAggregateBuilderTemplateBase::beginArray
ArrayBuilder beginArray(llvm::Type *eltTy=nullptr)
Definition: ConstantInitBuilder.h:344
clang::CXXRecordDecl::getTemplateSpecializationKind
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
Definition: DeclCXX.cpp:1627
clang::CodeGen::RValue
RValue - This trivial value class is used to represent the result of an expression that is evaluated...
Definition: CGValue.h:39
clang::CharUnits::getQuantity
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:179
clang::CodeGen::CodeGenVTables::isVTableExternal
bool isVTableExternal(const CXXRecordDecl *RD)
At this point in the translation unit, does it appear that can we rely on the vtable being defined el...
Definition: CGVTables.cpp:909
clang::CodeGen::CGCXXABI::HasThisReturn
virtual bool HasThisReturn(GlobalDecl GD) const
Returns true if the given constructor or destructor is one of the kinds that the ABI says returns &#39;th...
Definition: CGCXXABI.h:107
clang::TargetCXXABI::hasKeyFunctions
bool hasKeyFunctions() const
Does this ABI use key functions? If so, class data such as the vtable is emitted with strong linkage ...
Definition: TargetCXXABI.h:227
setThunkProperties
static void setThunkProperties(CodeGenModule &CGM, const ThunkInfo &Thunk, llvm::Function *ThunkFn, bool ForVTable, GlobalDecl GD)
Definition: CGVTables.cpp:40
similar
static bool similar(const ABIArgInfo &infoL, CanQualType typeL, const ABIArgInfo &infoR, CanQualType typeR)
Definition: CGVTables.cpp:60
CodeGenModule.h
clang::VTableComponent::CK_FunctionPointer
Definition: VTableBuilder.h:37
clang::Type::castAs
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:6811
clang::CodeGen::CGCallee::forDirect
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
Definition: CGCall.h:134
clang::CXXDestructorDecl
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2706
clang::CodeGen::CGCXXABI::exportThunk
virtual bool exportThunk()=0
clang::ASTContext::getTagDeclType
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
Definition: ASTContext.cpp:4948
clang::CodeGen::CGCXXABI::GetPureVirtualCallName
virtual StringRef GetPureVirtualCallName()=0
Gets the pure virtual member call function.
CGCXXABI.h
clang::LinkageInfo::getLinkage
Linkage getLinkage() const
Definition: Visibility.h:84
clang::BaseSubobject::getBase
const CXXRecordDecl * getBase() const
getBase - Returns the base class declaration.
Definition: BaseSubobject.h:44
clang::CodeGen::CodeGenFunction::EmitCallAndReturnForThunk
void EmitCallAndReturnForThunk(llvm::Constant *Callee, const ThunkInfo *Thunk, bool IsUnprototyped)
Definition: CGVTables.cpp:282
clang::CodeGen::ABIArgInfo::isDirect
bool isDirect() const
Definition: CGFunctionInfo.h:261
clang::FunctionDecl::hasBody
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition: Decl.cpp:2695
clang::Dtor_Base
Base object dtor.
Definition: ABI.h:37
clang::CodeGen::ABIArgInfo::isIndirect
bool isIndirect() const
Definition: CGFunctionInfo.h:265
clang::BaseSubobject
Definition: BaseSubobject.h:31
clang::CodeGen::CodeGenTypes::arrangeUnprototypedMustTailThunk
const CGFunctionInfo & arrangeUnprototypedMustTailThunk(const CXXMethodDecl *MD)
Arrange a thunk that takes &#39;this&#39; as the first parameter followed by varargs.
Definition: CGCall.cpp:535
clang::DeclContext::getParent
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1752
clang::isExternallyVisible
bool isExternallyVisible(Linkage L)
Definition: Linkage.h:86
clang::ASTContext::getRecordType
QualType getRecordType(const RecordDecl *Decl) const
Definition: ASTContext.cpp:3903
clang::CodeGen::CodeGenModule::getTarget
const TargetInfo & getTarget() const
Definition: CodeGenModule.h:664
clang::TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:152
clang::CodeGen::CodeGenModule::getLangOpts
const LangOptions & getLangOpts() const
Definition: CodeGenModule.h:653
clang::CodeGen::CodeGenModule::getContext
ASTContext & getContext() const
Definition: CodeGenModule.h:652
clang::CodeGen::CGCXXABI::adjustCallArgsForDestructorThunk
virtual void adjustCallArgsForDestructorThunk(CodeGenFunction &CGF, GlobalDecl GD, CallArgList &CallArgs)
Definition: CGCXXABI.h:435
CodeGenFunction.h
clang::CallingConv
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:236
clang::GlobalDecl
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:35
clang::CodeGen::ABIArgInfo::getKind
Kind getKind() const
Definition: CGFunctionInfo.h:260
clang::CodeGen::AlignmentSource::Type
The l-value was considered opaque, so the alignment was determined from a type.
clang::VTableLayout::vtable_thunks
ArrayRef< VTableThunkTy > vtable_thunks() const
Definition: VTableBuilder.h:268
clang::MangleContext::mangleCXXDtorThunk
virtual void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type, const ThisAdjustment &ThisAdjustment, raw_ostream &)=0
clang::CodeGen::CodeGenModule::GetAddrOfThunk
llvm::Constant * GetAddrOfThunk(StringRef Name, llvm::Type *FnTy, GlobalDecl GD)
Get the address of the thunk for the given global decl.
Definition: CGVTables.cpp:34
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::FunctionType::getReturnType
QualType getReturnType() const
Definition: Type.h:3613
clang::CodeGen::ABIArgInfo::isSRetAfterThis
bool isSRetAfterThis() const
Definition: CGFunctionInfo.h:371
clang::CodeGen::CodeGenModule::setGVProperties
void setGVProperties(llvm::GlobalValue *GV, GlobalDecl GD) const
Set visibility, dllimport/dllexport and dso_local.
Definition: CodeGenModule.cpp:837
clang::GlobalDecl::getDecl
const Decl * getDecl() const
Definition: GlobalDecl.h:69
clang::MangleContext
MangleContext - Context for tracking state which persists across multiple calls to the C++ name mangl...
Definition: Mangle.h:44
clang::CXXMethodDecl
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2041
clang::CodeGen::CodeGenModule::GetAddrOfRTTIDescriptor
llvm::Constant * GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH=false)
Get the address of the RTTI descriptor for the given type.
Definition: CodeGenModule.cpp:5309
clang::CodeGen::CodeGenVTables::CodeGenVTables
CodeGenVTables(CodeGenModule &CGM)
Definition: CGVTables.cpp:31
clang::CanQual< Type >
clang::ASTContext::VoidTy
CanQualType VoidTy
Definition: ASTContext.h:1016
clang::CodeGen::CodeGenVTables::createVTableInitializer
void createVTableInitializer(ConstantStructBuilder &builder, const VTableLayout &layout, llvm::Constant *rtti)
Add vtable components for the given vtable layout to the given global initializer.
Definition: CGVTables.cpp:709
llvm::SmallVector
Definition: LLVM.h:36
clang::CodeGen::Address
An aligned address.
Definition: Address.h:25
clang::CodeGen::CodeGenModule::SetLLVMFunctionAttributesForDefinition
void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F)
Set the LLVM function attributes which only apply to a function definition.
Definition: CodeGenModule.cpp:1224
clang::CodeGen::CGCXXABI::emitVirtualInheritanceTables
virtual void emitVirtualInheritanceTables(const CXXRecordDecl *RD)=0
Emit any tables needed to implement virtual inheritance.
clang::CodeGen::CGCallee
All available information about a concrete callee.
Definition: CGCall.h:67
clang::CodeGen::CGCXXABI::getMangleContext
MangleContext & getMangleContext()
Gets the mangle context.
Definition: CGCXXABI.h:97
clang::TSK_ExplicitInstantiationDefinition
This template specialization was instantiated from a template due to an explicit instantiation defini...
Definition: Specifiers.h:164
clang::TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared, defined, or instantiated.
Definition: Specifiers.h:149
clang::Dtor_Complete
Complete object dtor.
Definition: ABI.h:36
clang::CodeGen::CodeGenVTables::GenerateConstructionVTable
llvm::GlobalVariable * GenerateConstructionVTable(const CXXRecordDecl *RD, const BaseSubobject &Base, bool BaseIsVirtual, llvm::GlobalVariable::LinkageTypes Linkage, VTableAddressPointsMapTy &AddressPoints)
GenerateConstructionVTable - Generate a construction vtable for the given base subobject.
Definition: CGVTables.cpp:725
clang::CodeGen::FunctionArgList
FunctionArgList - Type for representing both the decl and type of parameters to a function...
Definition: CGCall.h:356
clang::CodeGen::RValue::getScalarVal
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
Definition: CGValue.h:59
clang::CodeGen::CodeGenModule::ErrorUnsupported
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn&#39;t support the specified stmt yet.
Definition: CodeGenModule.cpp:702
clang::CodeGen::CGFunctionInfo
CGFunctionInfo - Class to encapsulate the information about a function definition.
Definition: CGFunctionInfo.h:493
clang::CodeGen::CodeGenModule
This class organizes the cross-function state that is used while generating LLVM code.
Definition: CodeGenModule.h:274
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::CodeGen::ReturnValueSlot::isNull
bool isNull() const
Definition: CGCall.h:378
clang::ThunkInfo::This
ThisAdjustment This
The this pointer adjustment.
Definition: ABI.h:181
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1262
clang::FunctionDecl::getTemplateSpecializationKind
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition: Decl.cpp:3558
clang::CodeGen::CodeGenModule::EmitVTableTypeMetadata
void EmitVTableTypeMetadata(llvm::GlobalVariable *VTable, const VTableLayout &VTLayout)
Emit type metadata for the given vtable using the given layout.
Definition: CGVTables.cpp:1008
CodeGenOptions.h
clang::TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
Definition: Specifiers.h:160
clang::CodeGen::CodeGenFunction::FinishThunk
void FinishThunk()
Definition: CGVTables.cpp:273
clang::CXXMethodDecl::getParent
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
Definition: DeclCXX.h:2166
clang::CodeGen::CGCXXABI::buildThisParam
void buildThisParam(CodeGenFunction &CGF, FunctionArgList &Params)
Build a parameter variable suitable for &#39;this&#39;.
Definition: CGCXXABI.cpp:128
clang::TemplateSpecializationKind
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:146
clang::CodeGen::CodeGenModule::getModule
llvm::Module & getModule() const
Definition: CodeGenModule.h:659
clang::VTableComponent::CK_OffsetToTop
Definition: VTableBuilder.h:35
clang::CodeGen::CodeGenVTables::EmitThunks
void EmitThunks(GlobalDecl GD)
EmitThunks - Emit the associated thunks for the given global decl.
Definition: CGVTables.cpp:571
clang::FunctionDecl::param_end
param_iterator param_end()
Definition: Decl.h:2275
clang::CodeGen::CodeGenModule::getVTableLinkage
llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD)
Return the appropriate linkage for the vtable, VTT, and type information of the given class...
Definition: CGVTables.cpp:792
clang::NamedDecl::getLinkageAndVisibility
LinkageInfo getLinkageAndVisibility() const
Determines the linkage and visibility of this entity.
Definition: Decl.cpp:1070
clang::CodeGen::ConstantInitBuilderTemplateBase::beginStruct
StructBuilder beginStruct(llvm::StructType *structTy=nullptr)
Definition: ConstantInitBuilder.h:500
clang::TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp...
Definition: Specifiers.h:156
clang::CodeGen::CodeGenTypeCache::Int8PtrTy
llvm::PointerType * Int8PtrTy
Definition: CodeGenTypeCache.h:55
shouldEmitVTableAtEndOfTranslationUnit
static bool shouldEmitVTableAtEndOfTranslationUnit(CodeGenModule &CGM, const CXXRecordDecl *RD)
Given that we&#39;re currently at the end of the translation unit, and we&#39;ve emitted a reference to the v...
Definition: CGVTables.cpp:943
clang::CodeGen::CodeGenVTables::GenerateClassData
void GenerateClassData(const CXXRecordDecl *RD)
GenerateClassData - Generate all the class data required to be generated upon definition of a KeyFunc...
Definition: CGVTables.cpp:889
clang::ThunkInfo::Return
ReturnAdjustment Return
The return adjustment.
Definition: ABI.h:184
clang::CodeGen::CodeGenModule::GetAddrOfFunction
llvm::Constant * GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty=nullptr, bool ForVTable=false, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the given function.
Definition: CodeGenModule.cpp:2888
clang::InternalLinkage
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
Definition: Linkage.h:32
clang::CodeGen::CodeGenFunction::EmitBlock
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
Definition: CGStmt.cpp:443
clang::FunctionDecl::isInlined
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
Definition: Decl.h:2356
clang::CodeGen::CodeGenTypes::GetFunctionTypeForVTable
llvm::Type * GetFunctionTypeForVTable(GlobalDecl GD)
GetFunctionTypeForVTable - Get the LLVM function type for use in a vtable, given a CXXMethodDecl...
Definition: CGCall.cpp:1678
clang::CodeGen::CodeGenTypeCache::PtrDiffTy
llvm::IntegerType * PtrDiffTy
Definition: CodeGenTypeCache.h:49
clang::ASTContext::toCharUnitsFromBits
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
Definition: ASTContext.cpp:2156
PerformReturnAdjustment
static RValue PerformReturnAdjustment(CodeGenFunction &CGF, QualType ResultType, RValue RV, const ThunkInfo &Thunk)
Definition: CGVTables.cpp:69
clang::ASTContext::getCurrentKeyFunction
const CXXMethodDecl * getCurrentKeyFunction(const CXXRecordDecl *RD)
Get our current best idea for the key function of the given record decl, or nullptr if there isn&#39;t on...
Definition: RecordLayoutBuilder.cpp:3055
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:300
clang::Type::isVoidType
bool isVoidType() const
Definition: Type.h:6544
RecordLayout.h
clang::MangleContext::mangleThunk
virtual void mangleThunk(const CXXMethodDecl *MD, const ThunkInfo &Thunk, raw_ostream &)=0
clang::CodeGen::ConstantStructBuilder
A helper class of ConstantInitBuilder, used for building constant struct initializers.
Definition: ConstantInitBuilder.h:543
clang::VTableLayout
Definition: VTableBuilder.h:233
clang::VTableLayout::getVTableSize
size_t getVTableSize(size_t i) const
Definition: VTableBuilder.h:295
clang::TargetCXXABI::isMicrosoft
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
Definition: TargetCXXABI.h:154
clang::VTableComponent::CK_DeletingDtorPointer
A pointer to the deleting destructor.
Definition: VTableBuilder.h:43
clang::CodeGen::CodeGenModule::getCXXABI
CGCXXABI & getCXXABI() const
Definition: CodeGenModule.h:669
clang::CodeGen::CodeGenModule::CreateOrReplaceCXXRuntimeVariable
llvm::GlobalVariable * CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty, llvm::GlobalValue::LinkageTypes Linkage, unsigned Alignment)
Will return a global variable of the given type.
Definition: CodeGenModule.cpp:3235
getKind
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:954
clang::CodeGen::RValue::get
static RValue get(llvm::Value *V)
Definition: CGValue.h:86
clang::CodeGen::RequiredArgs::forPrototypePlus
static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype, unsigned additional, const FunctionDecl *FD)
Compute the arguments required by the given formal prototype, given that there may be some additional...
Definition: CGFunctionInfo.h:443
clang::CodeGen::CGCXXABI::performReturnAdjustment
virtual llvm::Value * performReturnAdjustment(CodeGenFunction &CGF, Address Ret, const ReturnAdjustment &RA)=0
ConstantInitBuilder.h
clang::CodeGen::ApplyDebugLocation::CreateEmpty
static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF)
Set the IRBuilder to not attach debug locations.
Definition: CGDebugInfo.h:732
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:648
clang::CodeGen::CodeGenModule::getVTables
CodeGenVTables & getVTables()
Definition: CodeGenModule.h:678
clang::CodeGen::CodeGenFunction::CGM
CodeGenModule & CGM
Definition: CodeGenFunction.h:258
clang::CodeGen::CallArgList
CallArgList - Type for representing both the value and type of arguments in a call.
Definition: CGCall.h:260
clang::CodeGen::CodeGenTypes::arrangeCXXMethodCall
const CGFunctionInfo & arrangeCXXMethodCall(const CallArgList &args, const FunctionProtoType *type, RequiredArgs required, unsigned numPrefixArgs)
Arrange a call to a C++ method, passing the given arguments.
Definition: CGCall.cpp:681
clang::ASTContext::getLangOpts
const LangOptions & getLangOpts() const
Definition: ASTContext.h:707
clang::VTableComponent::CK_CompleteDtorPointer
A pointer to the complete destructor.
Definition: VTableBuilder.h:40
clang::CodeGen::ConstantArrayBuilder
A helper class of ConstantInitBuilder, used for building constant array initializers.
Definition: ConstantInitBuilder.h:526
clang::VTableLayout::getVTableOffset
size_t getVTableOffset(size_t i) const
Definition: VTableBuilder.h:287
clang::VTableComponent::CK_UnusedFunctionPointer
An entry that is never used.
Definition: VTableBuilder.h:50
clang::CodeGen::CGCXXABI::setThunkLinkage
virtual void setThunkLinkage(llvm::Function *Thunk, bool ForVTable, GlobalDecl GD, bool ReturnAdjustment)=0
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:418
clang::NamedDecl::isExternallyVisible
bool isExternallyVisible() const
Definition: Decl.h:380
clang::CodeGen::CodeGenModule::EmitVTable
void EmitVTable(CXXRecordDecl *Class)
This is a callback from Sema to tell us that a particular vtable is required to be emitted in this tr...
Definition: CGVTables.cpp:884
clang::Create
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> PL, ArrayRef< Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.
clang::CodeGen::CodeGenTypes::GetFunctionType
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
Definition: CGCall.cpp:1550