clang  3.7.0
CGDeclCXX.cpp
Go to the documentation of this file.
1 //===--- CGDeclCXX.cpp - Emit LLVM Code for C++ declarations --------------===//
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 code generation of C++ declarations
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "CodeGenFunction.h"
15 #include "CGCXXABI.h"
16 #include "CGObjCRuntime.h"
17 #include "CGOpenMPRuntime.h"
19 #include "llvm/ADT/StringExtras.h"
20 #include "llvm/IR/Intrinsics.h"
21 #include "llvm/Support/Path.h"
22 
23 using namespace clang;
24 using namespace CodeGen;
25 
26 static void EmitDeclInit(CodeGenFunction &CGF, const VarDecl &D,
27  llvm::Constant *DeclPtr) {
28  assert(D.hasGlobalStorage() && "VarDecl must have global storage!");
29  assert(!D.getType()->isReferenceType() &&
30  "Should not call EmitDeclInit on a reference!");
31 
32  ASTContext &Context = CGF.getContext();
33 
34  CharUnits alignment = Context.getDeclAlign(&D);
35  QualType type = D.getType();
36  LValue lv = CGF.MakeAddrLValue(DeclPtr, type, alignment);
37 
38  const Expr *Init = D.getInit();
39  switch (CGF.getEvaluationKind(type)) {
40  case TEK_Scalar: {
41  CodeGenModule &CGM = CGF.CGM;
42  if (lv.isObjCStrong())
44  DeclPtr, D.getTLSKind());
45  else if (lv.isObjCWeak())
47  DeclPtr);
48  else
49  CGF.EmitScalarInit(Init, &D, lv, false);
50  return;
51  }
52  case TEK_Complex:
53  CGF.EmitComplexExprIntoLValue(Init, lv, /*isInit*/ true);
54  return;
55  case TEK_Aggregate:
59  return;
60  }
61  llvm_unreachable("bad evaluation kind");
62 }
63 
64 /// Emit code to cause the destruction of the given variable with
65 /// static storage duration.
66 static void EmitDeclDestroy(CodeGenFunction &CGF, const VarDecl &D,
67  llvm::Constant *addr) {
68  CodeGenModule &CGM = CGF.CGM;
69 
70  // FIXME: __attribute__((cleanup)) ?
71 
72  QualType type = D.getType();
74 
75  switch (dtorKind) {
76  case QualType::DK_none:
77  return;
78 
80  break;
81 
84  // We don't care about releasing objects during process teardown.
85  assert(!D.getTLSKind() && "should have rejected this");
86  return;
87  }
88 
89  llvm::Constant *function;
90  llvm::Constant *argument;
91 
92  // Special-case non-array C++ destructors, where there's a function
93  // with the right signature that we can just call.
94  const CXXRecordDecl *record = nullptr;
95  if (dtorKind == QualType::DK_cxx_destructor &&
96  (record = type->getAsCXXRecordDecl())) {
97  assert(!record->hasTrivialDestructor());
98  CXXDestructorDecl *dtor = record->getDestructor();
99 
100  function = CGM.getAddrOfCXXStructor(dtor, StructorType::Complete);
101  argument = llvm::ConstantExpr::getBitCast(
102  addr, CGF.getTypes().ConvertType(type)->getPointerTo());
103 
104  // Otherwise, the standard logic requires a helper function.
105  } else {
106  function = CodeGenFunction(CGM)
107  .generateDestroyHelper(addr, type, CGF.getDestroyer(dtorKind),
108  CGF.needsEHCleanup(dtorKind), &D);
109  argument = llvm::Constant::getNullValue(CGF.Int8PtrTy);
110  }
111 
112  CGM.getCXXABI().registerGlobalDtor(CGF, D, function, argument);
113 }
114 
115 /// Emit code to cause the variable at the given address to be considered as
116 /// constant from this point onwards.
117 static void EmitDeclInvariant(CodeGenFunction &CGF, const VarDecl &D,
118  llvm::Constant *Addr) {
119  // Don't emit the intrinsic if we're not optimizing.
120  if (!CGF.CGM.getCodeGenOpts().OptimizationLevel)
121  return;
122 
123  // Grab the llvm.invariant.start intrinsic.
124  llvm::Intrinsic::ID InvStartID = llvm::Intrinsic::invariant_start;
125  llvm::Constant *InvariantStart = CGF.CGM.getIntrinsic(InvStartID);
126 
127  // Emit a call with the size in bytes of the object.
128  CharUnits WidthChars = CGF.getContext().getTypeSizeInChars(D.getType());
129  uint64_t Width = WidthChars.getQuantity();
130  llvm::Value *Args[2] = { llvm::ConstantInt::getSigned(CGF.Int64Ty, Width),
131  llvm::ConstantExpr::getBitCast(Addr, CGF.Int8PtrTy)};
132  CGF.Builder.CreateCall(InvariantStart, Args);
133 }
134 
136  llvm::Constant *DeclPtr,
137  bool PerformInit) {
138 
139  const Expr *Init = D.getInit();
140  QualType T = D.getType();
141 
142  // The address space of a static local variable (DeclPtr) may be different
143  // from the address space of the "this" argument of the constructor. In that
144  // case, we need an addrspacecast before calling the constructor.
145  //
146  // struct StructWithCtor {
147  // __device__ StructWithCtor() {...}
148  // };
149  // __device__ void foo() {
150  // __shared__ StructWithCtor s;
151  // ...
152  // }
153  //
154  // For example, in the above CUDA code, the static local variable s has a
155  // "shared" address space qualifier, but the constructor of StructWithCtor
156  // expects "this" in the "generic" address space.
157  unsigned ExpectedAddrSpace = getContext().getTargetAddressSpace(T);
158  unsigned ActualAddrSpace = DeclPtr->getType()->getPointerAddressSpace();
159  if (ActualAddrSpace != ExpectedAddrSpace) {
160  llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(T);
161  llvm::PointerType *PTy = llvm::PointerType::get(LTy, ExpectedAddrSpace);
162  DeclPtr = llvm::ConstantExpr::getAddrSpaceCast(DeclPtr, PTy);
163  }
164 
165  if (!T->isReferenceType()) {
166  if (getLangOpts().OpenMP && D.hasAttr<OMPThreadPrivateDeclAttr>())
167  (void)CGM.getOpenMPRuntime().emitThreadPrivateVarDefinition(
168  &D, DeclPtr, D.getAttr<OMPThreadPrivateDeclAttr>()->getLocation(),
169  PerformInit, this);
170  if (PerformInit)
171  EmitDeclInit(*this, D, DeclPtr);
172  if (CGM.isTypeConstant(D.getType(), true))
173  EmitDeclInvariant(*this, D, DeclPtr);
174  else
175  EmitDeclDestroy(*this, D, DeclPtr);
176  return;
177  }
178 
179  assert(PerformInit && "cannot have constant initializer which needs "
180  "destruction for reference");
181  unsigned Alignment = getContext().getDeclAlign(&D).getQuantity();
183  EmitStoreOfScalar(RV.getScalarVal(), DeclPtr, false, Alignment, T);
184 }
185 
186 /// Create a stub function, suitable for being passed to atexit,
187 /// which passes the given address to the given destructor function.
188 llvm::Constant *CodeGenFunction::createAtExitStub(const VarDecl &VD,
189  llvm::Constant *dtor,
190  llvm::Constant *addr) {
191  // Get the destructor function type, void(*)(void).
192  llvm::FunctionType *ty = llvm::FunctionType::get(CGM.VoidTy, false);
193  SmallString<256> FnName;
194  {
195  llvm::raw_svector_ostream Out(FnName);
197  }
198  llvm::Function *fn = CGM.CreateGlobalInitOrDestructFunction(ty, FnName.str(),
199  VD.getLocation());
200 
201  CodeGenFunction CGF(CGM);
202 
203  CGF.StartFunction(&VD, CGM.getContext().VoidTy, fn,
205 
206  llvm::CallInst *call = CGF.Builder.CreateCall(dtor, addr);
207 
208  // Make sure the call and the callee agree on calling convention.
209  if (llvm::Function *dtorFn =
210  dyn_cast<llvm::Function>(dtor->stripPointerCasts()))
211  call->setCallingConv(dtorFn->getCallingConv());
212 
213  CGF.FinishFunction();
214 
215  return fn;
216 }
217 
218 /// Register a global destructor using the C atexit runtime function.
220  llvm::Constant *dtor,
221  llvm::Constant *addr) {
222  // Create a function which calls the destructor.
223  llvm::Constant *dtorStub = createAtExitStub(VD, dtor, addr);
224 
225  // extern "C" int atexit(void (*f)(void));
226  llvm::FunctionType *atexitTy =
227  llvm::FunctionType::get(IntTy, dtorStub->getType(), false);
228 
229  llvm::Constant *atexit =
230  CGM.CreateRuntimeFunction(atexitTy, "atexit");
231  if (llvm::Function *atexitFn = dyn_cast<llvm::Function>(atexit))
232  atexitFn->setDoesNotThrow();
233 
234  EmitNounwindRuntimeCall(atexit, dtorStub);
235 }
236 
238  llvm::GlobalVariable *DeclPtr,
239  bool PerformInit) {
240  // If we've been asked to forbid guard variables, emit an error now.
241  // This diagnostic is hard-coded for Darwin's use case; we can find
242  // better phrasing if someone else needs it.
243  if (CGM.getCodeGenOpts().ForbidGuardVariables)
244  CGM.Error(D.getLocation(),
245  "this initialization requires a guard variable, which "
246  "the kernel does not support");
247 
248  CGM.getCXXABI().EmitGuardedInit(*this, D, DeclPtr, PerformInit);
249 }
250 
252  llvm::FunctionType *FTy, const Twine &Name, SourceLocation Loc, bool TLS) {
253  llvm::Function *Fn =
255  Name, &getModule());
256  if (!getLangOpts().AppleKext && !TLS) {
257  // Set the section if needed.
258  if (const char *Section = getTarget().getStaticInitSectionSpecifier())
259  Fn->setSection(Section);
260  }
261 
262  SetLLVMFunctionAttributes(nullptr, getTypes().arrangeNullaryFunction(), Fn);
263 
264  Fn->setCallingConv(getRuntimeCC());
265 
266  if (!getLangOpts().Exceptions)
267  Fn->setDoesNotThrow();
268 
269  if (!isInSanitizerBlacklist(Fn, Loc)) {
270  if (getLangOpts().Sanitize.hasOneOf(SanitizerKind::Address |
271  SanitizerKind::KernelAddress))
272  Fn->addFnAttr(llvm::Attribute::SanitizeAddress);
273  if (getLangOpts().Sanitize.has(SanitizerKind::Thread))
274  Fn->addFnAttr(llvm::Attribute::SanitizeThread);
275  if (getLangOpts().Sanitize.has(SanitizerKind::Memory))
276  Fn->addFnAttr(llvm::Attribute::SanitizeMemory);
277  if (getLangOpts().Sanitize.has(SanitizerKind::SafeStack))
278  Fn->addFnAttr(llvm::Attribute::SafeStack);
279  }
280 
281  return Fn;
282 }
283 
284 /// Create a global pointer to a function that will initialize a global
285 /// variable. The user has requested that this pointer be emitted in a specific
286 /// section.
287 void CodeGenModule::EmitPointerToInitFunc(const VarDecl *D,
288  llvm::GlobalVariable *GV,
289  llvm::Function *InitFunc,
290  InitSegAttr *ISA) {
291  llvm::GlobalVariable *PtrArray = new llvm::GlobalVariable(
292  TheModule, InitFunc->getType(), /*isConstant=*/true,
293  llvm::GlobalValue::PrivateLinkage, InitFunc, "__cxx_init_fn_ptr");
294  PtrArray->setSection(ISA->getSection());
295  addUsedGlobal(PtrArray);
296 
297  // If the GV is already in a comdat group, then we have to join it.
298  if (llvm::Comdat *C = GV->getComdat())
299  PtrArray->setComdat(C);
300 }
301 
302 void
303 CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
304  llvm::GlobalVariable *Addr,
305  bool PerformInit) {
306  // Check if we've already initialized this decl.
307  auto I = DelayedCXXInitPosition.find(D);
308  if (I != DelayedCXXInitPosition.end() && I->second == ~0U)
309  return;
310 
311  llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false);
312  SmallString<256> FnName;
313  {
314  llvm::raw_svector_ostream Out(FnName);
316  }
317 
318  // Create a variable initialization function.
319  llvm::Function *Fn =
320  CreateGlobalInitOrDestructFunction(FTy, FnName.str(), D->getLocation());
321 
322  auto *ISA = D->getAttr<InitSegAttr>();
324  PerformInit);
325 
326  llvm::GlobalVariable *COMDATKey =
327  supportsCOMDAT() && D->isExternallyVisible() ? Addr : nullptr;
328 
329  if (D->getTLSKind()) {
330  // FIXME: Should we support init_priority for thread_local?
331  // FIXME: Ideally, initialization of instantiated thread_local static data
332  // members of class templates should not trigger initialization of other
333  // entities in the TU.
334  // FIXME: We only need to register one __cxa_thread_atexit function for the
335  // entire TU.
336  CXXThreadLocalInits.push_back(Fn);
337  CXXThreadLocalInitVars.push_back(Addr);
338  } else if (PerformInit && ISA) {
339  EmitPointerToInitFunc(D, Addr, Fn, ISA);
340  } else if (auto *IPA = D->getAttr<InitPriorityAttr>()) {
341  OrderGlobalInits Key(IPA->getPriority(), PrioritizedCXXGlobalInits.size());
342  PrioritizedCXXGlobalInits.push_back(std::make_pair(Key, Fn));
344  // C++ [basic.start.init]p2:
345  // Definitions of explicitly specialized class template static data
346  // members have ordered initialization. Other class template static data
347  // members (i.e., implicitly or explicitly instantiated specializations)
348  // have unordered initialization.
349  //
350  // As a consequence, we can put them into their own llvm.global_ctors entry.
351  //
352  // If the global is externally visible, put the initializer into a COMDAT
353  // group with the global being initialized. On most platforms, this is a
354  // minor startup time optimization. In the MS C++ ABI, there are no guard
355  // variables, so this COMDAT key is required for correctness.
356  AddGlobalCtor(Fn, 65535, COMDATKey);
357  } else if (D->hasAttr<SelectAnyAttr>()) {
358  // SelectAny globals will be comdat-folded. Put the initializer into a
359  // COMDAT group associated with the global, so the initializers get folded
360  // too.
361  AddGlobalCtor(Fn, 65535, COMDATKey);
362  } else {
363  I = DelayedCXXInitPosition.find(D); // Re-do lookup in case of re-hash.
364  if (I == DelayedCXXInitPosition.end()) {
365  CXXGlobalInits.push_back(Fn);
366  } else if (I->second != ~0U) {
367  assert(I->second < CXXGlobalInits.size() &&
368  CXXGlobalInits[I->second] == nullptr);
369  CXXGlobalInits[I->second] = Fn;
370  }
371  }
372 
373  // Remember that we already emitted the initializer for this global.
374  DelayedCXXInitPosition[D] = ~0U;
375 }
376 
377 void CodeGenModule::EmitCXXThreadLocalInitFunc() {
379  *this, CXXThreadLocals, CXXThreadLocalInits, CXXThreadLocalInitVars);
380 
381  CXXThreadLocalInits.clear();
382  CXXThreadLocalInitVars.clear();
383  CXXThreadLocals.clear();
384 }
385 
386 void
387 CodeGenModule::EmitCXXGlobalInitFunc() {
388  while (!CXXGlobalInits.empty() && !CXXGlobalInits.back())
389  CXXGlobalInits.pop_back();
390 
391  if (CXXGlobalInits.empty() && PrioritizedCXXGlobalInits.empty())
392  return;
393 
394  llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false);
395 
396 
397  // Create our global initialization function.
398  if (!PrioritizedCXXGlobalInits.empty()) {
399  SmallVector<llvm::Function *, 8> LocalCXXGlobalInits;
400  llvm::array_pod_sort(PrioritizedCXXGlobalInits.begin(),
401  PrioritizedCXXGlobalInits.end());
402  // Iterate over "chunks" of ctors with same priority and emit each chunk
403  // into separate function. Note - everything is sorted first by priority,
404  // second - by lex order, so we emit ctor functions in proper order.
406  I = PrioritizedCXXGlobalInits.begin(),
407  E = PrioritizedCXXGlobalInits.end(); I != E; ) {
409  PrioE = std::upper_bound(I + 1, E, *I, GlobalInitPriorityCmp());
410 
411  LocalCXXGlobalInits.clear();
412  unsigned Priority = I->first.priority;
413  // Compute the function suffix from priority. Prepend with zeroes to make
414  // sure the function names are also ordered as priorities.
415  std::string PrioritySuffix = llvm::utostr(Priority);
416  // Priority is always <= 65535 (enforced by sema).
417  PrioritySuffix = std::string(6-PrioritySuffix.size(), '0')+PrioritySuffix;
418  llvm::Function *Fn = CreateGlobalInitOrDestructFunction(
419  FTy, "_GLOBAL__I_" + PrioritySuffix);
420 
421  for (; I < PrioE; ++I)
422  LocalCXXGlobalInits.push_back(I->second);
423 
424  CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn, LocalCXXGlobalInits);
425  AddGlobalCtor(Fn, Priority);
426  }
427  PrioritizedCXXGlobalInits.clear();
428  }
429 
430  SmallString<128> FileName;
431  SourceManager &SM = Context.getSourceManager();
432  if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
433  // Include the filename in the symbol name. Including "sub_" matches gcc and
434  // makes sure these symbols appear lexicographically behind the symbols with
435  // priority emitted above.
436  FileName = llvm::sys::path::filename(MainFile->getName());
437  } else {
438  FileName = "<null>";
439  }
440 
441  for (size_t i = 0; i < FileName.size(); ++i) {
442  // Replace everything that's not [a-zA-Z0-9._] with a _. This set happens
443  // to be the set of C preprocessing numbers.
444  if (!isPreprocessingNumberBody(FileName[i]))
445  FileName[i] = '_';
446  }
447 
448  llvm::Function *Fn = CreateGlobalInitOrDestructFunction(
449  FTy, llvm::Twine("_GLOBAL__sub_I_", FileName));
450 
451  CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn, CXXGlobalInits);
452  AddGlobalCtor(Fn);
453 
454  CXXGlobalInits.clear();
455 }
456 
457 void CodeGenModule::EmitCXXGlobalDtorFunc() {
458  if (CXXGlobalDtors.empty())
459  return;
460 
461  llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false);
462 
463  // Create our global destructor function.
464  llvm::Function *Fn = CreateGlobalInitOrDestructFunction(FTy, "_GLOBAL__D_a");
465 
466  CodeGenFunction(*this).GenerateCXXGlobalDtorsFunc(Fn, CXXGlobalDtors);
467  AddGlobalDtor(Fn);
468 }
469 
470 /// Emit the code necessary to initialize the given global variable.
472  const VarDecl *D,
473  llvm::GlobalVariable *Addr,
474  bool PerformInit) {
475  // Check if we need to emit debug info for variable initializer.
476  if (D->hasAttr<NoDebugAttr>())
477  DebugInfo = nullptr; // disable debug info indefinitely for this function
478 
479  CurEHLocation = D->getLocStart();
480 
482  getTypes().arrangeNullaryFunction(),
484  D->getInit()->getExprLoc());
485 
486  // Use guarded initialization if the global variable is weak. This
487  // occurs for, e.g., instantiated static data members and
488  // definitions explicitly marked weak.
489  if (Addr->hasWeakLinkage() || Addr->hasLinkOnceLinkage()) {
490  EmitCXXGuardedInit(*D, Addr, PerformInit);
491  } else {
492  EmitCXXGlobalVarDeclInit(*D, Addr, PerformInit);
493  }
494 
495  FinishFunction();
496 }
497 
498 void
501  llvm::GlobalVariable *Guard) {
502  {
503  auto NL = ApplyDebugLocation::CreateEmpty(*this);
505  getTypes().arrangeNullaryFunction(), FunctionArgList());
506  // Emit an artificial location for this function.
507  auto AL = ApplyDebugLocation::CreateArtificial(*this);
508 
509  llvm::BasicBlock *ExitBlock = nullptr;
510  if (Guard) {
511  // If we have a guard variable, check whether we've already performed
512  // these initializations. This happens for TLS initialization functions.
513  llvm::Value *GuardVal = Builder.CreateLoad(Guard);
514  llvm::Value *Uninit = Builder.CreateIsNull(GuardVal,
515  "guard.uninitialized");
516  // Mark as initialized before initializing anything else. If the
517  // initializers use previously-initialized thread_local vars, that's
518  // probably supposed to be OK, but the standard doesn't say.
519  Builder.CreateStore(llvm::ConstantInt::get(GuardVal->getType(),1), Guard);
520  llvm::BasicBlock *InitBlock = createBasicBlock("init");
521  ExitBlock = createBasicBlock("exit");
522  Builder.CreateCondBr(Uninit, InitBlock, ExitBlock);
523  EmitBlock(InitBlock);
524  }
525 
526  RunCleanupsScope Scope(*this);
527 
528  // When building in Objective-C++ ARC mode, create an autorelease pool
529  // around the global initializers.
530  if (getLangOpts().ObjCAutoRefCount && getLangOpts().CPlusPlus) {
533  }
534 
535  for (unsigned i = 0, e = Decls.size(); i != e; ++i)
536  if (Decls[i])
537  EmitRuntimeCall(Decls[i]);
538 
539  Scope.ForceCleanup();
540 
541  if (ExitBlock) {
542  Builder.CreateBr(ExitBlock);
543  EmitBlock(ExitBlock);
544  }
545  }
546 
547  FinishFunction();
548 }
549 
551  const std::vector<std::pair<llvm::WeakVH, llvm::Constant*> >
552  &DtorsAndObjects) {
553  {
554  auto NL = ApplyDebugLocation::CreateEmpty(*this);
556  getTypes().arrangeNullaryFunction(), FunctionArgList());
557  // Emit an artificial location for this function.
558  auto AL = ApplyDebugLocation::CreateArtificial(*this);
559 
560  // Emit the dtors, in reverse order from construction.
561  for (unsigned i = 0, e = DtorsAndObjects.size(); i != e; ++i) {
562  llvm::Value *Callee = DtorsAndObjects[e - i - 1].first;
563  llvm::CallInst *CI = Builder.CreateCall(Callee,
564  DtorsAndObjects[e - i - 1].second);
565  // Make sure the call and the callee agree on calling convention.
566  if (llvm::Function *F = dyn_cast<llvm::Function>(Callee))
567  CI->setCallingConv(F->getCallingConv());
568  }
569  }
570 
571  FinishFunction();
572 }
573 
574 /// generateDestroyHelper - Generates a helper function which, when
575 /// invoked, destroys the given object.
577  llvm::Constant *addr, QualType type, Destroyer *destroyer,
578  bool useEHCleanupForArray, const VarDecl *VD) {
579  FunctionArgList args;
580  ImplicitParamDecl dst(getContext(), nullptr, SourceLocation(), nullptr,
582  args.push_back(&dst);
583 
585  getContext().VoidTy, args, FunctionType::ExtInfo(), /*variadic=*/false);
586  llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI);
587  llvm::Function *fn = CGM.CreateGlobalInitOrDestructFunction(
588  FTy, "__cxx_global_array_dtor", VD->getLocation());
589 
590  CurEHLocation = VD->getLocStart();
591 
592  StartFunction(VD, getContext().VoidTy, fn, FI, args);
593 
594  emitDestroy(addr, type, destroyer, useEHCleanupForArray);
595 
596  FinishFunction();
597 
598  return fn;
599 }
llvm::IntegerType * IntTy
int
TemplateSpecializationKind getTemplateSpecializationKind() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
Definition: Decl.cpp:2202
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
Definition: CGDecl.cpp:1356
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
Definition: DeclCXX.h:1263
DestructionKind isDestructedType() const
Definition: Type.h:999
llvm::Module & getModule() const
static AggValueSlot forLValue(const LValue &LV, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, IsZeroed_t isZeroed=IsNotZeroed)
Definition: CGValue.h:441
static void EmitDeclDestroy(CodeGenFunction &CGF, const VarDecl &D, llvm::Constant *addr)
Definition: CGDeclCXX.cpp:66
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:163
llvm::CallingConv::ID getRuntimeCC() const
void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit)
const Expr * getInit() const
Definition: Decl.h:1068
const LangOptions & getLangOpts() const
const CGFunctionInfo & arrangeFreeFunctionDeclaration(QualType ResTy, const FunctionArgList &Args, const FunctionType::ExtInfo &Info, bool isVariadic)
Definition: CGCall.cpp:460
virtual void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, llvm::Value *dest)=0
TLSKind getTLSKind() const
Definition: Decl.cpp:1803
llvm::Value * EmitObjCAutoreleasePoolPush()
Definition: CGObjC.cpp:2266
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
Definition: Decl.h:922
llvm::Type * ConvertTypeForMem(QualType T)
static LLVM_READONLY bool isPreprocessingNumberBody(unsigned char c)
Definition: CharInfo.h:148
bool hasAttr() const
Definition: DeclBase.h:487
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:89
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
Definition: CGExpr.cpp:442
bool isReferenceType() const
Definition: Type.h:5241
llvm::CallInst * EmitRuntimeCall(llvm::Value *callee, const Twine &name="")
void GenerateCXXGlobalDtorsFunc(llvm::Function *Fn, const std::vector< std::pair< llvm::WeakVH, llvm::Constant * > > &DtorsAndObjects)
Definition: CGDeclCXX.cpp:550
void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, const VarDecl *D, llvm::GlobalVariable *Addr, bool PerformInit)
Emit the code necessary to initialize the given global variable.
Definition: CGDeclCXX.cpp:471
static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF)
Apply TemporaryLocation if it is valid. Otherwise switch to an artificial debug location that has a v...
Definition: CGDebugInfo.h:525
T * getAttr() const
Definition: DeclBase.h:484
LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment=CharUnits())
virtual void EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, llvm::Value *dest, bool threadlocal=false)=0
bool needsEHCleanup(QualType::DestructionKind kind)
void registerGlobalDtorWithAtExit(const VarDecl &D, llvm::Constant *fn, llvm::Constant *addr)
Register a global destructor using the C atexit runtime function.
Definition: CGDeclCXX.cpp:219
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr * > VL, ArrayRef< Expr * > IL, Expr *Step, Expr *CalcStep)
Creates clause with a list of variables VL and a linear step Step.
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
llvm::Function * generateDestroyHelper(llvm::Constant *addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray, const VarDecl *VD)
Definition: CGDeclCXX.cpp:576
QualType getType() const
Definition: Decl.h:538
bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor)
llvm::GlobalValue * getAddrOfCXXStructor(const CXXMethodDecl *MD, StructorType Type, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false)
Return the address of the constructor/destructor of the given type.
Definition: CGCXX.cpp:229
void GenerateCXXGlobalInitFunc(llvm::Function *Fn, ArrayRef< llvm::Function * > CXXThreadLocals, llvm::GlobalVariable *Guard=nullptr)
Definition: CGDeclCXX.cpp:499
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
llvm::CallInst * EmitNounwindRuntimeCall(llvm::Value *callee, const Twine &name="")
void emitDestroy(llvm::Value *addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
Definition: CGDecl.cpp:1432
const TargetInfo & getTarget() const
virtual void mangleDynamicAtExitDestructor(const VarDecl *D, raw_ostream &)=0
ASTContext * Context
ID
Defines the set of possible language-specific address spaces.
Definition: AddressSpaces.h:27
SourceManager & SM
void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr, bool PerformInit)
Definition: CGDeclCXX.cpp:237
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
static TypeEvaluationKind getEvaluationKind(QualType T)
void SetLLVMFunctionAttributes(const Decl *D, const CGFunctionInfo &Info, llvm::Function *F)
Set the LLVM function attributes (sext, zext, etc).
CGCXXABI & getCXXABI() const
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited...
const CGFunctionInfo & arrangeNullaryFunction()
Definition: CGCall.cpp:475
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2358
virtual void mangleDynamicInitializer(const VarDecl *D, raw_ostream &)=0
virtual void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D, llvm::GlobalVariable *DeclPtr, bool PerformInit)=0
ASTContext & getContext() const
virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D, llvm::Constant *Dtor, llvm::Constant *Addr)=0
bool isExternallyVisible() const
Definition: Decl.h:279
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=None)
void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::Constant *DeclPtr, bool PerformInit)
Definition: CGDeclCXX.cpp:135
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
Definition: Specifiers.h:155
virtual void EmitThreadLocalInitFuncs(CodeGenModule &CGM, ArrayRef< std::pair< const VarDecl *, llvm::GlobalVariable * >> CXXThreadLocals, ArrayRef< llvm::Function * > CXXThreadLocalInits, ArrayRef< llvm::GlobalVariable * > CXXThreadLocalInitVars)=0
llvm::Constant * CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeSet ExtraAttrs=llvm::AttributeSet())
Create a new runtime function with the specified type and name.
ASTContext & getContext() const
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
llvm::Constant * createAtExitStub(const VarDecl &VD, llvm::Constant *Dtor, llvm::Constant *Addr)
Definition: CGDeclCXX.cpp:188
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:53
CanQualType VoidTy
Definition: ASTContext.h:817
const CodeGenOptions & getCodeGenOpts() const
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.
const LangOptions & getLangOpts() const
MangleContext & getMangleContext()
Gets the mangle context.
Definition: CGCXXABI.h:85
FileID getMainFileID() const
Returns the FileID of the main source file.
void Error(SourceLocation loc, StringRef error)
Emit a general error that something can't be done.
void FinishFunction(SourceLocation EndLoc=SourceLocation())
SourceLocation getExprLoc() const LLVM_READONLY
Definition: Expr.cpp:193
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
void addUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.used metadata.
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
Definition: DeclCXX.cpp:1302
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchers.h:1639
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
Definition: CGValue.h:54
bool isObjCWeak() const
Definition: CGValue.h:233
SourceLocation getLocStart() const LLVM_READONLY
Definition: Decl.h:633
static void EmitDeclInit(CodeGenFunction &CGF, const VarDecl &D, llvm::Constant *DeclPtr)
Definition: CGDeclCXX.cpp:26
void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr, bool Volatile, unsigned Alignment, QualType Ty, llvm::MDNode *TBAAInfo=nullptr, bool isInit=false, QualType TBAABaseTy=QualType(), uint64_t TBAAOffset=0)
Definition: CGExpr.cpp:1244
bool isInSanitizerBlacklist(llvm::Function *Fn, SourceLocation Loc) const
void EmitAggExpr(const Expr *E, AggValueSlot AS)
Definition: CGExprAgg.cpp:1403
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
Definition: CGDecl.cpp:604
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1505
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
Definition: Linkage.h:33
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
Definition: CGStmt.cpp:348
SourceManager & getSourceManager()
Definition: ASTContext.h:494
Represents a C++ struct/union/class.
Definition: DeclCXX.h:285
bool isObjCStrong() const
Definition: CGValue.h:236
void ForceCleanup()
Force the emission of cleanups now, instead of waiting until this object is destroyed.
llvm::Function * CreateGlobalInitOrDestructFunction(llvm::FunctionType *ty, const Twine &name, SourceLocation Loc=SourceLocation(), bool TLS=false)
Definition: CGDeclCXX.cpp:251
void EmitObjCAutoreleasePoolCleanup(llvm::Value *Ptr)
Definition: CGObjC.cpp:2373
unsigned getTargetAddressSpace(QualType T) const
Definition: ASTContext.h:2089
static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF)
Definition: CGDebugInfo.h:542
CodeGenTypes & getTypes() const
SourceLocation getLocation() const
Definition: DeclBase.h:372
This class handles loading and caching of source files into memory.
static void EmitDeclInvariant(CodeGenFunction &CGF, const VarDecl &D, llvm::Constant *Addr)
Definition: CGDeclCXX.cpp:117
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
Definition: CGCall.cpp:1253