clang  10.0.0svn
CGDeclCXX.cpp
Go to the documentation of this file.
1 //===--- CGDeclCXX.cpp - Emit LLVM Code for C++ declarations --------------===//
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 code generation of C++ declarations
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "CodeGenFunction.h"
14 #include "CGCXXABI.h"
15 #include "CGObjCRuntime.h"
16 #include "CGOpenMPRuntime.h"
17 #include "TargetInfo.h"
19 #include "llvm/ADT/StringExtras.h"
20 #include "llvm/IR/Intrinsics.h"
21 #include "llvm/IR/MDBuilder.h"
22 #include "llvm/Support/Path.h"
23 
24 using namespace clang;
25 using namespace CodeGen;
26 
27 static void EmitDeclInit(CodeGenFunction &CGF, const VarDecl &D,
28  ConstantAddress DeclPtr) {
29  assert(
30  (D.hasGlobalStorage() ||
31  (D.hasLocalStorage() && CGF.getContext().getLangOpts().OpenCLCPlusPlus)) &&
32  "VarDecl must have global or local (in the case of OpenCL) storage!");
33  assert(!D.getType()->isReferenceType() &&
34  "Should not call EmitDeclInit on a reference!");
35 
36  QualType type = D.getType();
37  LValue lv = CGF.MakeAddrLValue(DeclPtr, type);
38 
39  const Expr *Init = D.getInit();
40  switch (CGF.getEvaluationKind(type)) {
41  case TEK_Scalar: {
42  CodeGenModule &CGM = CGF.CGM;
43  if (lv.isObjCStrong())
45  DeclPtr, D.getTLSKind());
46  else if (lv.isObjCWeak())
48  DeclPtr);
49  else
50  CGF.EmitScalarInit(Init, &D, lv, false);
51  return;
52  }
53  case TEK_Complex:
54  CGF.EmitComplexExprIntoLValue(Init, lv, /*isInit*/ true);
55  return;
56  case TEK_Aggregate:
61  return;
62  }
63  llvm_unreachable("bad evaluation kind");
64 }
65 
66 /// Emit code to cause the destruction of the given variable with
67 /// static storage duration.
68 static void EmitDeclDestroy(CodeGenFunction &CGF, const VarDecl &D,
69  ConstantAddress Addr) {
70  // Honor __attribute__((no_destroy)) and bail instead of attempting
71  // to emit a reference to a possibly nonexistent destructor, which
72  // in turn can cause a crash. This will result in a global constructor
73  // that isn't balanced out by a destructor call as intended by the
74  // attribute. This also checks for -fno-c++-static-destructors and
75  // bails even if the attribute is not present.
77 
78  // FIXME: __attribute__((cleanup)) ?
79 
80  switch (DtorKind) {
81  case QualType::DK_none:
82  return;
83 
85  break;
86 
90  // We don't care about releasing objects during process teardown.
91  assert(!D.getTLSKind() && "should have rejected this");
92  return;
93  }
94 
95  llvm::FunctionCallee Func;
96  llvm::Constant *Argument;
97 
98  CodeGenModule &CGM = CGF.CGM;
99  QualType Type = D.getType();
100 
101  // Special-case non-array C++ destructors, if they have the right signature.
102  // Under some ABIs, destructors return this instead of void, and cannot be
103  // passed directly to __cxa_atexit if the target does not allow this
104  // mismatch.
105  const CXXRecordDecl *Record = Type->getAsCXXRecordDecl();
106  bool CanRegisterDestructor =
107  Record && (!CGM.getCXXABI().HasThisReturn(
108  GlobalDecl(Record->getDestructor(), Dtor_Complete)) ||
110  // If __cxa_atexit is disabled via a flag, a different helper function is
111  // generated elsewhere which uses atexit instead, and it takes the destructor
112  // directly.
113  bool UsingExternalHelper = !CGM.getCodeGenOpts().CXAAtExit;
114  if (Record && (CanRegisterDestructor || UsingExternalHelper)) {
115  assert(!Record->hasTrivialDestructor());
116  CXXDestructorDecl *Dtor = Record->getDestructor();
117 
119  if (CGF.getContext().getLangOpts().OpenCL) {
120  auto DestAS =
122  auto DestTy = CGF.getTypes().ConvertType(Type)->getPointerTo(
123  CGM.getContext().getTargetAddressSpace(DestAS));
124  auto SrcAS = D.getType().getQualifiers().getAddressSpace();
125  if (DestAS == SrcAS)
126  Argument = llvm::ConstantExpr::getBitCast(Addr.getPointer(), DestTy);
127  else
128  // FIXME: On addr space mismatch we are passing NULL. The generation
129  // of the global destructor function should be adjusted accordingly.
130  Argument = llvm::ConstantPointerNull::get(DestTy);
131  } else {
132  Argument = llvm::ConstantExpr::getBitCast(
133  Addr.getPointer(), CGF.getTypes().ConvertType(Type)->getPointerTo());
134  }
135  // Otherwise, the standard logic requires a helper function.
136  } else {
137  Func = CodeGenFunction(CGM)
138  .generateDestroyHelper(Addr, Type, CGF.getDestroyer(DtorKind),
139  CGF.needsEHCleanup(DtorKind), &D);
140  Argument = llvm::Constant::getNullValue(CGF.Int8PtrTy);
141  }
142 
143  CGM.getCXXABI().registerGlobalDtor(CGF, D, Func, Argument);
144 }
145 
146 /// Emit code to cause the variable at the given address to be considered as
147 /// constant from this point onwards.
148 static void EmitDeclInvariant(CodeGenFunction &CGF, const VarDecl &D,
149  llvm::Constant *Addr) {
150  return CGF.EmitInvariantStart(
151  Addr, CGF.getContext().getTypeSizeInChars(D.getType()));
152 }
153 
154 void CodeGenFunction::EmitInvariantStart(llvm::Constant *Addr, CharUnits Size) {
155  // Do not emit the intrinsic if we're not optimizing.
156  if (!CGM.getCodeGenOpts().OptimizationLevel)
157  return;
158 
159  // Grab the llvm.invariant.start intrinsic.
160  llvm::Intrinsic::ID InvStartID = llvm::Intrinsic::invariant_start;
161  // Overloaded address space type.
162  llvm::Type *ObjectPtr[1] = {Int8PtrTy};
163  llvm::Function *InvariantStart = CGM.getIntrinsic(InvStartID, ObjectPtr);
164 
165  // Emit a call with the size in bytes of the object.
166  uint64_t Width = Size.getQuantity();
167  llvm::Value *Args[2] = { llvm::ConstantInt::getSigned(Int64Ty, Width),
168  llvm::ConstantExpr::getBitCast(Addr, Int8PtrTy)};
169  Builder.CreateCall(InvariantStart, Args);
170 }
171 
173  llvm::Constant *DeclPtr,
174  bool PerformInit) {
175 
176  const Expr *Init = D.getInit();
177  QualType T = D.getType();
178 
179  // The address space of a static local variable (DeclPtr) may be different
180  // from the address space of the "this" argument of the constructor. In that
181  // case, we need an addrspacecast before calling the constructor.
182  //
183  // struct StructWithCtor {
184  // __device__ StructWithCtor() {...}
185  // };
186  // __device__ void foo() {
187  // __shared__ StructWithCtor s;
188  // ...
189  // }
190  //
191  // For example, in the above CUDA code, the static local variable s has a
192  // "shared" address space qualifier, but the constructor of StructWithCtor
193  // expects "this" in the "generic" address space.
194  unsigned ExpectedAddrSpace = getContext().getTargetAddressSpace(T);
195  unsigned ActualAddrSpace = DeclPtr->getType()->getPointerAddressSpace();
196  if (ActualAddrSpace != ExpectedAddrSpace) {
198  llvm::PointerType *PTy = llvm::PointerType::get(LTy, ExpectedAddrSpace);
199  DeclPtr = llvm::ConstantExpr::getAddrSpaceCast(DeclPtr, PTy);
200  }
201 
202  ConstantAddress DeclAddr(DeclPtr, getContext().getDeclAlign(&D));
203 
204  if (!T->isReferenceType()) {
205  if (getLangOpts().OpenMP && !getLangOpts().OpenMPSimd &&
206  D.hasAttr<OMPThreadPrivateDeclAttr>()) {
207  (void)CGM.getOpenMPRuntime().emitThreadPrivateVarDefinition(
208  &D, DeclAddr, D.getAttr<OMPThreadPrivateDeclAttr>()->getLocation(),
209  PerformInit, this);
210  }
211  if (PerformInit)
212  EmitDeclInit(*this, D, DeclAddr);
213  if (CGM.isTypeConstant(D.getType(), true))
214  EmitDeclInvariant(*this, D, DeclPtr);
215  else
216  EmitDeclDestroy(*this, D, DeclAddr);
217  return;
218  }
219 
220  assert(PerformInit && "cannot have constant initializer which needs "
221  "destruction for reference");
223  EmitStoreOfScalar(RV.getScalarVal(), DeclAddr, false, T);
224 }
225 
226 /// Create a stub function, suitable for being passed to atexit,
227 /// which passes the given address to the given destructor function.
228 llvm::Function *CodeGenFunction::createAtExitStub(const VarDecl &VD,
229  llvm::FunctionCallee dtor,
230  llvm::Constant *addr) {
231  // Get the destructor function type, void(*)(void).
232  llvm::FunctionType *ty = llvm::FunctionType::get(CGM.VoidTy, false);
233  SmallString<256> FnName;
234  {
235  llvm::raw_svector_ostream Out(FnName);
237  }
238 
240  llvm::Function *fn = CGM.CreateGlobalInitOrDestructFunction(
241  ty, FnName.str(), FI, VD.getLocation());
242 
243  CodeGenFunction CGF(CGM);
244 
246  CGM.getContext().VoidTy, fn, FI, FunctionArgList());
247 
248  llvm::CallInst *call = CGF.Builder.CreateCall(dtor, addr);
249 
250  // Make sure the call and the callee agree on calling convention.
251  if (auto *dtorFn = dyn_cast<llvm::Function>(
252  dtor.getCallee()->stripPointerCastsAndAliases()))
253  call->setCallingConv(dtorFn->getCallingConv());
254 
255  CGF.FinishFunction();
256 
257  return fn;
258 }
259 
260 /// Register a global destructor using the C atexit runtime function.
262  llvm::FunctionCallee dtor,
263  llvm::Constant *addr) {
264  // Create a function which calls the destructor.
265  llvm::Constant *dtorStub = createAtExitStub(VD, dtor, addr);
267 }
268 
269 void CodeGenFunction::registerGlobalDtorWithAtExit(llvm::Constant *dtorStub) {
270  // extern "C" int atexit(void (*f)(void));
271  llvm::FunctionType *atexitTy =
272  llvm::FunctionType::get(IntTy, dtorStub->getType(), false);
273 
274  llvm::FunctionCallee atexit =
275  CGM.CreateRuntimeFunction(atexitTy, "atexit", llvm::AttributeList(),
276  /*Local=*/true);
277  if (llvm::Function *atexitFn = dyn_cast<llvm::Function>(atexit.getCallee()))
278  atexitFn->setDoesNotThrow();
279 
280  EmitNounwindRuntimeCall(atexit, dtorStub);
281 }
282 
284  llvm::GlobalVariable *DeclPtr,
285  bool PerformInit) {
286  // If we've been asked to forbid guard variables, emit an error now.
287  // This diagnostic is hard-coded for Darwin's use case; we can find
288  // better phrasing if someone else needs it.
289  if (CGM.getCodeGenOpts().ForbidGuardVariables)
290  CGM.Error(D.getLocation(),
291  "this initialization requires a guard variable, which "
292  "the kernel does not support");
293 
294  CGM.getCXXABI().EmitGuardedInit(*this, D, DeclPtr, PerformInit);
295 }
296 
298  llvm::BasicBlock *InitBlock,
299  llvm::BasicBlock *NoInitBlock,
300  GuardKind Kind,
301  const VarDecl *D) {
302  assert((Kind == GuardKind::TlsGuard || D) && "no guarded variable");
303 
304  // A guess at how many times we will enter the initialization of a
305  // variable, depending on the kind of variable.
306  static const uint64_t InitsPerTLSVar = 1024;
307  static const uint64_t InitsPerLocalVar = 1024 * 1024;
308 
309  llvm::MDNode *Weights;
310  if (Kind == GuardKind::VariableGuard && !D->isLocalVarDecl()) {
311  // For non-local variables, don't apply any weighting for now. Due to our
312  // use of COMDATs, we expect there to be at most one initialization of the
313  // variable per DSO, but we have no way to know how many DSOs will try to
314  // initialize the variable.
315  Weights = nullptr;
316  } else {
317  uint64_t NumInits;
318  // FIXME: For the TLS case, collect and use profiling information to
319  // determine a more accurate brach weight.
320  if (Kind == GuardKind::TlsGuard || D->getTLSKind())
321  NumInits = InitsPerTLSVar;
322  else
323  NumInits = InitsPerLocalVar;
324 
325  // The probability of us entering the initializer is
326  // 1 / (total number of times we attempt to initialize the variable).
327  llvm::MDBuilder MDHelper(CGM.getLLVMContext());
328  Weights = MDHelper.createBranchWeights(1, NumInits - 1);
329  }
330 
331  Builder.CreateCondBr(NeedsInit, InitBlock, NoInitBlock, Weights);
332 }
333 
335  llvm::FunctionType *FTy, const Twine &Name, const CGFunctionInfo &FI,
336  SourceLocation Loc, bool TLS) {
337  llvm::Function *Fn =
339  Name, &getModule());
340  if (!getLangOpts().AppleKext && !TLS) {
341  // Set the section if needed.
342  if (const char *Section = getTarget().getStaticInitSectionSpecifier())
343  Fn->setSection(Section);
344  }
345 
346  SetInternalFunctionAttributes(GlobalDecl(), Fn, FI);
347 
348  Fn->setCallingConv(getRuntimeCC());
349 
350  if (!getLangOpts().Exceptions)
351  Fn->setDoesNotThrow();
352 
353  if (getLangOpts().Sanitize.has(SanitizerKind::Address) &&
354  !isInSanitizerBlacklist(SanitizerKind::Address, Fn, Loc))
355  Fn->addFnAttr(llvm::Attribute::SanitizeAddress);
356 
357  if (getLangOpts().Sanitize.has(SanitizerKind::KernelAddress) &&
358  !isInSanitizerBlacklist(SanitizerKind::KernelAddress, Fn, Loc))
359  Fn->addFnAttr(llvm::Attribute::SanitizeAddress);
360 
361  if (getLangOpts().Sanitize.has(SanitizerKind::HWAddress) &&
362  !isInSanitizerBlacklist(SanitizerKind::HWAddress, Fn, Loc))
363  Fn->addFnAttr(llvm::Attribute::SanitizeHWAddress);
364 
365  if (getLangOpts().Sanitize.has(SanitizerKind::KernelHWAddress) &&
366  !isInSanitizerBlacklist(SanitizerKind::KernelHWAddress, Fn, Loc))
367  Fn->addFnAttr(llvm::Attribute::SanitizeHWAddress);
368 
369  if (getLangOpts().Sanitize.has(SanitizerKind::MemTag) &&
370  !isInSanitizerBlacklist(SanitizerKind::MemTag, Fn, Loc))
371  Fn->addFnAttr(llvm::Attribute::SanitizeMemTag);
372 
373  if (getLangOpts().Sanitize.has(SanitizerKind::Thread) &&
374  !isInSanitizerBlacklist(SanitizerKind::Thread, Fn, Loc))
375  Fn->addFnAttr(llvm::Attribute::SanitizeThread);
376 
377  if (getLangOpts().Sanitize.has(SanitizerKind::Memory) &&
378  !isInSanitizerBlacklist(SanitizerKind::Memory, Fn, Loc))
379  Fn->addFnAttr(llvm::Attribute::SanitizeMemory);
380 
381  if (getLangOpts().Sanitize.has(SanitizerKind::KernelMemory) &&
382  !isInSanitizerBlacklist(SanitizerKind::KernelMemory, Fn, Loc))
383  Fn->addFnAttr(llvm::Attribute::SanitizeMemory);
384 
385  if (getLangOpts().Sanitize.has(SanitizerKind::SafeStack) &&
386  !isInSanitizerBlacklist(SanitizerKind::SafeStack, Fn, Loc))
387  Fn->addFnAttr(llvm::Attribute::SafeStack);
388 
389  if (getLangOpts().Sanitize.has(SanitizerKind::ShadowCallStack) &&
390  !isInSanitizerBlacklist(SanitizerKind::ShadowCallStack, Fn, Loc))
391  Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
392 
393  auto RASignKind = getCodeGenOpts().getSignReturnAddress();
395  Fn->addFnAttr("sign-return-address",
397  ? "all"
398  : "non-leaf");
399  auto RASignKey = getCodeGenOpts().getSignReturnAddressKey();
400  Fn->addFnAttr("sign-return-address-key",
401  RASignKey == CodeGenOptions::SignReturnAddressKeyValue::AKey
402  ? "a_key"
403  : "b_key");
404  }
405 
406  if (getCodeGenOpts().BranchTargetEnforcement)
407  Fn->addFnAttr("branch-target-enforcement");
408 
409  return Fn;
410 }
411 
412 /// Create a global pointer to a function that will initialize a global
413 /// variable. The user has requested that this pointer be emitted in a specific
414 /// section.
415 void CodeGenModule::EmitPointerToInitFunc(const VarDecl *D,
416  llvm::GlobalVariable *GV,
417  llvm::Function *InitFunc,
418  InitSegAttr *ISA) {
419  llvm::GlobalVariable *PtrArray = new llvm::GlobalVariable(
420  TheModule, InitFunc->getType(), /*isConstant=*/true,
421  llvm::GlobalValue::PrivateLinkage, InitFunc, "__cxx_init_fn_ptr");
422  PtrArray->setSection(ISA->getSection());
423  addUsedGlobal(PtrArray);
424 
425  // If the GV is already in a comdat group, then we have to join it.
426  if (llvm::Comdat *C = GV->getComdat())
427  PtrArray->setComdat(C);
428 }
429 
430 void
431 CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
432  llvm::GlobalVariable *Addr,
433  bool PerformInit) {
434 
435  // According to E.2.3.1 in CUDA-7.5 Programming guide: __device__,
436  // __constant__ and __shared__ variables defined in namespace scope,
437  // that are of class type, cannot have a non-empty constructor. All
438  // the checks have been done in Sema by now. Whatever initializers
439  // are allowed are empty and we just need to ignore them here.
440  if (getLangOpts().CUDA && getLangOpts().CUDAIsDevice &&
441  (D->hasAttr<CUDADeviceAttr>() || D->hasAttr<CUDAConstantAttr>() ||
442  D->hasAttr<CUDASharedAttr>()))
443  return;
444 
445  if (getLangOpts().OpenMP &&
446  getOpenMPRuntime().emitDeclareTargetVarDefinition(D, Addr, PerformInit))
447  return;
448 
449  // Check if we've already initialized this decl.
450  auto I = DelayedCXXInitPosition.find(D);
451  if (I != DelayedCXXInitPosition.end() && I->second == ~0U)
452  return;
453 
454  llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false);
455  SmallString<256> FnName;
456  {
457  llvm::raw_svector_ostream Out(FnName);
458  getCXXABI().getMangleContext().mangleDynamicInitializer(D, Out);
459  }
460 
461  // Create a variable initialization function.
462  llvm::Function *Fn =
463  CreateGlobalInitOrDestructFunction(FTy, FnName.str(),
465  D->getLocation());
466 
467  auto *ISA = D->getAttr<InitSegAttr>();
469  PerformInit);
470 
471  llvm::GlobalVariable *COMDATKey =
472  supportsCOMDAT() && D->isExternallyVisible() ? Addr : nullptr;
473 
474  if (D->getTLSKind()) {
475  // FIXME: Should we support init_priority for thread_local?
476  // FIXME: We only need to register one __cxa_thread_atexit function for the
477  // entire TU.
478  CXXThreadLocalInits.push_back(Fn);
479  CXXThreadLocalInitVars.push_back(D);
480  } else if (PerformInit && ISA) {
481  EmitPointerToInitFunc(D, Addr, Fn, ISA);
482  } else if (auto *IPA = D->getAttr<InitPriorityAttr>()) {
483  OrderGlobalInits Key(IPA->getPriority(), PrioritizedCXXGlobalInits.size());
484  PrioritizedCXXGlobalInits.push_back(std::make_pair(Key, Fn));
487  // C++ [basic.start.init]p2:
488  // Definitions of explicitly specialized class template static data
489  // members have ordered initialization. Other class template static data
490  // members (i.e., implicitly or explicitly instantiated specializations)
491  // have unordered initialization.
492  //
493  // As a consequence, we can put them into their own llvm.global_ctors entry.
494  //
495  // If the global is externally visible, put the initializer into a COMDAT
496  // group with the global being initialized. On most platforms, this is a
497  // minor startup time optimization. In the MS C++ ABI, there are no guard
498  // variables, so this COMDAT key is required for correctness.
499  AddGlobalCtor(Fn, 65535, COMDATKey);
500  if (getTarget().getCXXABI().isMicrosoft() && COMDATKey) {
501  // In The MS C++, MS add template static data member in the linker
502  // drective.
503  addUsedGlobal(COMDATKey);
504  }
505  } else if (D->hasAttr<SelectAnyAttr>()) {
506  // SelectAny globals will be comdat-folded. Put the initializer into a
507  // COMDAT group associated with the global, so the initializers get folded
508  // too.
509  AddGlobalCtor(Fn, 65535, COMDATKey);
510  } else {
511  I = DelayedCXXInitPosition.find(D); // Re-do lookup in case of re-hash.
512  if (I == DelayedCXXInitPosition.end()) {
513  CXXGlobalInits.push_back(Fn);
514  } else if (I->second != ~0U) {
515  assert(I->second < CXXGlobalInits.size() &&
516  CXXGlobalInits[I->second] == nullptr);
517  CXXGlobalInits[I->second] = Fn;
518  }
519  }
520 
521  // Remember that we already emitted the initializer for this global.
522  DelayedCXXInitPosition[D] = ~0U;
523 }
524 
525 void CodeGenModule::EmitCXXThreadLocalInitFunc() {
526  getCXXABI().EmitThreadLocalInitFuncs(
527  *this, CXXThreadLocals, CXXThreadLocalInits, CXXThreadLocalInitVars);
528 
529  CXXThreadLocalInits.clear();
530  CXXThreadLocalInitVars.clear();
531  CXXThreadLocals.clear();
532 }
533 
534 void
535 CodeGenModule::EmitCXXGlobalInitFunc() {
536  while (!CXXGlobalInits.empty() && !CXXGlobalInits.back())
537  CXXGlobalInits.pop_back();
538 
539  if (CXXGlobalInits.empty() && PrioritizedCXXGlobalInits.empty())
540  return;
541 
542  llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false);
544 
545  // Create our global initialization function.
546  if (!PrioritizedCXXGlobalInits.empty()) {
547  SmallVector<llvm::Function *, 8> LocalCXXGlobalInits;
548  llvm::array_pod_sort(PrioritizedCXXGlobalInits.begin(),
549  PrioritizedCXXGlobalInits.end());
550  // Iterate over "chunks" of ctors with same priority and emit each chunk
551  // into separate function. Note - everything is sorted first by priority,
552  // second - by lex order, so we emit ctor functions in proper order.
554  I = PrioritizedCXXGlobalInits.begin(),
555  E = PrioritizedCXXGlobalInits.end(); I != E; ) {
557  PrioE = std::upper_bound(I + 1, E, *I, GlobalInitPriorityCmp());
558 
559  LocalCXXGlobalInits.clear();
560  unsigned Priority = I->first.priority;
561  // Compute the function suffix from priority. Prepend with zeroes to make
562  // sure the function names are also ordered as priorities.
563  std::string PrioritySuffix = llvm::utostr(Priority);
564  // Priority is always <= 65535 (enforced by sema).
565  PrioritySuffix = std::string(6-PrioritySuffix.size(), '0')+PrioritySuffix;
566  llvm::Function *Fn = CreateGlobalInitOrDestructFunction(
567  FTy, "_GLOBAL__I_" + PrioritySuffix, FI);
568 
569  for (; I < PrioE; ++I)
570  LocalCXXGlobalInits.push_back(I->second);
571 
572  CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn, LocalCXXGlobalInits);
573  AddGlobalCtor(Fn, Priority);
574  }
575  PrioritizedCXXGlobalInits.clear();
576  }
577 
578  // Include the filename in the symbol name. Including "sub_" matches gcc and
579  // makes sure these symbols appear lexicographically behind the symbols with
580  // priority emitted above.
581  SmallString<128> FileName = llvm::sys::path::filename(getModule().getName());
582  if (FileName.empty())
583  FileName = "<null>";
584 
585  for (size_t i = 0; i < FileName.size(); ++i) {
586  // Replace everything that's not [a-zA-Z0-9._] with a _. This set happens
587  // to be the set of C preprocessing numbers.
588  if (!isPreprocessingNumberBody(FileName[i]))
589  FileName[i] = '_';
590  }
591 
592  llvm::Function *Fn = CreateGlobalInitOrDestructFunction(
593  FTy, llvm::Twine("_GLOBAL__sub_I_", FileName), FI);
594 
595  CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn, CXXGlobalInits);
596  AddGlobalCtor(Fn);
597 
598  // In OpenCL global init functions must be converted to kernels in order to
599  // be able to launch them from the host.
600  // FIXME: Some more work might be needed to handle destructors correctly.
601  // Current initialization function makes use of function pointers callbacks.
602  // We can't support function pointers especially between host and device.
603  // However it seems global destruction has little meaning without any
604  // dynamic resource allocation on the device and program scope variables are
605  // destroyed by the runtime when program is released.
606  if (getLangOpts().OpenCL) {
607  GenOpenCLArgMetadata(Fn);
608  Fn->setCallingConv(llvm::CallingConv::SPIR_KERNEL);
609  }
610 
611  CXXGlobalInits.clear();
612 }
613 
614 void CodeGenModule::EmitCXXGlobalDtorFunc() {
615  if (CXXGlobalDtors.empty())
616  return;
617 
618  llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false);
619 
620  // Create our global destructor function.
622  llvm::Function *Fn =
623  CreateGlobalInitOrDestructFunction(FTy, "_GLOBAL__D_a", FI);
624 
625  CodeGenFunction(*this).GenerateCXXGlobalDtorsFunc(Fn, CXXGlobalDtors);
626  AddGlobalDtor(Fn);
627 }
628 
629 /// Emit the code necessary to initialize the given global variable.
631  const VarDecl *D,
632  llvm::GlobalVariable *Addr,
633  bool PerformInit) {
634  // Check if we need to emit debug info for variable initializer.
635  if (D->hasAttr<NoDebugAttr>())
636  DebugInfo = nullptr; // disable debug info indefinitely for this function
637 
638  CurEHLocation = D->getBeginLoc();
639 
641  getContext().VoidTy, Fn, getTypes().arrangeNullaryFunction(),
643  D->getInit()->getExprLoc());
644 
645  // Use guarded initialization if the global variable is weak. This
646  // occurs for, e.g., instantiated static data members and
647  // definitions explicitly marked weak.
648  //
649  // Also use guarded initialization for a variable with dynamic TLS and
650  // unordered initialization. (If the initialization is ordered, the ABI
651  // layer will guard the whole-TU initialization for us.)
652  if (Addr->hasWeakLinkage() || Addr->hasLinkOnceLinkage() ||
653  (D->getTLSKind() == VarDecl::TLS_Dynamic &&
655  EmitCXXGuardedInit(*D, Addr, PerformInit);
656  } else {
657  EmitCXXGlobalVarDeclInit(*D, Addr, PerformInit);
658  }
659 
660  FinishFunction();
661 }
662 
663 void
666  ConstantAddress Guard) {
667  {
668  auto NL = ApplyDebugLocation::CreateEmpty(*this);
670  getTypes().arrangeNullaryFunction(), FunctionArgList());
671  // Emit an artificial location for this function.
672  auto AL = ApplyDebugLocation::CreateArtificial(*this);
673 
674  llvm::BasicBlock *ExitBlock = nullptr;
675  if (Guard.isValid()) {
676  // If we have a guard variable, check whether we've already performed
677  // these initializations. This happens for TLS initialization functions.
678  llvm::Value *GuardVal = Builder.CreateLoad(Guard);
679  llvm::Value *Uninit = Builder.CreateIsNull(GuardVal,
680  "guard.uninitialized");
681  llvm::BasicBlock *InitBlock = createBasicBlock("init");
682  ExitBlock = createBasicBlock("exit");
683  EmitCXXGuardedInitBranch(Uninit, InitBlock, ExitBlock,
684  GuardKind::TlsGuard, nullptr);
685  EmitBlock(InitBlock);
686  // Mark as initialized before initializing anything else. If the
687  // initializers use previously-initialized thread_local vars, that's
688  // probably supposed to be OK, but the standard doesn't say.
689  Builder.CreateStore(llvm::ConstantInt::get(GuardVal->getType(),1), Guard);
690 
691  // The guard variable can't ever change again.
693  Guard.getPointer(),
695  CGM.getDataLayout().getTypeAllocSize(GuardVal->getType())));
696  }
697 
698  RunCleanupsScope Scope(*this);
699 
700  // When building in Objective-C++ ARC mode, create an autorelease pool
701  // around the global initializers.
702  if (getLangOpts().ObjCAutoRefCount && getLangOpts().CPlusPlus) {
705  }
706 
707  for (unsigned i = 0, e = Decls.size(); i != e; ++i)
708  if (Decls[i])
709  EmitRuntimeCall(Decls[i]);
710 
711  Scope.ForceCleanup();
712 
713  if (ExitBlock) {
714  Builder.CreateBr(ExitBlock);
715  EmitBlock(ExitBlock);
716  }
717  }
718 
719  FinishFunction();
720 }
721 
723  llvm::Function *Fn,
724  const std::vector<std::tuple<llvm::FunctionType *, llvm::WeakTrackingVH,
725  llvm::Constant *>> &DtorsAndObjects) {
726  {
727  auto NL = ApplyDebugLocation::CreateEmpty(*this);
729  getTypes().arrangeNullaryFunction(), FunctionArgList());
730  // Emit an artificial location for this function.
731  auto AL = ApplyDebugLocation::CreateArtificial(*this);
732 
733  // Emit the dtors, in reverse order from construction.
734  for (unsigned i = 0, e = DtorsAndObjects.size(); i != e; ++i) {
735  llvm::FunctionType *CalleeTy;
736  llvm::Value *Callee;
737  llvm::Constant *Arg;
738  std::tie(CalleeTy, Callee, Arg) = DtorsAndObjects[e - i - 1];
739  llvm::CallInst *CI = Builder.CreateCall(CalleeTy, Callee, Arg);
740  // Make sure the call and the callee agree on calling convention.
741  if (llvm::Function *F = dyn_cast<llvm::Function>(Callee))
742  CI->setCallingConv(F->getCallingConv());
743  }
744  }
745 
746  FinishFunction();
747 }
748 
749 /// generateDestroyHelper - Generates a helper function which, when
750 /// invoked, destroys the given object. The address of the object
751 /// should be in global memory.
753  Address addr, QualType type, Destroyer *destroyer,
754  bool useEHCleanupForArray, const VarDecl *VD) {
755  FunctionArgList args;
758  args.push_back(&Dst);
759 
760  const CGFunctionInfo &FI =
762  llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI);
763  llvm::Function *fn = CGM.CreateGlobalInitOrDestructFunction(
764  FTy, "__cxx_global_array_dtor", FI, VD->getLocation());
765 
766  CurEHLocation = VD->getBeginLoc();
767 
768  StartFunction(VD, getContext().VoidTy, fn, FI, args);
769 
770  emitDestroy(addr, type, destroyer, useEHCleanupForArray);
771 
772  FinishFunction();
773 
774  return fn;
775 }
const CGFunctionInfo & arrangeBuiltinFunctionDeclaration(QualType resultType, const FunctionArgList &args)
A builtin function is a freestanding function using the default C conventions.
Definition: CGCall.cpp:652
const llvm::DataLayout & getDataLayout() const
void EmitCXXGuardedInitBranch(llvm::Value *NeedsInit, llvm::BasicBlock *InitBlock, llvm::BasicBlock *NoInitBlock, GuardKind Kind, const VarDecl *D)
Emit a branch to select whether or not to perform guarded initialization.
Definition: CGDeclCXX.cpp:297
llvm::IntegerType * IntTy
int
Other implicit parameter.
Definition: Decl.h:1560
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
Definition: CGDecl.cpp:2026
A (possibly-)qualified type.
Definition: Type.h:643
const CodeGenOptions & getCodeGenOpts() const
llvm::LLVMContext & getLLVMContext()
The base class of the type hierarchy.
Definition: Type.h:1436
void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit)
EmitComplexExprIntoLValue - Emit the given expression of complex type and place its result into the s...
Represents a variable declaration or definition.
Definition: Decl.h:827
llvm::Value * EmitObjCAutoreleasePoolPush()
Produce the code to do a objc_autoreleasepool_push.
Definition: CGObjC.cpp:2484
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
std::string getName(ArrayRef< StringRef > Parts) const
Get the platform-specific name separator.
const TargetInfo & getTarget() const
void emitDestroy(Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
emitDestroy - Immediately perform the destruction of the given object.
Definition: CGDecl.cpp:2101
QualType::DestructionKind needsDestruction(const ASTContext &Ctx) const
Do we need to emit an exit-time destructor for this variable, and if so, what kind?
Definition: Decl.cpp:2598
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
Definition: CGExpr.cpp:593
bool isReferenceType() const
Definition: Type.h:6403
void registerGlobalDtorWithAtExit(const VarDecl &D, llvm::FunctionCallee fn, llvm::Constant *addr)
Call atexit() with a function that passes the given argument to the given function.
Definition: CGDeclCXX.cpp:261
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:746
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:630
void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, QualType Ty, AlignmentSource Source=AlignmentSource::Type, bool isInit=false, bool isNontemporal=false)
EmitStoreOfScalar - Store a scalar value to an address, taking care to appropriately convert from the...
static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF)
Apply TemporaryLocation if it is valid.
Definition: CGDebugInfo.h:742
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
llvm::CallInst * EmitRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
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:2534
bool needsEHCleanup(QualType::DestructionKind kind)
Determines whether an EH cleanup is required to destroy a type with the given destruction kind...
LangAS getAddressSpace() const
Definition: Type.h:353
bool isObjCWeak() const
Definition: CGValue.h:293
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
Definition: DeclCXX.h:1270
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
Definition: DeclCXX.cpp:1765
virtual bool canCallMismatchedFunctionType() const
Returns true if the target allows calling a function through a pointer with a different signature tha...
Definition: CGCXXABI.h:118
constexpr XRayInstrMask All
Definition: XRayInstr.h:41
virtual void EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dest, bool threadlocal=false)=0
bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor)
isTypeConstant - Determine whether an object of this type can be emitted as a constant.
bool hasAttr() const
Definition: DeclBase.h:542
bool isValid() const
Definition: Address.h:35
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1692
const TargetCodeGenInfo & getTargetCodeGenInfo()
RValue - This trivial value class is used to represent the result of an expression that is evaluated...
Definition: CGValue.h:38
virtual void mangleDynamicAtExitDestructor(const VarDecl *D, raw_ostream &)=0
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:179
virtual bool HasThisReturn(GlobalDecl GD) const
Returns true if the given constructor or destructor is one of the kinds that the ABI says returns &#39;th...
Definition: CGCXXABI.h:106
llvm::CallingConv::ID getRuntimeCC() const
void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr, bool PerformInit)
Emit code in this function to perform a guarded variable initialization.
Definition: CGDeclCXX.cpp:283
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
llvm::Function * generateDestroyHelper(Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray, const VarDecl *VD)
generateDestroyHelper - Generates a helper function which, when invoked, destroys the given object...
Definition: CGDeclCXX.cpp:752
This represents one expression.
Definition: Expr.h:108
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
Definition: Decl.h:1050
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited...
const CGFunctionInfo & arrangeNullaryFunction()
A nullary function is a freestanding function of type &#39;void ()&#39;.
Definition: CGCall.cpp:694
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2629
virtual void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D, llvm::GlobalVariable *DeclPtr, bool PerformInit)=0
Emits the guarded initializer and destructor setup for the given variable, given that it couldn&#39;t be ...
void EmitInvariantStart(llvm::Constant *Addr, CharUnits Size)
Definition: CGDeclCXX.cpp:154
TLSKind getTLSKind() const
Definition: Decl.cpp:1983
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
Definition: CharUnits.h:63
void GenerateCXXGlobalInitFunc(llvm::Function *Fn, ArrayRef< llvm::Function *> CXXThreadLocals, ConstantAddress Guard=ConstantAddress::invalid())
GenerateCXXGlobalInitFunc - Generates code for initializing global variables.
Definition: CGDeclCXX.cpp:664
void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::Constant *DeclPtr, bool PerformInit)
EmitCXXGlobalVarDeclInit - Create the initializer for a C++ variable with global storage.
Definition: CGDeclCXX.cpp:172
bool isObjCStrong() const
Definition: CGValue.h:296
ASTContext & getContext() const
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
Definition: Specifiers.h:199
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:40
The l-value was considered opaque, so the alignment was determined from a type.
Kind
Encodes a location in the source.
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
Definition: Decl.h:1092
CanQualType VoidTy
Definition: ASTContext.h:1015
An aligned address.
Definition: Address.h:24
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.
MangleContext & getMangleContext()
Gets the mangle context.
Definition: CGCXXABI.h:96
Complete object dtor.
Definition: ABI.h:35
constexpr XRayInstrMask None
Definition: XRayInstr.h:37
void Error(SourceLocation loc, StringRef error)
Emit a general error that something can&#39;t be done.
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:221
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type, returning the result.
FunctionArgList - Type for representing both the decl and type of parameters to a function...
Definition: CGCall.h:358
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
Definition: CGValue.h:58
TLS with a dynamic initializer.
Definition: Decl.h:850
CGFunctionInfo - Class to encapsulate the information about a function definition.
This class organizes the cross-function state that is used while generating LLVM code.
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
Dataflow Directional Tag Classes.
const Expr * getInit() const
Definition: Decl.h:1234
llvm::Constant * getPointer() const
Definition: Address.h:83
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
Definition: CGBuilder.h:69
virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D, llvm::FunctionCallee Dtor, llvm::Constant *Addr)=0
Emit code to force the execution of a destructor during global teardown.
static void EmitDeclDestroy(CodeGenFunction &CGF, const VarDecl &D, ConstantAddress Addr)
Emit code to cause the destruction of the given variable with static storage duration.
Definition: CGDeclCXX.cpp:68
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type *> Tys=None)
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
Definition: CGBuilder.h:107
static AggValueSlot forLValue(const LValue &LV, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
Definition: CGValue.h:539
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
llvm::Function * createAtExitStub(const VarDecl &VD, llvm::FunctionCallee Dtor, llvm::Constant *Addr)
Create a stub function, suitable for being passed to atexit, which passes the given address to the gi...
Definition: CGDeclCXX.cpp:228
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type. ...
Definition: CGExprAgg.cpp:1851
GVALinkage GetGVALinkageForVariable(const VarDecl *VD)
virtual void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dest)=0
virtual bool emitDeclareTargetVarDefinition(const VarDecl *VD, llvm::GlobalVariable *Addr, bool PerformInit)
Emit a code for initialization of declare target variable.
CodeGenTypes & getTypes() const
T * getAttr() const
Definition: DeclBase.h:538
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
Definition: CGDecl.cpp:740
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
Definition: Linkage.h:31
llvm::FunctionCallee CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList(), bool Local=false)
Create or return a runtime function declaration with the specified type and name. ...
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
Definition: CGStmt.cpp:465
static void EmitDeclInit(CodeGenFunction &CGF, const VarDecl &D, ConstantAddress DeclPtr)
Definition: CGDeclCXX.cpp:27
llvm::FunctionCallee getAddrAndTypeOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Definition: CGCXX.cpp:220
Represents a C++ struct/union/class.
Definition: DeclCXX.h:255
llvm::Function * CreateGlobalInitOrDestructFunction(llvm::FunctionType *ty, const Twine &name, const CGFunctionInfo &FI, SourceLocation Loc=SourceLocation(), bool TLS=false)
Definition: CGDeclCXX.cpp:334
int Priority
Definition: Format.cpp:1811
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:6175
A specialization of Address that requires the address to be an LLVM Constant.
Definition: Address.h:74
void GenerateCXXGlobalDtorsFunc(llvm::Function *Fn, const std::vector< std::tuple< llvm::FunctionType *, llvm::WeakTrackingVH, llvm::Constant *>> &DtorsAndObjects)
GenerateCXXGlobalDtorsFunc - Generates code for destroying global variables.
Definition: CGDeclCXX.cpp:722
CGCXXABI & getCXXABI() const
virtual LangAS getAddrSpaceOfCxaAtexitPtrParam() const
Get address space of pointer parameter for __cxa_atexit.
Definition: TargetInfo.h:271
void EmitObjCAutoreleasePoolCleanup(llvm::Value *Ptr)
Definition: CGObjC.cpp:2680
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF)
Set the IRBuilder to not attach debug locations.
Definition: CGDebugInfo.h:759
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
Definition: Decl.h:1119
QualType getType() const
Definition: Decl.h:655
LValue - This represents an lvalue references.
Definition: CGValue.h:166
const LangOptions & getLangOpts() const
unsigned getTargetAddressSpace(QualType T) const
Definition: ASTContext.h:2541
llvm::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
LLVM_READONLY bool isPreprocessingNumberBody(unsigned char c)
Return true if this is the body character of a C preprocessing number, which is [a-zA-Z0-9_.
Definition: CharInfo.h:147
const LangOptions & getLangOpts() const
Definition: ASTContext.h:723
SourceLocation getLocation() const
Definition: DeclBase.h:429
bool isExternallyVisible() const
Definition: Decl.h:387
static void EmitDeclInvariant(CodeGenFunction &CGF, const VarDecl &D, llvm::Constant *Addr)
Emit code to cause the variable at the given address to be considered as constant from this point onw...
Definition: CGDeclCXX.cpp:148
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> PL, ArrayRef< Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.
void Destroyer(CodeGenFunction &CGF, Address addr, QualType ty)
static CharUnits getDeclAlign(Expr *E, CharUnits TypeAlign, ASTContext &Context)
A helper function to get the alignment of a Decl referred to by DeclRefExpr or MemberExpr.
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
Definition: CGCall.cpp:1541