clang  14.0.0git
CGVTables.cpp
Go to the documentation of this file.
1 //===--- CGVTables.cpp - Emit LLVM Code for C++ vtables -------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This contains code dealing with C++ code generation of virtual tables.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "CGCXXABI.h"
14 #include "CodeGenFunction.h"
15 #include "CodeGenModule.h"
16 #include "clang/AST/Attr.h"
18 #include "clang/AST/RecordLayout.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 
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 
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 *
158  const CGFunctionInfo &FnInfo,
159  GlobalDecl GD, const ThunkInfo &Thunk) {
160  const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
161  const FunctionProtoType *FPT = MD->getType()->castAs<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  // Cloning can't work if we don't have a definition. The Microsoft ABI may
171  // require thunks when a definition is not available. Emit an error in these
172  // cases.
173  if (!MD->isDefined()) {
174  CGM.ErrorUnsupported(MD, "return-adjusting thunk with variadic arguments");
175  return Fn;
176  }
177  assert(!BaseFn->isDeclaration() && "cannot clone undefined variadic method");
178 
179  // Clone to thunk.
180  llvm::ValueToValueMapTy VMap;
181 
182  // We are cloning a function while some Metadata nodes are still unresolved.
183  // Ensure that the value mapper does not encounter any of them.
184  resolveTopLevelMetadata(BaseFn, VMap);
185  llvm::Function *NewFn = llvm::CloneFunction(BaseFn, VMap);
186  Fn->replaceAllUsesWith(NewFn);
187  NewFn->takeName(Fn);
188  Fn->eraseFromParent();
189  Fn = NewFn;
190 
191  // "Initialize" CGF (minimally).
192  CurFn = Fn;
193 
194  // Get the "this" value
195  llvm::Function::arg_iterator AI = Fn->arg_begin();
196  if (CGM.ReturnTypeUsesSRet(FnInfo))
197  ++AI;
198 
199  // Find the first store of "this", which will be to the alloca associated
200  // with "this".
201  Address ThisPtr(&*AI, CGM.getClassPointerAlignment(MD->getParent()));
202  llvm::BasicBlock *EntryBB = &Fn->front();
203  llvm::BasicBlock::iterator ThisStore =
204  llvm::find_if(*EntryBB, [&](llvm::Instruction &I) {
205  return isa<llvm::StoreInst>(I) &&
206  I.getOperand(0) == ThisPtr.getPointer();
207  });
208  assert(ThisStore != EntryBB->end() &&
209  "Store of this should be in entry block?");
210  // Adjust "this", if necessary.
211  Builder.SetInsertPoint(&*ThisStore);
212  llvm::Value *AdjustedThisPtr =
213  CGM.getCXXABI().performThisAdjustment(*this, ThisPtr, Thunk.This);
214  AdjustedThisPtr = Builder.CreateBitCast(AdjustedThisPtr,
215  ThisStore->getOperand(0)->getType());
216  ThisStore->setOperand(0, AdjustedThisPtr);
217 
218  if (!Thunk.Return.isEmpty()) {
219  // Fix up the returned value, if necessary.
220  for (llvm::BasicBlock &BB : *Fn) {
221  llvm::Instruction *T = BB.getTerminator();
222  if (isa<llvm::ReturnInst>(T)) {
223  RValue RV = RValue::get(T->getOperand(0));
224  T->eraseFromParent();
225  Builder.SetInsertPoint(&BB);
226  RV = PerformReturnAdjustment(*this, ResultType, RV, Thunk);
227  Builder.CreateRet(RV.getScalarVal());
228  break;
229  }
230  }
231  }
232 
233  return Fn;
234 }
235 
236 void CodeGenFunction::StartThunk(llvm::Function *Fn, GlobalDecl GD,
237  const CGFunctionInfo &FnInfo,
238  bool IsUnprototyped) {
239  assert(!CurGD.getDecl() && "CurGD was already set!");
240  CurGD = GD;
241  CurFuncIsThunk = true;
242 
243  // Build FunctionArgs.
244  const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
245  QualType ThisType = MD->getThisType();
246  QualType ResultType;
247  if (IsUnprototyped)
248  ResultType = CGM.getContext().VoidTy;
249  else if (CGM.getCXXABI().HasThisReturn(GD))
250  ResultType = ThisType;
251  else if (CGM.getCXXABI().hasMostDerivedReturn(GD))
252  ResultType = CGM.getContext().VoidPtrTy;
253  else
254  ResultType = MD->getType()->castAs<FunctionProtoType>()->getReturnType();
255  FunctionArgList FunctionArgs;
256 
257  // Create the implicit 'this' parameter declaration.
258  CGM.getCXXABI().buildThisParam(*this, FunctionArgs);
259 
260  // Add the rest of the parameters, if we have a prototype to work with.
261  if (!IsUnprototyped) {
262  FunctionArgs.append(MD->param_begin(), MD->param_end());
263 
264  if (isa<CXXDestructorDecl>(MD))
265  CGM.getCXXABI().addImplicitStructorParams(*this, ResultType,
266  FunctionArgs);
267  }
268 
269  // Start defining the function.
270  auto NL = ApplyDebugLocation::CreateEmpty(*this);
271  StartFunction(GlobalDecl(), ResultType, Fn, FnInfo, FunctionArgs,
272  MD->getLocation());
273  // Create a scope with an artificial location for the body of this function.
274  auto AL = ApplyDebugLocation::CreateArtificial(*this);
275 
276  // Since we didn't pass a GlobalDecl to StartFunction, do this ourselves.
278  CXXThisValue = CXXABIThisValue;
279  CurCodeDecl = MD;
280  CurFuncDecl = MD;
281 }
282 
284  // Clear these to restore the invariants expected by
285  // StartFunction/FinishFunction.
286  CurCodeDecl = nullptr;
287  CurFuncDecl = nullptr;
288 
289  FinishFunction();
290 }
291 
292 void CodeGenFunction::EmitCallAndReturnForThunk(llvm::FunctionCallee Callee,
293  const ThunkInfo *Thunk,
294  bool IsUnprototyped) {
295  assert(isa<CXXMethodDecl>(CurGD.getDecl()) &&
296  "Please use a new CGF for this thunk");
297  const CXXMethodDecl *MD = cast<CXXMethodDecl>(CurGD.getDecl());
298 
299  // Adjust the 'this' pointer if necessary
300  llvm::Value *AdjustedThisPtr =
302  *this, LoadCXXThisAddress(), Thunk->This)
303  : LoadCXXThis();
304 
305  // If perfect forwarding is required a variadic method, a method using
306  // inalloca, or an unprototyped thunk, use musttail. Emit an error if this
307  // thunk requires a return adjustment, since that is impossible with musttail.
308  if (CurFnInfo->usesInAlloca() || CurFnInfo->isVariadic() || IsUnprototyped) {
309  if (Thunk && !Thunk->Return.isEmpty()) {
310  if (IsUnprototyped)
312  MD, "return-adjusting thunk with incomplete parameter type");
313  else if (CurFnInfo->isVariadic())
314  llvm_unreachable("shouldn't try to emit musttail return-adjusting "
315  "thunks for variadic functions");
316  else
318  MD, "non-trivial argument copy for return-adjusting thunk");
319  }
320  EmitMustTailThunk(CurGD, AdjustedThisPtr, Callee);
321  return;
322  }
323 
324  // Start building CallArgs.
325  CallArgList CallArgs;
326  QualType ThisType = MD->getThisType();
327  CallArgs.add(RValue::get(AdjustedThisPtr), ThisType);
328 
329  if (isa<CXXDestructorDecl>(MD))
331 
332 #ifndef NDEBUG
333  unsigned PrefixArgs = CallArgs.size() - 1;
334 #endif
335  // Add the rest of the arguments.
336  for (const ParmVarDecl *PD : MD->parameters())
337  EmitDelegateCallArg(CallArgs, PD, SourceLocation());
338 
339  const FunctionProtoType *FPT = MD->getType()->castAs<FunctionProtoType>();
340 
341 #ifndef NDEBUG
342  const CGFunctionInfo &CallFnInfo = CGM.getTypes().arrangeCXXMethodCall(
343  CallArgs, FPT, RequiredArgs::forPrototypePlus(FPT, 1), PrefixArgs);
344  assert(CallFnInfo.getRegParm() == CurFnInfo->getRegParm() &&
345  CallFnInfo.isNoReturn() == CurFnInfo->isNoReturn() &&
346  CallFnInfo.getCallingConvention() == CurFnInfo->getCallingConvention());
347  assert(isa<CXXDestructorDecl>(MD) || // ignore dtor return types
348  similar(CallFnInfo.getReturnInfo(), CallFnInfo.getReturnType(),
350  assert(CallFnInfo.arg_size() == CurFnInfo->arg_size());
351  for (unsigned i = 0, e = CurFnInfo->arg_size(); i != e; ++i)
352  assert(similar(CallFnInfo.arg_begin()[i].info,
353  CallFnInfo.arg_begin()[i].type,
354  CurFnInfo->arg_begin()[i].info,
355  CurFnInfo->arg_begin()[i].type));
356 #endif
357 
358  // Determine whether we have a return value slot to use.
359  QualType ResultType = CGM.getCXXABI().HasThisReturn(CurGD)
360  ? ThisType
363  : FPT->getReturnType();
364  ReturnValueSlot Slot;
365  if (!ResultType->isVoidType() &&
367  hasAggregateEvaluationKind(ResultType)))
368  Slot = ReturnValueSlot(ReturnValue, ResultType.isVolatileQualified(),
369  /*IsUnused=*/false, /*IsExternallyDestructed=*/true);
370 
371  // Now emit our call.
372  llvm::CallBase *CallOrInvoke;
373  RValue RV = EmitCall(*CurFnInfo, CGCallee::forDirect(Callee, CurGD), Slot,
374  CallArgs, &CallOrInvoke);
375 
376  // Consider return adjustment if we have ThunkInfo.
377  if (Thunk && !Thunk->Return.isEmpty())
378  RV = PerformReturnAdjustment(*this, ResultType, RV, *Thunk);
379  else if (llvm::CallInst* Call = dyn_cast<llvm::CallInst>(CallOrInvoke))
380  Call->setTailCallKind(llvm::CallInst::TCK_Tail);
381 
382  // Emit return.
383  if (!ResultType->isVoidType() && Slot.isNull())
384  CGM.getCXXABI().EmitReturnFromThunk(*this, RV, ResultType);
385 
386  // Disable the final ARC autorelease.
387  AutoreleaseResult = false;
388 
389  FinishThunk();
390 }
391 
393  llvm::Value *AdjustedThisPtr,
394  llvm::FunctionCallee Callee) {
395  // Emitting a musttail call thunk doesn't use any of the CGCall.cpp machinery
396  // to translate AST arguments into LLVM IR arguments. For thunks, we know
397  // that the caller prototype more or less matches the callee prototype with
398  // the exception of 'this'.
400  for (llvm::Argument &A : CurFn->args())
401  Args.push_back(&A);
402 
403  // Set the adjusted 'this' pointer.
404  const ABIArgInfo &ThisAI = CurFnInfo->arg_begin()->info;
405  if (ThisAI.isDirect()) {
406  const ABIArgInfo &RetAI = CurFnInfo->getReturnInfo();
407  int ThisArgNo = RetAI.isIndirect() && !RetAI.isSRetAfterThis() ? 1 : 0;
408  llvm::Type *ThisType = Args[ThisArgNo]->getType();
409  if (ThisType != AdjustedThisPtr->getType())
410  AdjustedThisPtr = Builder.CreateBitCast(AdjustedThisPtr, ThisType);
411  Args[ThisArgNo] = AdjustedThisPtr;
412  } else {
413  assert(ThisAI.isInAlloca() && "this is passed directly or inalloca");
414  Address ThisAddr = GetAddrOfLocalVar(CXXABIThisDecl);
415  llvm::Type *ThisType = ThisAddr.getElementType();
416  if (ThisType != AdjustedThisPtr->getType())
417  AdjustedThisPtr = Builder.CreateBitCast(AdjustedThisPtr, ThisType);
418  Builder.CreateStore(AdjustedThisPtr, ThisAddr);
419  }
420 
421  // Emit the musttail call manually. Even if the prologue pushed cleanups, we
422  // don't actually want to run them.
423  llvm::CallInst *Call = Builder.CreateCall(Callee, Args);
424  Call->setTailCallKind(llvm::CallInst::TCK_MustTail);
425 
426  // Apply the standard set of call attributes.
427  unsigned CallingConv;
428  llvm::AttributeList Attrs;
429  CGM.ConstructAttributeList(Callee.getCallee()->getName(), *CurFnInfo, GD,
430  Attrs, CallingConv, /*AttrOnCallSite=*/true,
431  /*IsThunk=*/false, CurFuncDecl);
432  Call->setAttributes(Attrs);
433  Call->setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv));
434 
435  if (Call->getType()->isVoidTy())
436  Builder.CreateRetVoid();
437  else
438  Builder.CreateRet(Call);
439 
440  // Finish the function to maintain CodeGenFunction invariants.
441  // FIXME: Don't emit unreachable code.
443 
444  FinishThunk();
445 }
446 
447 void CodeGenFunction::generateThunk(llvm::Function *Fn,
448  const CGFunctionInfo &FnInfo, GlobalDecl GD,
449  const ThunkInfo &Thunk,
450  bool IsUnprototyped) {
451  StartThunk(Fn, GD, FnInfo, IsUnprototyped);
452  // Create a scope with an artificial location for the body of this function.
453  auto AL = ApplyDebugLocation::CreateArtificial(*this);
454 
455  // Get our callee. Use a placeholder type if this method is unprototyped so
456  // that CodeGenModule doesn't try to set attributes.
457  llvm::Type *Ty;
458  if (IsUnprototyped)
459  Ty = llvm::StructType::get(getLLVMContext());
460  else
461  Ty = CGM.getTypes().GetFunctionType(FnInfo);
462 
463  llvm::Constant *Callee = CGM.GetAddrOfFunction(GD, Ty, /*ForVTable=*/true);
464 
465  // Fix up the function type for an unprototyped musttail call.
466  if (IsUnprototyped)
467  Callee = llvm::ConstantExpr::getBitCast(Callee, Fn->getType());
468 
469  // Make the call and return the result.
470  EmitCallAndReturnForThunk(llvm::FunctionCallee(Fn->getFunctionType(), Callee),
471  &Thunk, IsUnprototyped);
472 }
473 
475  bool IsUnprototyped, bool ForVTable) {
476  // Always emit thunks in the MS C++ ABI. We cannot rely on other TUs to
477  // provide thunks for us.
478  if (CGM.getTarget().getCXXABI().isMicrosoft())
479  return true;
480 
481  // In the Itanium C++ ABI, vtable thunks are provided by TUs that provide
482  // definitions of the main method. Therefore, emitting thunks with the vtable
483  // is purely an optimization. Emit the thunk if optimizations are enabled and
484  // all of the parameter types are complete.
485  if (ForVTable)
486  return CGM.getCodeGenOpts().OptimizationLevel && !IsUnprototyped;
487 
488  // Always emit thunks along with the method definition.
489  return true;
490 }
491 
492 llvm::Constant *CodeGenVTables::maybeEmitThunk(GlobalDecl GD,
493  const ThunkInfo &TI,
494  bool ForVTable) {
495  const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
496 
497  // First, get a declaration. Compute the mangled name. Don't worry about
498  // getting the function prototype right, since we may only need this
499  // declaration to fill in a vtable slot.
500  SmallString<256> Name;
501  MangleContext &MCtx = CGM.getCXXABI().getMangleContext();
502  llvm::raw_svector_ostream Out(Name);
503  if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD))
504  MCtx.mangleCXXDtorThunk(DD, GD.getDtorType(), TI.This, Out);
505  else
506  MCtx.mangleThunk(MD, TI, Out);
507  llvm::Type *ThunkVTableTy = CGM.getTypes().GetFunctionTypeForVTable(GD);
508  llvm::Constant *Thunk = CGM.GetAddrOfThunk(Name, ThunkVTableTy, GD);
509 
510  // If we don't need to emit a definition, return this declaration as is.
511  bool IsUnprototyped = !CGM.getTypes().isFuncTypeConvertible(
512  MD->getType()->castAs<FunctionType>());
513  if (!shouldEmitVTableThunk(CGM, MD, IsUnprototyped, ForVTable))
514  return Thunk;
515 
516  // Arrange a function prototype appropriate for a function definition. In some
517  // cases in the MS ABI, we may need to build an unprototyped musttail thunk.
518  const CGFunctionInfo &FnInfo =
519  IsUnprototyped ? CGM.getTypes().arrangeUnprototypedMustTailThunk(MD)
521  llvm::FunctionType *ThunkFnTy = CGM.getTypes().GetFunctionType(FnInfo);
522 
523  // If the type of the underlying GlobalValue is wrong, we'll have to replace
524  // it. It should be a declaration.
525  llvm::Function *ThunkFn = cast<llvm::Function>(Thunk->stripPointerCasts());
526  if (ThunkFn->getFunctionType() != ThunkFnTy) {
527  llvm::GlobalValue *OldThunkFn = ThunkFn;
528 
529  assert(OldThunkFn->isDeclaration() && "Shouldn't replace non-declaration");
530 
531  // Remove the name from the old thunk function and get a new thunk.
532  OldThunkFn->setName(StringRef());
533  ThunkFn = llvm::Function::Create(ThunkFnTy, llvm::Function::ExternalLinkage,
534  Name.str(), &CGM.getModule());
535  CGM.SetLLVMFunctionAttributes(MD, FnInfo, ThunkFn, /*IsThunk=*/false);
536 
537  // If needed, replace the old thunk with a bitcast.
538  if (!OldThunkFn->use_empty()) {
539  llvm::Constant *NewPtrForOldDecl =
540  llvm::ConstantExpr::getBitCast(ThunkFn, OldThunkFn->getType());
541  OldThunkFn->replaceAllUsesWith(NewPtrForOldDecl);
542  }
543 
544  // Remove the old thunk.
545  OldThunkFn->eraseFromParent();
546  }
547 
548  bool ABIHasKeyFunctions = CGM.getTarget().getCXXABI().hasKeyFunctions();
549  bool UseAvailableExternallyLinkage = ForVTable && ABIHasKeyFunctions;
550 
551  if (!ThunkFn->isDeclaration()) {
552  if (!ABIHasKeyFunctions || UseAvailableExternallyLinkage) {
553  // There is already a thunk emitted for this function, do nothing.
554  return ThunkFn;
555  }
556 
557  setThunkProperties(CGM, TI, ThunkFn, ForVTable, GD);
558  return ThunkFn;
559  }
560 
561  // If this will be unprototyped, add the "thunk" attribute so that LLVM knows
562  // that the return type is meaningless. These thunks can be used to call
563  // functions with differing return types, and the caller is required to cast
564  // the prototype appropriately to extract the correct value.
565  if (IsUnprototyped)
566  ThunkFn->addFnAttr("thunk");
567 
569 
570  // Thunks for variadic methods are special because in general variadic
571  // arguments cannot be perfectly forwarded. In the general case, clang
572  // implements such thunks by cloning the original function body. However, for
573  // thunks with no return adjustment on targets that support musttail, we can
574  // use musttail to perfectly forward the variadic arguments.
575  bool ShouldCloneVarArgs = false;
576  if (!IsUnprototyped && ThunkFn->isVarArg()) {
577  ShouldCloneVarArgs = true;
578  if (TI.Return.isEmpty()) {
579  switch (CGM.getTriple().getArch()) {
580  case llvm::Triple::x86_64:
581  case llvm::Triple::x86:
582  case llvm::Triple::aarch64:
583  ShouldCloneVarArgs = false;
584  break;
585  default:
586  break;
587  }
588  }
589  }
590 
591  if (ShouldCloneVarArgs) {
592  if (UseAvailableExternallyLinkage)
593  return ThunkFn;
594  ThunkFn =
595  CodeGenFunction(CGM).GenerateVarArgsThunk(ThunkFn, FnInfo, GD, TI);
596  } else {
597  // Normal thunk body generation.
598  CodeGenFunction(CGM).generateThunk(ThunkFn, FnInfo, GD, TI, IsUnprototyped);
599  }
600 
601  setThunkProperties(CGM, TI, ThunkFn, ForVTable, GD);
602  return ThunkFn;
603 }
604 
606  const CXXMethodDecl *MD =
607  cast<CXXMethodDecl>(GD.getDecl())->getCanonicalDecl();
608 
609  // We don't need to generate thunks for the base destructor.
610  if (isa<CXXDestructorDecl>(MD) && GD.getDtorType() == Dtor_Base)
611  return;
612 
613  const VTableContextBase::ThunkInfoVectorTy *ThunkInfoVector =
614  VTContext->getThunkInfo(GD);
615 
616  if (!ThunkInfoVector)
617  return;
618 
619  for (const ThunkInfo& Thunk : *ThunkInfoVector)
620  maybeEmitThunk(GD, Thunk, /*ForVTable=*/false);
621 }
622 
623 void CodeGenVTables::addRelativeComponent(ConstantArrayBuilder &builder,
624  llvm::Constant *component,
625  unsigned vtableAddressPoint,
626  bool vtableHasLocalLinkage,
627  bool isCompleteDtor) const {
628  // No need to get the offset of a nullptr.
629  if (component->isNullValue())
630  return builder.add(llvm::ConstantInt::get(CGM.Int32Ty, 0));
631 
632  auto *globalVal =
633  cast<llvm::GlobalValue>(component->stripPointerCastsAndAliases());
634  llvm::Module &module = CGM.getModule();
635 
636  // We don't want to copy the linkage of the vtable exactly because we still
637  // want the stub/proxy to be emitted for properly calculating the offset.
638  // Examples where there would be no symbol emitted are available_externally
639  // and private linkages.
640  auto stubLinkage = vtableHasLocalLinkage ? llvm::GlobalValue::InternalLinkage
642 
643  llvm::Constant *target;
644  if (auto *func = dyn_cast<llvm::Function>(globalVal)) {
645  target = llvm::DSOLocalEquivalent::get(func);
646  } else {
647  llvm::SmallString<16> rttiProxyName(globalVal->getName());
648  rttiProxyName.append(".rtti_proxy");
649 
650  // The RTTI component may not always be emitted in the same linkage unit as
651  // the vtable. As a general case, we can make a dso_local proxy to the RTTI
652  // that points to the actual RTTI struct somewhere. This will result in a
653  // GOTPCREL relocation when taking the relative offset to the proxy.
654  llvm::GlobalVariable *proxy = module.getNamedGlobal(rttiProxyName);
655  if (!proxy) {
656  proxy = new llvm::GlobalVariable(module, globalVal->getType(),
657  /*isConstant=*/true, stubLinkage,
658  globalVal, rttiProxyName);
659  proxy->setDSOLocal(true);
660  proxy->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
661  if (!proxy->hasLocalLinkage()) {
662  proxy->setVisibility(llvm::GlobalValue::HiddenVisibility);
663  proxy->setComdat(module.getOrInsertComdat(rttiProxyName));
664  }
665  }
666  target = proxy;
667  }
668 
669  builder.addRelativeOffsetToPosition(CGM.Int32Ty, target,
670  /*position=*/vtableAddressPoint);
671 }
672 
673 bool CodeGenVTables::useRelativeLayout() const {
674  return CGM.getTarget().getCXXABI().isItaniumFamily() &&
676 }
677 
678 llvm::Type *CodeGenVTables::getVTableComponentType() const {
679  if (useRelativeLayout())
680  return CGM.Int32Ty;
681  return CGM.Int8PtrTy;
682 }
683 
684 static void AddPointerLayoutOffset(const CodeGenModule &CGM,
685  ConstantArrayBuilder &builder,
686  CharUnits offset) {
687  builder.add(llvm::ConstantExpr::getIntToPtr(
688  llvm::ConstantInt::get(CGM.PtrDiffTy, offset.getQuantity()),
689  CGM.Int8PtrTy));
690 }
691 
692 static void AddRelativeLayoutOffset(const CodeGenModule &CGM,
693  ConstantArrayBuilder &builder,
694  CharUnits offset) {
695  builder.add(llvm::ConstantInt::get(CGM.Int32Ty, offset.getQuantity()));
696 }
697 
698 void CodeGenVTables::addVTableComponent(ConstantArrayBuilder &builder,
699  const VTableLayout &layout,
700  unsigned componentIndex,
701  llvm::Constant *rtti,
702  unsigned &nextVTableThunkIndex,
703  unsigned vtableAddressPoint,
704  bool vtableHasLocalLinkage) {
705  auto &component = layout.vtable_components()[componentIndex];
706 
707  auto addOffsetConstant =
708  useRelativeLayout() ? AddRelativeLayoutOffset : AddPointerLayoutOffset;
709 
710  switch (component.getKind()) {
712  return addOffsetConstant(CGM, builder, component.getVCallOffset());
713 
715  return addOffsetConstant(CGM, builder, component.getVBaseOffset());
716 
718  return addOffsetConstant(CGM, builder, component.getOffsetToTop());
719 
721  if (useRelativeLayout())
722  return addRelativeComponent(builder, rtti, vtableAddressPoint,
723  vtableHasLocalLinkage,
724  /*isCompleteDtor=*/false);
725  else
726  return builder.add(llvm::ConstantExpr::getBitCast(rtti, CGM.Int8PtrTy));
727 
731  GlobalDecl GD = component.getGlobalDecl();
732 
733  if (CGM.getLangOpts().CUDA) {
734  // Emit NULL for methods we can't codegen on this
735  // side. Otherwise we'd end up with vtable with unresolved
736  // references.
737  const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
738  // OK on device side: functions w/ __device__ attribute
739  // OK on host side: anything except __device__-only functions.
740  bool CanEmitMethod =
741  CGM.getLangOpts().CUDAIsDevice
742  ? MD->hasAttr<CUDADeviceAttr>()
743  : (MD->hasAttr<CUDAHostAttr>() || !MD->hasAttr<CUDADeviceAttr>());
744  if (!CanEmitMethod)
745  return builder.add(llvm::ConstantExpr::getNullValue(CGM.Int8PtrTy));
746  // Method is acceptable, continue processing as usual.
747  }
748 
749  auto getSpecialVirtualFn = [&](StringRef name) -> llvm::Constant * {
750  // FIXME(PR43094): When merging comdat groups, lld can select a local
751  // symbol as the signature symbol even though it cannot be accessed
752  // outside that symbol's TU. The relative vtables ABI would make
753  // __cxa_pure_virtual and __cxa_deleted_virtual local symbols, and
754  // depending on link order, the comdat groups could resolve to the one
755  // with the local symbol. As a temporary solution, fill these components
756  // with zero. We shouldn't be calling these in the first place anyway.
757  if (useRelativeLayout())
758  return llvm::ConstantPointerNull::get(CGM.Int8PtrTy);
759 
760  // For NVPTX devices in OpenMP emit special functon as null pointers,
761  // otherwise linking ends up with unresolved references.
762  if (CGM.getLangOpts().OpenMP && CGM.getLangOpts().OpenMPIsDevice &&
763  CGM.getTriple().isNVPTX())
764  return llvm::ConstantPointerNull::get(CGM.Int8PtrTy);
765  llvm::FunctionType *fnTy =
766  llvm::FunctionType::get(CGM.VoidTy, /*isVarArg=*/false);
767  llvm::Constant *fn = cast<llvm::Constant>(
768  CGM.CreateRuntimeFunction(fnTy, name).getCallee());
769  if (auto f = dyn_cast<llvm::Function>(fn))
770  f->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
771  return llvm::ConstantExpr::getBitCast(fn, CGM.Int8PtrTy);
772  };
773 
774  llvm::Constant *fnPtr;
775 
776  // Pure virtual member functions.
777  if (cast<CXXMethodDecl>(GD.getDecl())->isPure()) {
778  if (!PureVirtualFn)
779  PureVirtualFn =
780  getSpecialVirtualFn(CGM.getCXXABI().GetPureVirtualCallName());
781  fnPtr = PureVirtualFn;
782 
783  // Deleted virtual member functions.
784  } else if (cast<CXXMethodDecl>(GD.getDecl())->isDeleted()) {
785  if (!DeletedVirtualFn)
786  DeletedVirtualFn =
787  getSpecialVirtualFn(CGM.getCXXABI().GetDeletedVirtualCallName());
788  fnPtr = DeletedVirtualFn;
789 
790  // Thunks.
791  } else if (nextVTableThunkIndex < layout.vtable_thunks().size() &&
792  layout.vtable_thunks()[nextVTableThunkIndex].first ==
793  componentIndex) {
794  auto &thunkInfo = layout.vtable_thunks()[nextVTableThunkIndex].second;
795 
796  nextVTableThunkIndex++;
797  fnPtr = maybeEmitThunk(GD, thunkInfo, /*ForVTable=*/true);
798 
799  // Otherwise we can use the method definition directly.
800  } else {
801  llvm::Type *fnTy = CGM.getTypes().GetFunctionTypeForVTable(GD);
802  fnPtr = CGM.GetAddrOfFunction(GD, fnTy, /*ForVTable=*/true);
803  }
804 
805  if (useRelativeLayout()) {
806  return addRelativeComponent(
807  builder, fnPtr, vtableAddressPoint, vtableHasLocalLinkage,
808  component.getKind() == VTableComponent::CK_CompleteDtorPointer);
809  } else
810  return builder.add(llvm::ConstantExpr::getBitCast(fnPtr, CGM.Int8PtrTy));
811  }
812 
814  if (useRelativeLayout())
815  return builder.add(llvm::ConstantExpr::getNullValue(CGM.Int32Ty));
816  else
817  return builder.addNullPointer(CGM.Int8PtrTy);
818  }
819 
820  llvm_unreachable("Unexpected vtable component kind");
821 }
822 
823 llvm::Type *CodeGenVTables::getVTableType(const VTableLayout &layout) {
825  llvm::Type *componentType = getVTableComponentType();
826  for (unsigned i = 0, e = layout.getNumVTables(); i != e; ++i)
827  tys.push_back(llvm::ArrayType::get(componentType, layout.getVTableSize(i)));
828 
829  return llvm::StructType::get(CGM.getLLVMContext(), tys);
830 }
831 
833  const VTableLayout &layout,
834  llvm::Constant *rtti,
835  bool vtableHasLocalLinkage) {
836  llvm::Type *componentType = getVTableComponentType();
837 
838  const auto &addressPoints = layout.getAddressPointIndices();
839  unsigned nextVTableThunkIndex = 0;
840  for (unsigned vtableIndex = 0, endIndex = layout.getNumVTables();
841  vtableIndex != endIndex; ++vtableIndex) {
842  auto vtableElem = builder.beginArray(componentType);
843 
844  size_t vtableStart = layout.getVTableOffset(vtableIndex);
845  size_t vtableEnd = vtableStart + layout.getVTableSize(vtableIndex);
846  for (size_t componentIndex = vtableStart; componentIndex < vtableEnd;
847  ++componentIndex) {
848  addVTableComponent(vtableElem, layout, componentIndex, rtti,
849  nextVTableThunkIndex, addressPoints[vtableIndex],
850  vtableHasLocalLinkage);
851  }
852  vtableElem.finishAndAddTo(builder);
853  }
854 }
855 
857  const CXXRecordDecl *RD, const BaseSubobject &Base, bool BaseIsVirtual,
858  llvm::GlobalVariable::LinkageTypes Linkage,
859  VTableAddressPointsMapTy &AddressPoints) {
860  if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
861  DI->completeClassData(Base.getBase());
862 
863  std::unique_ptr<VTableLayout> VTLayout(
864  getItaniumVTableContext().createConstructionVTableLayout(
865  Base.getBase(), Base.getBaseOffset(), BaseIsVirtual, RD));
866 
867  // Add the address points.
868  AddressPoints = VTLayout->getAddressPoints();
869 
870  // Get the mangled construction vtable name.
871  SmallString<256> OutName;
872  llvm::raw_svector_ostream Out(OutName);
873  cast<ItaniumMangleContext>(CGM.getCXXABI().getMangleContext())
874  .mangleCXXCtorVTable(RD, Base.getBaseOffset().getQuantity(),
875  Base.getBase(), Out);
876  SmallString<256> Name(OutName);
877 
878  bool UsingRelativeLayout = getItaniumVTableContext().isRelativeLayout();
879  bool VTableAliasExists =
880  UsingRelativeLayout && CGM.getModule().getNamedAlias(Name);
881  if (VTableAliasExists) {
882  // We previously made the vtable hidden and changed its name.
883  Name.append(".local");
884  }
885 
886  llvm::Type *VTType = getVTableType(*VTLayout);
887 
888  // Construction vtable symbols are not part of the Itanium ABI, so we cannot
889  // guarantee that they actually will be available externally. Instead, when
890  // emitting an available_externally VTT, we provide references to an internal
891  // linkage construction vtable. The ABI only requires complete-object vtables
892  // to be the same for all instances of a type, not construction vtables.
893  if (Linkage == llvm::GlobalVariable::AvailableExternallyLinkage)
895 
896  unsigned Align = CGM.getDataLayout().getABITypeAlignment(VTType);
897 
898  // Create the variable that will hold the construction vtable.
899  llvm::GlobalVariable *VTable =
900  CGM.CreateOrReplaceCXXRuntimeVariable(Name, VTType, Linkage, Align);
901 
902  // V-tables are always unnamed_addr.
903  VTable->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
904 
905  llvm::Constant *RTTI = CGM.GetAddrOfRTTIDescriptor(
906  CGM.getContext().getTagDeclType(Base.getBase()));
907 
908  // Create and set the initializer.
909  ConstantInitBuilder builder(CGM);
910  auto components = builder.beginStruct();
911  createVTableInitializer(components, *VTLayout, RTTI,
912  VTable->hasLocalLinkage());
913  components.finishAndSetAsInitializer(VTable);
914 
915  // Set properties only after the initializer has been set to ensure that the
916  // GV is treated as definition and not declaration.
917  assert(!VTable->isDeclaration() && "Shouldn't set properties on declaration");
918  CGM.setGVProperties(VTable, RD);
919 
920  CGM.EmitVTableTypeMetadata(RD, VTable, *VTLayout.get());
921 
922  if (UsingRelativeLayout && !VTable->isDSOLocal())
923  GenerateRelativeVTableAlias(VTable, OutName);
924 
925  return VTable;
926 }
927 
928 // If the VTable is not dso_local, then we will not be able to indicate that
929 // the VTable does not need a relocation and move into rodata. A frequent
930 // time this can occur is for classes that should be made public from a DSO
931 // (like in libc++). For cases like these, we can make the vtable hidden or
932 // private and create a public alias with the same visibility and linkage as
933 // the original vtable type.
934 void CodeGenVTables::GenerateRelativeVTableAlias(llvm::GlobalVariable *VTable,
935  llvm::StringRef AliasNameRef) {
936  assert(getItaniumVTableContext().isRelativeLayout() &&
937  "Can only use this if the relative vtable ABI is used");
938  assert(!VTable->isDSOLocal() && "This should be called only if the vtable is "
939  "not guaranteed to be dso_local");
940 
941  // If the vtable is available_externally, we shouldn't (or need to) generate
942  // an alias for it in the first place since the vtable won't actually by
943  // emitted in this compilation unit.
944  if (VTable->hasAvailableExternallyLinkage())
945  return;
946 
947  // Create a new string in the event the alias is already the name of the
948  // vtable. Using the reference directly could lead to use of an inititialized
949  // value in the module's StringMap.
950  llvm::SmallString<256> AliasName(AliasNameRef);
951  VTable->setName(AliasName + ".local");
952 
953  auto Linkage = VTable->getLinkage();
954  assert(llvm::GlobalAlias::isValidLinkage(Linkage) &&
955  "Invalid vtable alias linkage");
956 
957  llvm::GlobalAlias *VTableAlias = CGM.getModule().getNamedAlias(AliasName);
958  if (!VTableAlias) {
959  VTableAlias = llvm::GlobalAlias::create(VTable->getValueType(),
960  VTable->getAddressSpace(), Linkage,
961  AliasName, &CGM.getModule());
962  } else {
963  assert(VTableAlias->getValueType() == VTable->getValueType());
964  assert(VTableAlias->getLinkage() == Linkage);
965  }
966  VTableAlias->setVisibility(VTable->getVisibility());
967  VTableAlias->setUnnamedAddr(VTable->getUnnamedAddr());
968 
969  // Both of these imply dso_local for the vtable.
970  if (!VTable->hasComdat()) {
971  // If this is in a comdat, then we shouldn't make the linkage private due to
972  // an issue in lld where private symbols can be used as the key symbol when
973  // choosing the prevelant group. This leads to "relocation refers to a
974  // symbol in a discarded section".
975  VTable->setLinkage(llvm::GlobalValue::PrivateLinkage);
976  } else {
977  // We should at least make this hidden since we don't want to expose it.
978  VTable->setVisibility(llvm::GlobalValue::HiddenVisibility);
979  }
980 
981  VTableAlias->setAliasee(VTable);
982 }
983 
985  const CXXRecordDecl *RD) {
986  return CGM.getCodeGenOpts().OptimizationLevel > 0 &&
988 }
989 
990 /// Compute the required linkage of the vtable for the given class.
991 ///
992 /// Note that we only call this at the end of the translation unit.
993 llvm::GlobalVariable::LinkageTypes
995  if (!RD->isExternallyVisible())
997 
998  // We're at the end of the translation unit, so the current key
999  // function is fully correct.
1000  const CXXMethodDecl *keyFunction = Context.getCurrentKeyFunction(RD);
1001  if (keyFunction && !RD->hasAttr<DLLImportAttr>()) {
1002  // If this class has a key function, use that to determine the
1003  // linkage of the vtable.
1004  const FunctionDecl *def = nullptr;
1005  if (keyFunction->hasBody(def))
1006  keyFunction = cast<CXXMethodDecl>(def);
1007 
1008  switch (keyFunction->getTemplateSpecializationKind()) {
1009  case TSK_Undeclared:
1011  assert((def || CodeGenOpts.OptimizationLevel > 0 ||
1012  CodeGenOpts.getDebugInfo() != codegenoptions::NoDebugInfo) &&
1013  "Shouldn't query vtable linkage without key function, "
1014  "optimizations, or debug info");
1015  if (!def && CodeGenOpts.OptimizationLevel > 0)
1016  return llvm::GlobalVariable::AvailableExternallyLinkage;
1017 
1018  if (keyFunction->isInlined())
1019  return !Context.getLangOpts().AppleKext ?
1020  llvm::GlobalVariable::LinkOnceODRLinkage :
1022 
1024 
1026  return !Context.getLangOpts().AppleKext ?
1027  llvm::GlobalVariable::LinkOnceODRLinkage :
1029 
1031  return !Context.getLangOpts().AppleKext ?
1032  llvm::GlobalVariable::WeakODRLinkage :
1034 
1036  llvm_unreachable("Should not have been asked to emit this");
1037  }
1038  }
1039 
1040  // -fapple-kext mode does not support weak linkage, so we must use
1041  // internal linkage.
1042  if (Context.getLangOpts().AppleKext)
1044 
1045  llvm::GlobalVariable::LinkageTypes DiscardableODRLinkage =
1046  llvm::GlobalValue::LinkOnceODRLinkage;
1047  llvm::GlobalVariable::LinkageTypes NonDiscardableODRLinkage =
1048  llvm::GlobalValue::WeakODRLinkage;
1049  if (RD->hasAttr<DLLExportAttr>()) {
1050  // Cannot discard exported vtables.
1051  DiscardableODRLinkage = NonDiscardableODRLinkage;
1052  } else if (RD->hasAttr<DLLImportAttr>()) {
1053  // Imported vtables are available externally.
1054  DiscardableODRLinkage = llvm::GlobalVariable::AvailableExternallyLinkage;
1055  NonDiscardableODRLinkage = llvm::GlobalVariable::AvailableExternallyLinkage;
1056  }
1057 
1058  switch (RD->getTemplateSpecializationKind()) {
1059  case TSK_Undeclared:
1062  return DiscardableODRLinkage;
1063 
1065  // Explicit instantiations in MSVC do not provide vtables, so we must emit
1066  // our own.
1067  if (getTarget().getCXXABI().isMicrosoft())
1068  return DiscardableODRLinkage;
1069  return shouldEmitAvailableExternallyVTable(*this, RD)
1070  ? llvm::GlobalVariable::AvailableExternallyLinkage
1072 
1074  return NonDiscardableODRLinkage;
1075  }
1076 
1077  llvm_unreachable("Invalid TemplateSpecializationKind!");
1078 }
1079 
1080 /// This is a callback from Sema to tell us that a particular vtable is
1081 /// required to be emitted in this translation unit.
1082 ///
1083 /// This is only called for vtables that _must_ be emitted (mainly due to key
1084 /// functions). For weak vtables, CodeGen tracks when they are needed and
1085 /// emits them as-needed.
1087  VTables.GenerateClassData(theClass);
1088 }
1089 
1090 void
1092  if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
1093  DI->completeClassData(RD);
1094 
1095  if (RD->getNumVBases())
1097 
1098  CGM.getCXXABI().emitVTableDefinitions(*this, RD);
1099 }
1100 
1101 /// At this point in the translation unit, does it appear that can we
1102 /// rely on the vtable being defined elsewhere in the program?
1103 ///
1104 /// The response is really only definitive when called at the end of
1105 /// the translation unit.
1106 ///
1107 /// The only semantic restriction here is that the object file should
1108 /// not contain a vtable definition when that vtable is defined
1109 /// strongly elsewhere. Otherwise, we'd just like to avoid emitting
1110 /// vtables when unnecessary.
1112  assert(RD->isDynamicClass() && "Non-dynamic classes have no VTable.");
1113 
1114  // We always synthesize vtables if they are needed in the MS ABI. MSVC doesn't
1115  // emit them even if there is an explicit template instantiation.
1116  if (CGM.getTarget().getCXXABI().isMicrosoft())
1117  return false;
1118 
1119  // If we have an explicit instantiation declaration (and not a
1120  // definition), the vtable is defined elsewhere.
1123  return true;
1124 
1125  // Otherwise, if the class is an instantiated template, the
1126  // vtable must be defined here.
1127  if (TSK == TSK_ImplicitInstantiation ||
1129  return false;
1130 
1131  // Otherwise, if the class doesn't have a key function (possibly
1132  // anymore), the vtable must be defined here.
1133  const CXXMethodDecl *keyFunction = CGM.getContext().getCurrentKeyFunction(RD);
1134  if (!keyFunction)
1135  return false;
1136 
1137  // Otherwise, if we don't have a definition of the key function, the
1138  // vtable must be defined somewhere else.
1139  return !keyFunction->hasBody();
1140 }
1141 
1142 /// Given that we're currently at the end of the translation unit, and
1143 /// we've emitted a reference to the vtable for this class, should
1144 /// we define that vtable?
1146  const CXXRecordDecl *RD) {
1147  // If vtable is internal then it has to be done.
1148  if (!CGM.getVTables().isVTableExternal(RD))
1149  return true;
1150 
1151  // If it's external then maybe we will need it as available_externally.
1152  return shouldEmitAvailableExternallyVTable(CGM, RD);
1153 }
1154 
1155 /// Given that at some point we emitted a reference to one or more
1156 /// vtables, and that we are now at the end of the translation unit,
1157 /// decide whether we should emit them.
1158 void CodeGenModule::EmitDeferredVTables() {
1159 #ifndef NDEBUG
1160  // Remember the size of DeferredVTables, because we're going to assume
1161  // that this entire operation doesn't modify it.
1162  size_t savedSize = DeferredVTables.size();
1163 #endif
1164 
1165  for (const CXXRecordDecl *RD : DeferredVTables)
1167  VTables.GenerateClassData(RD);
1168  else if (shouldOpportunisticallyEmitVTables())
1169  OpportunisticVTables.push_back(RD);
1170 
1171  assert(savedSize == DeferredVTables.size() &&
1172  "deferred extra vtables during vtable emission?");
1173  DeferredVTables.clear();
1174 }
1175 
1177  if (!getCodeGenOpts().LTOVisibilityPublicStd)
1178  return false;
1179 
1180  const DeclContext *DC = RD;
1181  while (1) {
1182  auto *D = cast<Decl>(DC);
1183  DC = DC->getParent();
1184  if (isa<TranslationUnitDecl>(DC->getRedeclContext())) {
1185  if (auto *ND = dyn_cast<NamespaceDecl>(D))
1186  if (const IdentifierInfo *II = ND->getIdentifier())
1187  if (II->isStr("std") || II->isStr("stdext"))
1188  return true;
1189  break;
1190  }
1191  }
1192 
1193  return false;
1194 }
1195 
1198  if (!isExternallyVisible(LV.getLinkage()))
1199  return true;
1200 
1201  if (RD->hasAttr<LTOVisibilityPublicAttr>() || RD->hasAttr<UuidAttr>())
1202  return false;
1203 
1204  if (getTriple().isOSBinFormatCOFF()) {
1205  if (RD->hasAttr<DLLExportAttr>() || RD->hasAttr<DLLImportAttr>())
1206  return false;
1207  } else {
1208  if (LV.getVisibility() != HiddenVisibility)
1209  return false;
1210  }
1211 
1212  return !HasLTOVisibilityPublicStd(RD);
1213 }
1214 
1215 llvm::GlobalObject::VCallVisibility CodeGenModule::GetVCallVisibilityLevel(
1217  // If we have already visited this RD (which means this is a recursive call
1218  // since the initial call should have an empty Visited set), return the max
1219  // visibility. The recursive calls below compute the min between the result
1220  // of the recursive call and the current TypeVis, so returning the max here
1221  // ensures that it will have no effect on the current TypeVis.
1222  if (!Visited.insert(RD).second)
1223  return llvm::GlobalObject::VCallVisibilityTranslationUnit;
1224 
1226  llvm::GlobalObject::VCallVisibility TypeVis;
1227  if (!isExternallyVisible(LV.getLinkage()))
1228  TypeVis = llvm::GlobalObject::VCallVisibilityTranslationUnit;
1229  else if (HasHiddenLTOVisibility(RD))
1230  TypeVis = llvm::GlobalObject::VCallVisibilityLinkageUnit;
1231  else
1232  TypeVis = llvm::GlobalObject::VCallVisibilityPublic;
1233 
1234  for (auto B : RD->bases())
1235  if (B.getType()->getAsCXXRecordDecl()->isDynamicClass())
1236  TypeVis = std::min(
1237  TypeVis,
1238  GetVCallVisibilityLevel(B.getType()->getAsCXXRecordDecl(), Visited));
1239 
1240  for (auto B : RD->vbases())
1241  if (B.getType()->getAsCXXRecordDecl()->isDynamicClass())
1242  TypeVis = std::min(
1243  TypeVis,
1244  GetVCallVisibilityLevel(B.getType()->getAsCXXRecordDecl(), Visited));
1245 
1246  return TypeVis;
1247 }
1248 
1250  llvm::GlobalVariable *VTable,
1251  const VTableLayout &VTLayout) {
1252  if (!getCodeGenOpts().LTOUnit)
1253  return;
1254 
1255  CharUnits PointerWidth =
1256  Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerWidth(0));
1257 
1258  typedef std::pair<const CXXRecordDecl *, unsigned> AddressPoint;
1259  std::vector<AddressPoint> AddressPoints;
1260  for (auto &&AP : VTLayout.getAddressPoints())
1261  AddressPoints.push_back(std::make_pair(
1262  AP.first.getBase(), VTLayout.getVTableOffset(AP.second.VTableIndex) +
1263  AP.second.AddressPointIndex));
1264 
1265  // Sort the address points for determinism.
1266  llvm::sort(AddressPoints, [this](const AddressPoint &AP1,
1267  const AddressPoint &AP2) {
1268  if (&AP1 == &AP2)
1269  return false;
1270 
1271  std::string S1;
1272  llvm::raw_string_ostream O1(S1);
1274  QualType(AP1.first->getTypeForDecl(), 0), O1);
1275  O1.flush();
1276 
1277  std::string S2;
1278  llvm::raw_string_ostream O2(S2);
1280  QualType(AP2.first->getTypeForDecl(), 0), O2);
1281  O2.flush();
1282 
1283  if (S1 < S2)
1284  return true;
1285  if (S1 != S2)
1286  return false;
1287 
1288  return AP1.second < AP2.second;
1289  });
1290 
1291  ArrayRef<VTableComponent> Comps = VTLayout.vtable_components();
1292  for (auto AP : AddressPoints) {
1293  // Create type metadata for the address point.
1294  AddVTableTypeMetadata(VTable, PointerWidth * AP.second, AP.first);
1295 
1296  // The class associated with each address point could also potentially be
1297  // used for indirect calls via a member function pointer, so we need to
1298  // annotate the address of each function pointer with the appropriate member
1299  // function pointer type.
1300  for (unsigned I = 0; I != Comps.size(); ++I) {
1301  if (Comps[I].getKind() != VTableComponent::CK_FunctionPointer)
1302  continue;
1303  llvm::Metadata *MD = CreateMetadataIdentifierForVirtualMemPtrType(
1304  Context.getMemberPointerType(
1305  Comps[I].getFunctionDecl()->getType(),
1306  Context.getRecordType(AP.first).getTypePtr()));
1307  VTable->addTypeMetadata((PointerWidth * I).getQuantity(), MD);
1308  }
1309  }
1310 
1311  if (getCodeGenOpts().VirtualFunctionElimination ||
1312  getCodeGenOpts().WholeProgramVTables) {
1314  llvm::GlobalObject::VCallVisibility TypeVis =
1315  GetVCallVisibilityLevel(RD, Visited);
1316  if (TypeVis != llvm::GlobalObject::VCallVisibilityPublic)
1317  VTable->setVCallVisibilityMetadata(TypeVis);
1318  }
1319 }
clang::CodeGen::ABIArgInfo::isDirect
bool isDirect() const
Definition: CGFunctionInfo.h:296
clang::CXXMethodDecl::getThisType
QualType getThisType() const
Return the type of the this pointer.
Definition: DeclCXX.cpp:2451
clang::InternalLinkage
@ InternalLinkage
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
Definition: Linkage.h:31
clang::GlobalDecl::getDtorType
CXXDtorType getDtorType() const
Definition: GlobalDecl.h:109
clang::Dtor_Base
@ Dtor_Base
Base object dtor.
Definition: ABI.h:36
clang::CodeGen::CGFunctionInfo::arg_size
unsigned arg_size() const
Definition: CGFunctionInfo.h:651
clang::HiddenVisibility
@ HiddenVisibility
Objects with "hidden" visibility are not seen by the dynamic linker.
Definition: Visibility.h:36
clang::CodeGen::CodeGenTypeCache::Int8PtrTy
llvm::PointerType * Int8PtrTy
Definition: CodeGenTypeCache.h:57
clang::VTableComponent::CK_VCallOffset
@ CK_VCallOffset
Definition: VTableBuilder.h:33
clang::CodeGen::CodeGenVTables::GenerateRelativeVTableAlias
void GenerateRelativeVTableAlias(llvm::GlobalVariable *VTable, llvm::StringRef AliasNameRef)
Generate a public facing alias for the vtable and make the vtable either hidden or private.
Definition: CGVTables.cpp:934
clang::CodeGen::CodeGenFunction::EmitMustTailThunk
void EmitMustTailThunk(GlobalDecl GD, llvm::Value *AdjustedThisPtr, llvm::FunctionCallee Callee)
Emit a musttail call for a thunk with a potentially adjusted this pointer.
Definition: CGVTables.cpp:392
clang::CodeGen::CodeGenFunction::LoadCXXThis
llvm::Value * LoadCXXThis()
LoadCXXThis - Load the value of 'this'.
Definition: CodeGenFunction.h:2763
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::CodeGen::CodeGenModule::CreateRuntimeFunction
llvm::FunctionCallee CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList(), bool Local=false, bool AssumeConvergent=false)
Create or return a runtime function declaration with the specified type and name.
Definition: CodeGenModule.cpp:3792
clang::CodeGen::ConstantArrayBuilder
A helper class of ConstantInitBuilder, used for building constant array initializers.
Definition: ConstantInitBuilder.h:544
clang::CodeGen::CodeGenModule::getItaniumVTableContext
ItaniumVTableContext & getItaniumVTableContext()
Definition: CodeGenModule.h:730
clang::CodeGen::CodeGenFunction::AutoreleaseResult
bool AutoreleaseResult
In ARC, whether we should autorelease the return value.
Definition: CodeGenFunction.h:508
clang::CodeGen::ABIArgInfo::getKind
Kind getKind() const
Definition: CGFunctionInfo.h:295
clang::CodeGen::ConstantInitBuilder
The standard implementation of ConstantInitBuilder used in Clang.
Definition: ConstantInitBuilder.h:535
CodeGenFunction.h
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
shouldEmitVTableAtEndOfTranslationUnit
static bool shouldEmitVTableAtEndOfTranslationUnit(CodeGenModule &CGM, const CXXRecordDecl *RD)
Given that we're currently at the end of the translation unit, and we've emitted a reference to the v...
Definition: CGVTables.cpp:1145
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1347
clang::CodeGen::CodeGenFunction::EmitCall
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **callOrInvoke, bool IsMustTail, SourceLocation Loc)
EmitCall - Generate a call of the given function, expecting the given result type,...
Definition: CGCall.cpp:4616
clang::Decl::hasAttr
bool hasAttr() const
Definition: DeclBase.h:547
clang::CodeGen::CodeGenFunction::CurCodeDecl
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
Definition: CodeGenFunction.h:327
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 'th...
Definition: CGCXXABI.h:107
clang::ItaniumVTableContext::isRelativeLayout
bool isRelativeLayout() const
Definition: VTableBuilder.h:437
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:3712
clang::NamedDecl::isExternallyVisible
bool isExternallyVisible() const
Definition: Decl.h:407
clang::CodeGen::CodeGenFunction::GenerateVarArgsThunk
llvm::Function * GenerateVarArgsThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, GlobalDecl GD, const ThunkInfo &Thunk)
Definition: CGVTables.cpp:157
clang::ASTContext::VoidTy
CanQualType VoidTy
Definition: ASTContext.h:1075
llvm::SmallVector< llvm::Value *, 8 >
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::TargetCXXABI::isMicrosoft
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
Definition: TargetCXXABI.h:138
clang::CodeGen::CGCXXABI::getMangleContext
MangleContext & getMangleContext()
Gets the mangle context.
Definition: CGCXXABI.h:97
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:1196
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:208
clang::VTableLayout::getNumVTables
size_t getNumVTables() const
Definition: VTableBuilder.h:293
CXXInheritance.h
clang::MangleContext::mangleThunk
virtual void mangleThunk(const CXXMethodDecl *MD, const ThunkInfo &Thunk, raw_ostream &)=0
clang::TSK_Undeclared
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
Definition: Specifiers.h:176
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:673
Attr.h
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:856
clang::CodeGen::CodeGenModule::getContext
ASTContext & getContext() const
Definition: CodeGenModule.h:702
clang::CodeGen::CGFunctionInfo::arg_begin
const_arg_iterator arg_begin() const
Definition: CGFunctionInfo.h:646
clang::CodeGen::ABIArgInfo::isSRetAfterThis
bool isSRetAfterThis() const
Definition: CGFunctionInfo.h:426
clang::TargetInfo::getCXXABI
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
Definition: TargetInfo.h:1203
clang::TargetCXXABI::isItaniumFamily
bool isItaniumFamily() const
Does this ABI generally fall into the Itanium family of ABIs?
Definition: TargetCXXABI.h:124
clang::ParmVarDecl
Represents a parameter to a function.
Definition: Decl.h:1665
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:447
clang::CodeGen::ABIArgInfo::isInAlloca
bool isInAlloca() const
Definition: CGFunctionInfo.h:297
clang::CXXMethodDecl::getCanonicalDecl
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:2033
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:2394
clang::CodeGen::CGBuilderTy::CreateStore
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
Definition: CGBuilder.h:95
clang::CodeGen::ConstantAggregateBuilderTemplateBase::beginArray
ArrayBuilder beginArray(llvm::Type *eltTy=nullptr)
Definition: ConstantInitBuilder.h:362
clang::codegenoptions::NoDebugInfo
@ NoDebugInfo
Don't generate debug info.
Definition: DebugInfoOptions.h:22
clang::NamedDecl::getLinkageAndVisibility
LinkageInfo getLinkageAndVisibility() const
Determines the linkage and visibility of this entity.
Definition: Decl.cpp:1140
clang::CodeGen::CodeGenVTables::CodeGenVTables
CodeGenVTables(CodeGenModule &CGM)
Definition: CGVTables.cpp:31
clang::CodeGen::CodeGenModule::SetLLVMFunctionAttributes
void SetLLVMFunctionAttributes(GlobalDecl GD, const CGFunctionInfo &Info, llvm::Function *F, bool IsThunk)
Set the LLVM function attributes (sext, zext, etc).
Definition: CodeGenModule.cpp:1517
clang::CodeGen::CodeGenModule::getLangOpts
const LangOptions & getLangOpts() const
Definition: CodeGenModule.h:703
clang::Type::isVoidType
bool isVoidType() const
Definition: Type.h:6955
clang::QualType::isVolatileQualified
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition: Type.h:6494
clang::CodeGen::ConstantStructBuilder
A helper class of ConstantInitBuilder, used for building constant struct initializers.
Definition: ConstantInitBuilder.h:561
clang::VTableComponent::CK_RTTI
@ CK_RTTI
Definition: VTableBuilder.h:36
clang::VTableLayout::vtable_components
ArrayRef< VTableComponent > vtable_components() const
Definition: VTableBuilder.h:272
clang::CodeGen::CGFunctionInfo::isNoReturn
bool isNoReturn() const
Definition: CGFunctionInfo.h:665
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't on...
Definition: RecordLayoutBuilder.cpp:3338
clang::FunctionType
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3546
clang::CodeGen::CGFunctionInfo::isVariadic
bool isVariadic() const
Definition: CGFunctionInfo.h:653
shouldEmitAvailableExternallyVTable
static bool shouldEmitAvailableExternallyVTable(const CodeGenModule &CGM, const CXXRecordDecl *RD)
Definition: CGVTables.cpp:984
clang::CodeGen::CGFunctionInfo::getReturnType
CanQualType getReturnType() const
Definition: CGFunctionInfo.h:706
clang::CodeGen::CallArgList::add
void add(RValue rvalue, QualType type)
Definition: CGCall.h:288
clang::CodeGen::CodeGenFunction::Builder
CGBuilderTy Builder
Definition: CodeGenFunction.h:274
clang::CodeGen::CGBuilderTy::CreateBitCast
Address CreateBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Definition: CGBuilder.h:151
clang::VTableLayout::vtable_thunks
ArrayRef< VTableThunkTy > vtable_thunks() const
Definition: VTableBuilder.h:276
clang::CodeGen::CodeGenFunction::StartThunk
void StartThunk(llvm::Function *Fn, GlobalDecl GD, const CGFunctionInfo &FnInfo, bool IsUnprototyped)
Definition: CGVTables.cpp:236
clang::FunctionDecl::isInlined
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
Definition: Decl.h:2613
clang::CodeGen::CodeGenFunction::GetAddrOfLocalVar
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
Definition: CodeGenFunction.h:2679
clang::VTableComponent::CK_UnusedFunctionPointer
@ CK_UnusedFunctionPointer
An entry that is never used.
Definition: VTableBuilder.h:50
clang::GlobalDecl
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:55
clang::VTableLayout::getVTableOffset
size_t getVTableOffset(size_t i) const
Definition: VTableBuilder.h:299
clang::VTableContextBase::getThunkInfo
virtual const ThunkInfoVectorTy * getThunkInfo(GlobalDecl GD)
Definition: VTableBuilder.h:342
CodeGenOptions.h
clang::CodeGen::ABIArgInfo
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
Definition: CGFunctionInfo.h:32
clang::CodeGen::ReturnValueSlot
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
Definition: CGCall.h:362
clang::CodeGen::CGCXXABI::emitVirtualInheritanceTables
virtual void emitVirtualInheritanceTables(const CXXRecordDecl *RD)=0
Emit any tables needed to implement virtual inheritance.
clang::CodeGen::CGFunctionInfo::getCallingConvention
unsigned getCallingConvention() const
getCallingConvention - Return the user specified calling convention, which has been translated into a...
Definition: CGFunctionInfo.h:685
clang::CodeGen::CGCXXABI::buildThisParam
void buildThisParam(CodeGenFunction &CGF, FunctionArgList &Params)
Build a parameter variable suitable for 'this'.
Definition: CGCXXABI.cpp:122
clang::Type::isReferenceType
bool isReferenceType() const
Definition: Type.h:6684
clang::MangleContext::mangleCXXDtorThunk
virtual void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type, const ThisAdjustment &ThisAdjustment, raw_ostream &)=0
clang::TSK_ExplicitInstantiationDeclaration
@ TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
Definition: Specifiers.h:187
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:1761
min
__DEVICE__ int min(int __a, int __b)
Definition: __clang_cuda_math.h:197
clang::MangleContext
MangleContext - Context for tracking state which persists across multiple calls to the C++ name mangl...
Definition: Mangle.h:44
clang::CodeGen::CodeGenVTables::EmitThunks
void EmitThunks(GlobalDecl GD)
EmitThunks - Emit the associated thunks for the given global decl.
Definition: CGVTables.cpp:605
clang::Linkage
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
Definition: Linkage.h:23
clang::FunctionDecl::param_end
param_iterator param_end()
Definition: Decl.h:2496
clang::CodeGen::CodeGenModule::getClassPointerAlignment
CharUnits getClassPointerAlignment(const CXXRecordDecl *CD)
Returns the assumed alignment of an opaque pointer to the given class.
Definition: CGClass.cpp:38
clang::BaseSubobject
Definition: BaseSubobject.h:30
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:1091
clang::CodeGen::CodeGenModule::ReturnTypeUsesSRet
bool ReturnTypeUsesSRet(const CGFunctionInfo &FI)
Return true iff the given type uses 'sret' when used as a return type.
Definition: CGCall.cpp:1551
clang::CodeGen::CodeGenModule::getCodeGenOpts
const CodeGenOptions & getCodeGenOpts() const
Definition: CodeGenModule.h:708
CGFunctionInfo.h
clang::VTableComponent::CK_FunctionPointer
@ CK_FunctionPointer
Definition: VTableBuilder.h:37
clang::CodeGen::CGCXXABI::performReturnAdjustment
virtual llvm::Value * performReturnAdjustment(CodeGenFunction &CGF, Address Ret, const ReturnAdjustment &RA)=0
clang::VTableComponent::CK_DeletingDtorPointer
@ CK_DeletingDtorPointer
A pointer to the deleting destructor.
Definition: VTableBuilder.h:43
clang::CodeGen::CodeGenFunction::EmitCallAndReturnForThunk
void EmitCallAndReturnForThunk(llvm::FunctionCallee Callee, const ThunkInfo *Thunk, bool IsUnprototyped)
Definition: CGVTables.cpp:292
clang::CodeGen::CodeGenTypeCache::VoidTy
llvm::Type * VoidTy
void
Definition: CodeGenTypeCache.h:34
clang::VTableLayout::getAddressPointIndices
const AddressPointsIndexMapTy & getAddressPointIndices() const
Definition: VTableBuilder.h:289
clang::isExternallyVisible
bool isExternallyVisible(Linkage L)
Definition: Linkage.h:91
clang::CodeGen::CodeGenModule::getModule
llvm::Module & getModule() const
Definition: CodeGenModule.h:709
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:1729
clang::CXXDestructorDecl
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2668
clang::CodeGen::CGDebugInfo
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Definition: CGDebugInfo.h:56
clang::MangleContext::mangleTypeName
virtual void mangleTypeName(QualType T, raw_ostream &)=0
Generates a unique string for an externally visible type for use with TBAA or type uniquing.
clang::VTableComponent::CK_VBaseOffset
@ CK_VBaseOffset
Definition: VTableBuilder.h:34
clang::CodeGen::CGCXXABI::performThisAdjustment
virtual llvm::Value * performThisAdjustment(CodeGenFunction &CGF, Address This, const ThisAdjustment &TA)=0
clang::CodeGen::CodeGenModule::setFunctionLinkage
void setFunctionLinkage(GlobalDecl GD, llvm::Function *F)
Definition: CodeGenModule.h:1252
llvm::SmallString
Definition: LLVM.h:37
clang::ASTContext::getRecordType
QualType getRecordType(const RecordDecl *Decl) const
Definition: ASTContext.cpp:4596
clang::CallingConv
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:263
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:625
clang::LinkageInfo
Definition: Visibility.h:52
clang::TSK_ExplicitInstantiationDefinition
@ TSK_ExplicitInstantiationDefinition
This template specialization was instantiated from a template due to an explicit instantiation defini...
Definition: Specifiers.h:191
clang::VTableComponent::CK_CompleteDtorPointer
@ CK_CompleteDtorPointer
A pointer to the complete destructor.
Definition: VTableBuilder.h:40
clang::CodeGen::CodeGenModule::getTypes
CodeGenTypes & getTypes()
Definition: CodeGenModule.h:726
llvm::DenseSet
Definition: Sema.h:78
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:1760
clang::CXXRecordDecl::bases
base_class_range bases()
Definition: DeclCXX.h:589
clang::CodeGen::CodeGenFunction::getLLVMContext
llvm::LLVMContext & getLLVMContext()
Definition: CodeGenFunction.h:1990
clang::CodeGen::ABIArgInfo::Indirect
@ Indirect
Indirect - Pass the argument indirectly via a hidden pointer with the specified alignment (0 indicate...
Definition: CGFunctionInfo.h:49
clang::CodeGen::CodeGenFunction::FinishFunction
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
Definition: CodeGenFunction.cpp:324
clang::CanQual< Type >
clang::CodeGen::Address
An aligned address.
Definition: Address.h:24
Base
clang::FunctionDecl::getTemplateSpecializationKind
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition: Decl.cpp:3915
CodeGenModule.h
clang::ThunkInfo::This
ThisAdjustment This
The this pointer adjustment.
Definition: Thunk.h:158
getKind
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:998
clang::CodeGen::CodeGenModule::EmitVTableTypeMetadata
void EmitVTableTypeMetadata(const CXXRecordDecl *RD, llvm::GlobalVariable *VTable, const VTableLayout &VTLayout)
Emit type metadata for the given vtable using the given layout.
Definition: CGVTables.cpp:1249
clang::CXXRecordDecl::vbases
base_class_range vbases()
Definition: DeclCXX.h:606
clang::CodeGen::ConstantInitBuilderTemplateBase::beginStruct
StructBuilder beginStruct(llvm::StructType *structTy=nullptr)
Definition: ConstantInitBuilder.h:518
clang::CodeGen::CodeGenVTables::createVTableInitializer
void createVTableInitializer(ConstantStructBuilder &builder, const VTableLayout &layout, llvm::Constant *rtti, bool vtableHasLocalLinkage)
Add vtable components for the given vtable layout to the given global initializer.
Definition: CGVTables.cpp:832
clang::CodeGen::CGCallee::forDirect
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
Definition: CGCall.h:135
clang::LinkageInfo::getVisibility
Visibility getVisibility() const
Definition: Visibility.h:84
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:240
clang::CodeGen::CodeGenModule::getTarget
const TargetInfo & getTarget() const
Definition: CodeGenModule.h:714
clang::CodeGen::CodeGenFunction::CurGD
GlobalDecl CurGD
CurGD - The GlobalDecl for the current function being compiled.
Definition: CodeGenFunction.h:350
clang::VTableLayout::getAddressPoints
const AddressPointsMapTy & getAddressPoints() const
Definition: VTableBuilder.h:285
clang::CodeGen::CodeGenTypeCache::Int32Ty
llvm::IntegerType * Int32Ty
Definition: CodeGenTypeCache.h:37
resolveTopLevelMetadata
static void resolveTopLevelMetadata(llvm::Function *Fn, llvm::ValueToValueMapTy &VMap)
This function clones a function's DISubprogram node and enters it into a value map with the intent th...
Definition: CGVTables.cpp:118
clang::FunctionDecl::hasBody
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition: Decl.cpp:2955
clang::CodeGen::CodeGenModule::getModuleDebugInfo
CGDebugInfo * getModuleDebugInfo()
Definition: CodeGenModule.h:694
clang::CodeGen::CodeGenTypes::GetFunctionType
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
Definition: CGCall.cpp:1595
clang::CodeGen::CodeGenModule::getDataLayout
const llvm::DataLayout & getDataLayout() const
Definition: CodeGenModule.h:711
clang::Type::castAs
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7226
clang::CodeGen::CodeGenFunction::StartFunction
void StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn, const CGFunctionInfo &FnInfo, const FunctionArgList &Args, SourceLocation Loc=SourceLocation(), SourceLocation StartLoc=SourceLocation())
Emit code for the start of a function.
Definition: CodeGenFunction.cpp:700
clang::ThunkInfo::Return
ReturnAdjustment Return
The return adjustment.
Definition: Thunk.h:161
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:679
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:255
clang::VTableLayout::getVTableSize
size_t getVTableSize(size_t i) const
Definition: VTableBuilder.h:307
PerformReturnAdjustment
static RValue PerformReturnAdjustment(CodeGenFunction &CGF, QualType ResultType, RValue RV, const ThunkInfo &Thunk)
Definition: CGVTables.cpp:69
AddRelativeLayoutOffset
static void AddRelativeLayoutOffset(const CodeGenModule &CGM, ConstantArrayBuilder &builder, CharUnits offset)
Definition: CGVTables.cpp:692
clang::DeclContext::getRedeclContext
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1780
clang::TemplateSpecializationKind
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:173
clang::serialized_diags::create
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
Definition: SerializedDiagnosticPrinter.cpp:302
clang::CodeGen::CodeGenFunction::EmitDelegateCallArg
void EmitDelegateCallArg(CallArgList &args, const VarDecl *param, SourceLocation loc)
EmitDelegateCallArg - We are performing a delegate call; that is, the current function is delegating ...
Definition: CGCall.cpp:3702
clang::ASTContext::VoidPtrTy
CanQualType VoidPtrTy
Definition: ASTContext.h:1102
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::ReturnAdjustment::isEmpty
bool isEmpty() const
Definition: Thunk.h:69
clang::CodeGen::CodeGenTypes::arrangeUnprototypedMustTailThunk
const CGFunctionInfo & arrangeUnprototypedMustTailThunk(const CXXMethodDecl *MD)
Arrange a thunk that takes 'this' as the first parameter followed by varargs.
Definition: CGCall.cpp:534
clang::CXXRecordDecl::getNumVBases
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
Definition: DeclCXX.h:604
clang::CodeGen::ABIArgInfo::isIndirect
bool isIndirect() const
Definition: CGFunctionInfo.h:300
clang::CodeGen::Address::getPointer
llvm::Value * getPointer() const
Definition: Address.h:37
clang::CodeGen::CodeGenModule::ErrorUnsupported
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
Definition: CodeGenModule.cpp:964
clang::CodeGen::CodeGenModule::CreateMetadataIdentifierForVirtualMemPtrType
llvm::Metadata * CreateMetadataIdentifierForVirtualMemPtrType(QualType T)
Create a metadata identifier that is intended to be used to check virtual calls via a member function...
Definition: CodeGenModule.cpp:6291
clang::CodeGen::CodeGenFunction
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Definition: CodeGenFunction.h:235
AddPointerLayoutOffset
static void AddPointerLayoutOffset(const CodeGenModule &CGM, ConstantArrayBuilder &builder, CharUnits offset)
Definition: CGVTables.cpp:684
clang::CodeGen::CGCXXABI::setThunkLinkage
virtual void setThunkLinkage(llvm::Function *Thunk, bool ForVTable, GlobalDecl GD, bool ReturnAdjustment)=0
clang::CodeGen::CodeGenTypeCache::PtrDiffTy
llvm::IntegerType * PtrDiffTy
Definition: CodeGenTypeCache.h:51
clang::CodeGen::CodeGenModule::getCXXABI
CGCXXABI & getCXXABI() const
Definition: CodeGenModule.h:719
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:5699
clang::FunctionProtoType
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3885
clang::CodeGen::CodeGenModule::HasLTOVisibilityPublicStd
bool HasLTOVisibilityPublicStd(const CXXRecordDecl *RD)
Returns whether the given record has public std LTO visibility and therefore may not participate in (...
Definition: CGVTables.cpp:1176
clang::DeclContext::getParent
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1860
clang::CodeGen::CodeGenModule
This class organizes the cross-function state that is used while generating LLVM code.
Definition: CodeGenModule.h:284
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:6229
llvm::ArrayRef
Definition: LLVM.h:34
clang::CodeGen::CodeGenModule::getVTables
CodeGenVTables & getVTables()
Definition: CodeGenModule.h:728
clang::VTableComponent::CK_OffsetToTop
@ CK_OffsetToTop
Definition: VTableBuilder.h:35
Value
Value
Definition: UninitializedValues.cpp:102
clang::CodeGen::CodeGenModule::getTriple
const llvm::Triple & getTriple() const
Definition: CodeGenModule.h:715
clang::ThunkInfo
The this pointer adjustment as well as an optional return adjustment for a thunk.
Definition: Thunk.h:156
clang::CodeGen::CGFunctionInfo::usesInAlloca
bool usesInAlloca() const
Return true if this function uses inalloca arguments.
Definition: CGFunctionInfo.h:722
clang::CodeGen::CGCXXABI::GetDeletedVirtualCallName
virtual StringRef GetDeletedVirtualCallName()=0
Gets the deleted virtual member call name.
clang::CodeGen::FunctionArgList
FunctionArgList - Type for representing both the decl and type of parameters to a function.
Definition: CGCall.h:358
clang::CodeGen::CGFunctionInfo::getReturnInfo
ABIArgInfo & getReturnInfo()
Definition: CGFunctionInfo.h:708
clang::LinkageInfo::getLinkage
Linkage getLinkage() const
Definition: Visibility.h:83
clang::TSK_ExplicitSpecialization
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
Definition: Specifiers.h:183
clang::CodeGen::CGCXXABI::hasMostDerivedReturn
virtual bool hasMostDerivedReturn(GlobalDecl GD) const
Definition: CGCXXABI.h:109
clang::CodeGen::CGCXXABI::EmitReturnFromThunk
virtual void EmitReturnFromThunk(CodeGenFunction &CGF, RValue RV, QualType ResultType)
Definition: CGCXXABI.cpp:157
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:1086
clang::CodeGen::CodeGenFunction::hasAggregateEvaluationKind
static bool hasAggregateEvaluationKind(QualType T)
Definition: CodeGenFunction.h:2389
clang::CodeGen::Address::getElementType
llvm::Type * getElementType() const
Return the type of the values stored in this address.
Definition: Address.h:51
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:84
clang::CodeGen::CodeGenVTables::getVTableType
llvm::Type * getVTableType(const VTableLayout &layout)
Returns the type of a vtable with the given layout.
Definition: CGVTables.cpp:823
clang::ASTContext::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:747
clang::CodeGen::CodeGenFunction::FinishThunk
void FinishThunk()
Definition: CGVTables.cpp:283
clang::CodeGen::CodeGenModule::supportsCOMDAT
bool supportsCOMDAT() const
Definition: TargetInfo.cpp:11079
clang::CodeGen::CGFunctionInfo
CGFunctionInfo - Class to encapsulate the information about a function definition.
Definition: CGFunctionInfo.h:546
clang::CodeGen::CodeGenModule::ConstructAttributeList
void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info, CGCalleeInfo CalleeInfo, llvm::AttributeList &Attrs, unsigned &CallingConv, bool AttrOnCallSite, bool IsThunk, const Decl *Caller=nullptr)
Get the LLVM attributes and calling convention to use for a particular function type.
Definition: CGCall.cpp:2022
clang::CodeGen::CodeGenModule::GetVCallVisibilityLevel
llvm::GlobalObject::VCallVisibility GetVCallVisibilityLevel(const CXXRecordDecl *RD, llvm::DenseSet< const CXXRecordDecl * > &Visited)
Returns the vcall visibility of the given type.
Definition: CGVTables.cpp:1215
CGCXXABI.h
similar
static bool similar(const ABIArgInfo &infoL, CanQualType typeL, const ABIArgInfo &infoR, CanQualType typeR)
Definition: CGVTables.cpp:60
clang::CodeGen::RequiredArgs::forPrototypePlus
static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype, unsigned additional)
Compute the arguments required by the given formal prototype, given that there may be some additional...
Definition: CGFunctionInfo.h:497
clang::CodeGen::CodeGenFunction::CGM
CodeGenModule & CGM
Definition: CodeGenFunction.h:266
clang::VTableLayout
Definition: VTableBuilder.h:233
clang::Builtin::ID
ID
Definition: Builtins.h:48
clang::CodeGen::CodeGenFunction::CurFn
llvm::Function * CurFn
Definition: CodeGenFunction.h:330
clang::CodeGen::CodeGenTypes::arrangeGlobalDeclaration
const CGFunctionInfo & arrangeGlobalDeclaration(GlobalDecl GD)
Definition: CGCall.cpp:517
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:1817
clang
Definition: CalledOnceCheck.h:17
clang::CodeGen::RValue::get
static RValue get(llvm::Value *V)
Definition: CGValue.h:86
clang::ASTContext::toCharUnitsFromBits
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
Definition: ASTContext.cpp:2439
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:994
clang::CodeGen::ApplyDebugLocation::CreateArtificial
static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF)
Apply TemporaryLocation if it is valid.
Definition: CGDebugInfo.h:810
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:417
clang::ExternalLinkage
@ ExternalLinkage
External linkage, which indicates that the entity can be referred to from other translation units.
Definition: Linkage.h:59
clang::CodeGen::CGCXXABI::canSpeculativelyEmitVTable
virtual bool canSpeculativelyEmitVTable(const CXXRecordDecl *RD) const =0
Determine whether it's possible to emit a vtable for RD, even though we do not know that the vtable h...
clang::FunctionType::getReturnType
QualType getReturnType() const
Definition: Type.h:3809
clang::CodeGen::CGCXXABI::EmitInstanceFunctionProlog
virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF)=0
Emit the ABI-specific prolog for the function.
clang::CodeGen::RValue::getScalarVal
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
Definition: CGValue.h:59
clang::CodeGen::ApplyDebugLocation::CreateEmpty
static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF)
Set the IRBuilder to not attach debug locations.
Definition: CGDebugInfo.h:827
clang::CodeGen::CodeGenFunction::CurFuncIsThunk
bool CurFuncIsThunk
In C++, whether we are code generating a thunk.
Definition: CodeGenFunction.h:505
clang::FunctionDecl::param_begin
param_iterator param_begin()
Definition: Decl.h:2495
clang::CodeGen::CGCXXABI::emitVTableDefinitions
virtual void emitVTableDefinitions(CodeGenVTables &CGVT, const CXXRecordDecl *RD)=0
Emits the VTable definitions required for the given record type.
clang::CodeGen::CGFunctionInfo::getRegParm
unsigned getRegParm() const
Definition: CGFunctionInfo.h:697
clang::GlobalDecl::getDecl
const Decl * getDecl() const
Definition: GlobalDecl.h:102
clang::QualType::getTypePtr
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6424
clang::CXXRecordDecl::isDynamicClass
bool isDynamicClass() const
Definition: DeclCXX.h:555
clang::CharUnits
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
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:1111
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::CodeGen::CodeGenFunction::CurFnInfo
const CGFunctionInfo * CurFnInfo
Definition: CodeGenFunction.h:328
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:687
clang::CodeGen::CodeGenFunction::LoadCXXThisAddress
Address LoadCXXThisAddress()
Definition: CGClass.cpp:128
clang::CodeGen::CodeGenVTables::getItaniumVTableContext
ItaniumVTableContext & getItaniumVTableContext()
Definition: CGVTables.h:101
clang::CodeGen::CGCXXABI::adjustCallArgsForDestructorThunk
virtual void adjustCallArgsForDestructorThunk(CodeGenFunction &CGF, GlobalDecl GD, CallArgList &CallArgs)
Definition: CGCXXABI.h:470
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:4078
clang::CodeGen::CodeGenModule::setGVProperties
void setGVProperties(llvm::GlobalValue *GV, GlobalDecl GD) const
Set visibility, dllimport/dllexport and dso_local.
Definition: CodeGenModule.cpp:1130
clang::CodeGen::ReturnValueSlot::isNull
bool isNull() const
Definition: CGCall.h:378
clang::CodeGen::CGCXXABI::exportThunk
virtual bool exportThunk()=0
clang::transformer::name
RangeSelector name(std::string ID)
Given a node with a "name", (like NamedDecl, DeclRefExpr, CxxCtorInitializer, and TypeLoc) selects th...
Definition: RangeSelector.cpp:200
clang::TSK_ImplicitInstantiation
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:179
shouldEmitVTableThunk
static bool shouldEmitVTableThunk(CodeGenModule &CGM, const CXXMethodDecl *MD, bool IsUnprototyped, bool ForVTable)
Definition: CGVTables.cpp:474
clang::CodeGen::CGCXXABI::GetPureVirtualCallName
virtual StringRef GetPureVirtualCallName()=0
Gets the pure virtual member call function.
clang::FunctionDecl::parameters
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2483
clang::CodeGen::CodeGenModule::AddVTableTypeMetadata
void AddVTableTypeMetadata(llvm::GlobalVariable *VTable, CharUnits Offset, const CXXRecordDecl *RD)
Create and attach type metadata for the given vtable.
Definition: CodeGenModule.cpp:6346
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:430
clang::CodeGen::CallArgList
CallArgList - Type for representing both the value and type of arguments in a call.
Definition: CGCall.h:264
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1856
clang::CodeGen::CodeGenFunction::EmitBlock
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
Definition: CGStmt.cpp:529
clang::FunctionDecl::isDefined
bool isDefined(const FunctionDecl *&Definition, bool CheckForPendingFriendDefinition=false) const
Returns true if the function has a definition that does not need to be instantiated.
Definition: Decl.cpp:3002
clang::ASTContext::getLangOpts
const LangOptions & getLangOpts() const
Definition: ASTContext.h:765
clang::CodeGen::CodeGenModule::getLLVMContext
llvm::LLVMContext & getLLVMContext()
Definition: CodeGenModule.h:720
clang::CharUnits::getQuantity
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:179
ConstantInitBuilder.h
setThunkProperties
static void setThunkProperties(CodeGenModule &CGM, const ThunkInfo &Thunk, llvm::Function *ThunkFn, bool ForVTable, GlobalDecl GD)
Definition: CGVTables.cpp:40
RecordLayout.h
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:3442
clang::CodeGen::CodeGenFunction::CurFuncDecl
const Decl * CurFuncDecl
CurFuncDecl - Holds the Decl for the current outermost non-closure context.
Definition: CodeGenFunction.h:325
clang::CXXMethodDecl::getParent
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Definition: DeclCXX.h:2063
clang::CXXMethodDecl
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1948
clang::CodeGen::CodeGenFunction::ReturnValue
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
Definition: CodeGenFunction.h:361