clang  14.0.0git
CodeGenFunction.cpp
Go to the documentation of this file.
1 //===--- CodeGenFunction.cpp - Emit LLVM Code from ASTs for a Function ----===//
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 coordinates the per-function state used while generating code.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "CodeGenFunction.h"
14 #include "CGBlocks.h"
15 #include "CGCUDARuntime.h"
16 #include "CGCXXABI.h"
17 #include "CGCleanup.h"
18 #include "CGDebugInfo.h"
19 #include "CGOpenMPRuntime.h"
20 #include "CodeGenModule.h"
21 #include "CodeGenPGO.h"
22 #include "TargetInfo.h"
23 #include "clang/AST/ASTContext.h"
24 #include "clang/AST/ASTLambda.h"
25 #include "clang/AST/Attr.h"
26 #include "clang/AST/Decl.h"
27 #include "clang/AST/DeclCXX.h"
28 #include "clang/AST/Expr.h"
29 #include "clang/AST/StmtCXX.h"
30 #include "clang/AST/StmtObjC.h"
31 #include "clang/Basic/Builtins.h"
33 #include "clang/Basic/TargetInfo.h"
36 #include "llvm/ADT/ArrayRef.h"
37 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
38 #include "llvm/IR/DataLayout.h"
39 #include "llvm/IR/Dominators.h"
40 #include "llvm/IR/FPEnv.h"
41 #include "llvm/IR/IntrinsicInst.h"
42 #include "llvm/IR/Intrinsics.h"
43 #include "llvm/IR/MDBuilder.h"
44 #include "llvm/IR/Operator.h"
45 #include "llvm/Support/CRC.h"
46 #include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
47 #include "llvm/Transforms/Utils/PromoteMemToReg.h"
48 
49 using namespace clang;
50 using namespace CodeGen;
51 
52 /// shouldEmitLifetimeMarkers - Decide whether we need emit the life-time
53 /// markers.
54 static bool shouldEmitLifetimeMarkers(const CodeGenOptions &CGOpts,
55  const LangOptions &LangOpts) {
56  if (CGOpts.DisableLifetimeMarkers)
57  return false;
58 
59  // Sanitizers may use markers.
60  if (CGOpts.SanitizeAddressUseAfterScope ||
61  LangOpts.Sanitize.has(SanitizerKind::HWAddress) ||
62  LangOpts.Sanitize.has(SanitizerKind::Memory))
63  return true;
64 
65  // For now, only in optimized builds.
66  return CGOpts.OptimizationLevel != 0;
67 }
68 
69 CodeGenFunction::CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext)
70  : CodeGenTypeCache(cgm), CGM(cgm), Target(cgm.getTarget()),
71  Builder(cgm, cgm.getModule().getContext(), llvm::ConstantFolder(),
72  CGBuilderInserterTy(this)),
73  SanOpts(CGM.getLangOpts().Sanitize), CurFPFeatures(CGM.getLangOpts()),
74  DebugInfo(CGM.getModuleDebugInfo()), PGO(cgm),
75  ShouldEmitLifetimeMarkers(
76  shouldEmitLifetimeMarkers(CGM.getCodeGenOpts(), CGM.getLangOpts())) {
77  if (!suppressNewContext)
79  EHStack.setCGF(this);
80 
82 }
83 
85  assert(LifetimeExtendedCleanupStack.empty() && "failed to emit a cleanup");
86 
87  if (getLangOpts().OpenMP && CurFn)
89 
90  // If we have an OpenMPIRBuilder we want to finalize functions (incl.
91  // outlining etc) at some point. Doing it once the function codegen is done
92  // seems to be a reasonable spot. We do it here, as opposed to the deletion
93  // time of the CodeGenModule, because we have to ensure the IR has not yet
94  // been "emitted" to the outside, thus, modifications are still sensible.
95  if (CGM.getLangOpts().OpenMPIRBuilder && CurFn)
97 }
98 
99 // Map the LangOption for exception behavior into
100 // the corresponding enum in the IR.
101 llvm::fp::ExceptionBehavior
103 
104  switch (Kind) {
105  case LangOptions::FPE_Ignore: return llvm::fp::ebIgnore;
106  case LangOptions::FPE_MayTrap: return llvm::fp::ebMayTrap;
107  case LangOptions::FPE_Strict: return llvm::fp::ebStrict;
108  }
109  llvm_unreachable("Unsupported FP Exception Behavior");
110 }
111 
113  llvm::FastMathFlags FMF;
114  FMF.setAllowReassoc(FPFeatures.getAllowFPReassociate());
115  FMF.setNoNaNs(FPFeatures.getNoHonorNaNs());
116  FMF.setNoInfs(FPFeatures.getNoHonorInfs());
117  FMF.setNoSignedZeros(FPFeatures.getNoSignedZero());
118  FMF.setAllowReciprocal(FPFeatures.getAllowReciprocal());
119  FMF.setApproxFunc(FPFeatures.getAllowApproxFunc());
120  FMF.setAllowContract(FPFeatures.allowFPContractAcrossStatement());
121  Builder.setFastMathFlags(FMF);
122 }
123 
125  const Expr *E)
126  : CGF(CGF) {
127  ConstructorHelper(E->getFPFeaturesInEffect(CGF.getLangOpts()));
128 }
129 
131  FPOptions FPFeatures)
132  : CGF(CGF) {
133  ConstructorHelper(FPFeatures);
134 }
135 
136 void CodeGenFunction::CGFPOptionsRAII::ConstructorHelper(FPOptions FPFeatures) {
137  OldFPFeatures = CGF.CurFPFeatures;
138  CGF.CurFPFeatures = FPFeatures;
139 
140  OldExcept = CGF.Builder.getDefaultConstrainedExcept();
141  OldRounding = CGF.Builder.getDefaultConstrainedRounding();
142 
143  if (OldFPFeatures == FPFeatures)
144  return;
145 
146  FMFGuard.emplace(CGF.Builder);
147 
148  llvm::RoundingMode NewRoundingBehavior =
149  static_cast<llvm::RoundingMode>(FPFeatures.getRoundingMode());
150  CGF.Builder.setDefaultConstrainedRounding(NewRoundingBehavior);
151  auto NewExceptionBehavior =
153  FPFeatures.getFPExceptionMode()));
154  CGF.Builder.setDefaultConstrainedExcept(NewExceptionBehavior);
155 
156  CGF.SetFastMathFlags(FPFeatures);
157 
158  assert((CGF.CurFuncDecl == nullptr || CGF.Builder.getIsFPConstrained() ||
159  isa<CXXConstructorDecl>(CGF.CurFuncDecl) ||
160  isa<CXXDestructorDecl>(CGF.CurFuncDecl) ||
161  (NewExceptionBehavior == llvm::fp::ebIgnore &&
162  NewRoundingBehavior == llvm::RoundingMode::NearestTiesToEven)) &&
163  "FPConstrained should be enabled on entire function");
164 
165  auto mergeFnAttrValue = [&](StringRef Name, bool Value) {
166  auto OldValue =
167  CGF.CurFn->getFnAttribute(Name).getValueAsBool();
168  auto NewValue = OldValue & Value;
169  if (OldValue != NewValue)
170  CGF.CurFn->addFnAttr(Name, llvm::toStringRef(NewValue));
171  };
172  mergeFnAttrValue("no-infs-fp-math", FPFeatures.getNoHonorInfs());
173  mergeFnAttrValue("no-nans-fp-math", FPFeatures.getNoHonorNaNs());
174  mergeFnAttrValue("no-signed-zeros-fp-math", FPFeatures.getNoSignedZero());
175  mergeFnAttrValue("unsafe-fp-math", FPFeatures.getAllowFPReassociate() &&
176  FPFeatures.getAllowReciprocal() &&
177  FPFeatures.getAllowApproxFunc() &&
178  FPFeatures.getNoSignedZero());
179 }
180 
182  CGF.CurFPFeatures = OldFPFeatures;
183  CGF.Builder.setDefaultConstrainedExcept(OldExcept);
184  CGF.Builder.setDefaultConstrainedRounding(OldRounding);
185 }
186 
188  LValueBaseInfo BaseInfo;
189  TBAAAccessInfo TBAAInfo;
190  CharUnits Alignment = CGM.getNaturalTypeAlignment(T, &BaseInfo, &TBAAInfo);
191  Address Addr(V, ConvertTypeForMem(T), Alignment);
192  return LValue::MakeAddr(Addr, T, getContext(), BaseInfo, TBAAInfo);
193 }
194 
195 /// Given a value of type T* that may not be to a complete object,
196 /// construct an l-value with the natural pointee alignment of T.
197 LValue
199  LValueBaseInfo BaseInfo;
200  TBAAAccessInfo TBAAInfo;
201  CharUnits Align = CGM.getNaturalTypeAlignment(T, &BaseInfo, &TBAAInfo,
202  /* forPointeeType= */ true);
203  Address Addr(V, ConvertTypeForMem(T), Align);
204  return MakeAddrLValue(Addr, T, BaseInfo, TBAAInfo);
205 }
206 
207 
209  return CGM.getTypes().ConvertTypeForMem(T);
210 }
211 
213  return CGM.getTypes().ConvertType(T);
214 }
215 
217  type = type.getCanonicalType();
218  while (true) {
219  switch (type->getTypeClass()) {
220 #define TYPE(name, parent)
221 #define ABSTRACT_TYPE(name, parent)
222 #define NON_CANONICAL_TYPE(name, parent) case Type::name:
223 #define DEPENDENT_TYPE(name, parent) case Type::name:
224 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(name, parent) case Type::name:
225 #include "clang/AST/TypeNodes.inc"
226  llvm_unreachable("non-canonical or dependent type in IR-generation");
227 
228  case Type::Auto:
229  case Type::DeducedTemplateSpecialization:
230  llvm_unreachable("undeduced type in IR-generation");
231 
232  // Various scalar types.
233  case Type::Builtin:
234  case Type::Pointer:
235  case Type::BlockPointer:
236  case Type::LValueReference:
237  case Type::RValueReference:
238  case Type::MemberPointer:
239  case Type::Vector:
240  case Type::ExtVector:
241  case Type::ConstantMatrix:
242  case Type::FunctionProto:
243  case Type::FunctionNoProto:
244  case Type::Enum:
245  case Type::ObjCObjectPointer:
246  case Type::Pipe:
247  case Type::BitInt:
248  return TEK_Scalar;
249 
250  // Complexes.
251  case Type::Complex:
252  return TEK_Complex;
253 
254  // Arrays, records, and Objective-C objects.
255  case Type::ConstantArray:
256  case Type::IncompleteArray:
257  case Type::VariableArray:
258  case Type::Record:
259  case Type::ObjCObject:
260  case Type::ObjCInterface:
261  return TEK_Aggregate;
262 
263  // We operate on atomic values according to their underlying type.
264  case Type::Atomic:
265  type = cast<AtomicType>(type)->getValueType();
266  continue;
267  }
268  llvm_unreachable("unknown type kind!");
269  }
270 }
271 
273  // For cleanliness, we try to avoid emitting the return block for
274  // simple cases.
275  llvm::BasicBlock *CurBB = Builder.GetInsertBlock();
276 
277  if (CurBB) {
278  assert(!CurBB->getTerminator() && "Unexpected terminated block.");
279 
280  // We have a valid insert point, reuse it if it is empty or there are no
281  // explicit jumps to the return block.
282  if (CurBB->empty() || ReturnBlock.getBlock()->use_empty()) {
283  ReturnBlock.getBlock()->replaceAllUsesWith(CurBB);
284  delete ReturnBlock.getBlock();
285  ReturnBlock = JumpDest();
286  } else
288  return llvm::DebugLoc();
289  }
290 
291  // Otherwise, if the return block is the target of a single direct
292  // branch then we can just put the code in that block instead. This
293  // cleans up functions which started with a unified return block.
294  if (ReturnBlock.getBlock()->hasOneUse()) {
295  llvm::BranchInst *BI =
296  dyn_cast<llvm::BranchInst>(*ReturnBlock.getBlock()->user_begin());
297  if (BI && BI->isUnconditional() &&
298  BI->getSuccessor(0) == ReturnBlock.getBlock()) {
299  // Record/return the DebugLoc of the simple 'return' expression to be used
300  // later by the actual 'ret' instruction.
301  llvm::DebugLoc Loc = BI->getDebugLoc();
302  Builder.SetInsertPoint(BI->getParent());
303  BI->eraseFromParent();
304  delete ReturnBlock.getBlock();
305  ReturnBlock = JumpDest();
306  return Loc;
307  }
308  }
309 
310  // FIXME: We are at an unreachable point, there is no reason to emit the block
311  // unless it has uses. However, we still need a place to put the debug
312  // region.end for now.
313 
315  return llvm::DebugLoc();
316 }
317 
318 static void EmitIfUsed(CodeGenFunction &CGF, llvm::BasicBlock *BB) {
319  if (!BB) return;
320  if (!BB->use_empty())
321  return CGF.CurFn->getBasicBlockList().push_back(BB);
322  delete BB;
323 }
324 
326  assert(BreakContinueStack.empty() &&
327  "mismatched push/pop in break/continue stack!");
328 
329  bool OnlySimpleReturnStmts = NumSimpleReturnExprs > 0
330  && NumSimpleReturnExprs == NumReturnExprs
331  && ReturnBlock.getBlock()->use_empty();
332  // Usually the return expression is evaluated before the cleanup
333  // code. If the function contains only a simple return statement,
334  // such as a constant, the location before the cleanup code becomes
335  // the last useful breakpoint in the function, because the simple
336  // return expression will be evaluated after the cleanup code. To be
337  // safe, set the debug location for cleanup code to the location of
338  // the return statement. Otherwise the cleanup code should be at the
339  // end of the function's lexical scope.
340  //
341  // If there are multiple branches to the return block, the branch
342  // instructions will get the location of the return statements and
343  // all will be fine.
344  if (CGDebugInfo *DI = getDebugInfo()) {
345  if (OnlySimpleReturnStmts)
346  DI->EmitLocation(Builder, LastStopPoint);
347  else
348  DI->EmitLocation(Builder, EndLoc);
349  }
350 
351  // Pop any cleanups that might have been associated with the
352  // parameters. Do this in whatever block we're currently in; it's
353  // important to do this before we enter the return block or return
354  // edges will be *really* confused.
355  bool HasCleanups = EHStack.stable_begin() != PrologueCleanupDepth;
356  bool HasOnlyLifetimeMarkers =
358  bool EmitRetDbgLoc = !HasCleanups || HasOnlyLifetimeMarkers;
359  if (HasCleanups) {
360  // Make sure the line table doesn't jump back into the body for
361  // the ret after it's been at EndLoc.
363  if (CGDebugInfo *DI = getDebugInfo()) {
364  if (OnlySimpleReturnStmts)
365  DI->EmitLocation(Builder, EndLoc);
366  else
367  // We may not have a valid end location. Try to apply it anyway, and
368  // fall back to an artificial location if needed.
370  }
371 
373  }
374 
375  // Emit function epilog (to return).
376  llvm::DebugLoc Loc = EmitReturnBlock();
377 
378  if (ShouldInstrumentFunction()) {
379  if (CGM.getCodeGenOpts().InstrumentFunctions)
380  CurFn->addFnAttr("instrument-function-exit", "__cyg_profile_func_exit");
381  if (CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining)
382  CurFn->addFnAttr("instrument-function-exit-inlined",
383  "__cyg_profile_func_exit");
384  }
385 
387  CurFn->addFnAttr(llvm::Attribute::DisableSanitizerInstrumentation);
388 
389  // Emit debug descriptor for function end.
390  if (CGDebugInfo *DI = getDebugInfo())
391  DI->EmitFunctionEnd(Builder, CurFn);
392 
393  // Reset the debug location to that of the simple 'return' expression, if any
394  // rather than that of the end of the function's scope '}'.
395  ApplyDebugLocation AL(*this, Loc);
396  EmitFunctionEpilog(*CurFnInfo, EmitRetDbgLoc, EndLoc);
398 
399  assert(EHStack.empty() &&
400  "did not remove all scopes from cleanup stack!");
401 
402  // If someone did an indirect goto, emit the indirect goto block at the end of
403  // the function.
404  if (IndirectBranch) {
405  EmitBlock(IndirectBranch->getParent());
406  Builder.ClearInsertionPoint();
407  }
408 
409  // If some of our locals escaped, insert a call to llvm.localescape in the
410  // entry block.
411  if (!EscapedLocals.empty()) {
412  // Invert the map from local to index into a simple vector. There should be
413  // no holes.
415  EscapeArgs.resize(EscapedLocals.size());
416  for (auto &Pair : EscapedLocals)
417  EscapeArgs[Pair.second] = Pair.first;
418  llvm::Function *FrameEscapeFn = llvm::Intrinsic::getDeclaration(
419  &CGM.getModule(), llvm::Intrinsic::localescape);
420  CGBuilderTy(*this, AllocaInsertPt).CreateCall(FrameEscapeFn, EscapeArgs);
421  }
422 
423  // Remove the AllocaInsertPt instruction, which is just a convenience for us.
424  llvm::Instruction *Ptr = AllocaInsertPt;
425  AllocaInsertPt = nullptr;
426  Ptr->eraseFromParent();
427 
428  // PostAllocaInsertPt, if created, was lazily created when it was required,
429  // remove it now since it was just created for our own convenience.
430  if (PostAllocaInsertPt) {
431  llvm::Instruction *PostPtr = PostAllocaInsertPt;
432  PostAllocaInsertPt = nullptr;
433  PostPtr->eraseFromParent();
434  }
435 
436  // If someone took the address of a label but never did an indirect goto, we
437  // made a zero entry PHI node, which is illegal, zap it now.
438  if (IndirectBranch) {
439  llvm::PHINode *PN = cast<llvm::PHINode>(IndirectBranch->getAddress());
440  if (PN->getNumIncomingValues() == 0) {
441  PN->replaceAllUsesWith(llvm::UndefValue::get(PN->getType()));
442  PN->eraseFromParent();
443  }
444  }
445 
446  EmitIfUsed(*this, EHResumeBlock);
447  EmitIfUsed(*this, TerminateLandingPad);
448  EmitIfUsed(*this, TerminateHandler);
449  EmitIfUsed(*this, UnreachableBlock);
450 
451  for (const auto &FuncletAndParent : TerminateFunclets)
452  EmitIfUsed(*this, FuncletAndParent.second);
453 
454  if (CGM.getCodeGenOpts().EmitDeclMetadata)
455  EmitDeclMetadata();
456 
457  for (const auto &R : DeferredReplacements) {
458  if (llvm::Value *Old = R.first) {
459  Old->replaceAllUsesWith(R.second);
460  cast<llvm::Instruction>(Old)->eraseFromParent();
461  }
462  }
463  DeferredReplacements.clear();
464 
465  // Eliminate CleanupDestSlot alloca by replacing it with SSA values and
466  // PHIs if the current function is a coroutine. We don't do it for all
467  // functions as it may result in slight increase in numbers of instructions
468  // if compiled with no optimizations. We do it for coroutine as the lifetime
469  // of CleanupDestSlot alloca make correct coroutine frame building very
470  // difficult.
472  llvm::DominatorTree DT(*CurFn);
473  llvm::PromoteMemToReg(
474  cast<llvm::AllocaInst>(NormalCleanupDest.getPointer()), DT);
476  }
477 
478  // Scan function arguments for vector width.
479  for (llvm::Argument &A : CurFn->args())
480  if (auto *VT = dyn_cast<llvm::VectorType>(A.getType()))
481  LargestVectorWidth =
482  std::max((uint64_t)LargestVectorWidth,
483  VT->getPrimitiveSizeInBits().getKnownMinSize());
484 
485  // Update vector width based on return type.
486  if (auto *VT = dyn_cast<llvm::VectorType>(CurFn->getReturnType()))
487  LargestVectorWidth =
488  std::max((uint64_t)LargestVectorWidth,
489  VT->getPrimitiveSizeInBits().getKnownMinSize());
490 
491  // Add the required-vector-width attribute. This contains the max width from:
492  // 1. min-vector-width attribute used in the source program.
493  // 2. Any builtins used that have a vector width specified.
494  // 3. Values passed in and out of inline assembly.
495  // 4. Width of vector arguments and return types for this function.
496  // 5. Width of vector aguments and return types for functions called by this
497  // function.
498  CurFn->addFnAttr("min-legal-vector-width", llvm::utostr(LargestVectorWidth));
499 
500  // Add vscale_range attribute if appropriate.
503  if (VScaleRange) {
504  CurFn->addFnAttr(llvm::Attribute::getWithVScaleRangeArgs(
505  getLLVMContext(), VScaleRange.getValue().first,
506  VScaleRange.getValue().second));
507  }
508 
509  // If we generated an unreachable return block, delete it now.
510  if (ReturnBlock.isValid() && ReturnBlock.getBlock()->use_empty()) {
511  Builder.ClearInsertionPoint();
512  ReturnBlock.getBlock()->eraseFromParent();
513  }
514  if (ReturnValue.isValid()) {
515  auto *RetAlloca = dyn_cast<llvm::AllocaInst>(ReturnValue.getPointer());
516  if (RetAlloca && RetAlloca->use_empty()) {
517  RetAlloca->eraseFromParent();
519  }
520  }
521 }
522 
523 /// ShouldInstrumentFunction - Return true if the current function should be
524 /// instrumented with __cyg_profile_func_* calls
526  if (!CGM.getCodeGenOpts().InstrumentFunctions &&
527  !CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining &&
528  !CGM.getCodeGenOpts().InstrumentFunctionEntryBare)
529  return false;
530  if (!CurFuncDecl || CurFuncDecl->hasAttr<NoInstrumentFunctionAttr>())
531  return false;
532  return true;
533 }
534 
536  if (!CurFuncDecl)
537  return false;
538  return CurFuncDecl->hasAttr<DisableSanitizerInstrumentationAttr>();
539 }
540 
541 /// ShouldXRayInstrument - Return true if the current function should be
542 /// instrumented with XRay nop sleds.
544  return CGM.getCodeGenOpts().XRayInstrumentFunctions;
545 }
546 
547 /// AlwaysEmitXRayCustomEvents - Return true if we should emit IR for calls to
548 /// the __xray_customevent(...) builtin calls, when doing XRay instrumentation.
550  return CGM.getCodeGenOpts().XRayInstrumentFunctions &&
551  (CGM.getCodeGenOpts().XRayAlwaysEmitCustomEvents ||
554 }
555 
557  return CGM.getCodeGenOpts().XRayInstrumentFunctions &&
558  (CGM.getCodeGenOpts().XRayAlwaysEmitTypedEvents ||
561 }
562 
563 llvm::Constant *
565  llvm::Constant *Addr) {
566  // Addresses stored in prologue data can't require run-time fixups and must
567  // be PC-relative. Run-time fixups are undesirable because they necessitate
568  // writable text segments, which are unsafe. And absolute addresses are
569  // undesirable because they break PIE mode.
570 
571  // Add a layer of indirection through a private global. Taking its address
572  // won't result in a run-time fixup, even if Addr has linkonce_odr linkage.
573  auto *GV = new llvm::GlobalVariable(CGM.getModule(), Addr->getType(),
574  /*isConstant=*/true,
575  llvm::GlobalValue::PrivateLinkage, Addr);
576 
577  // Create a PC-relative address.
578  auto *GOTAsInt = llvm::ConstantExpr::getPtrToInt(GV, IntPtrTy);
579  auto *FuncAsInt = llvm::ConstantExpr::getPtrToInt(F, IntPtrTy);
580  auto *PCRelAsInt = llvm::ConstantExpr::getSub(GOTAsInt, FuncAsInt);
581  return (IntPtrTy == Int32Ty)
582  ? PCRelAsInt
583  : llvm::ConstantExpr::getTrunc(PCRelAsInt, Int32Ty);
584 }
585 
586 llvm::Value *
588  llvm::Value *EncodedAddr) {
589  // Reconstruct the address of the global.
590  auto *PCRelAsInt = Builder.CreateSExt(EncodedAddr, IntPtrTy);
591  auto *FuncAsInt = Builder.CreatePtrToInt(F, IntPtrTy, "func_addr.int");
592  auto *GOTAsInt = Builder.CreateAdd(PCRelAsInt, FuncAsInt, "global_addr.int");
593  auto *GOTAddr = Builder.CreateIntToPtr(GOTAsInt, Int8PtrPtrTy, "global_addr");
594 
595  // Load the original pointer through the global.
596  return Builder.CreateLoad(Address(GOTAddr, getPointerAlign()),
597  "decoded_addr");
598 }
599 
600 void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD,
601  llvm::Function *Fn)
602 {
603  if (!FD->hasAttr<OpenCLKernelAttr>())
604  return;
605 
606  llvm::LLVMContext &Context = getLLVMContext();
607 
608  CGM.GenOpenCLArgMetadata(Fn, FD, this);
609 
610  if (const VecTypeHintAttr *A = FD->getAttr<VecTypeHintAttr>()) {
611  QualType HintQTy = A->getTypeHint();
612  const ExtVectorType *HintEltQTy = HintQTy->getAs<ExtVectorType>();
613  bool IsSignedInteger =
614  HintQTy->isSignedIntegerType() ||
615  (HintEltQTy && HintEltQTy->getElementType()->isSignedIntegerType());
616  llvm::Metadata *AttrMDArgs[] = {
617  llvm::ConstantAsMetadata::get(llvm::UndefValue::get(
618  CGM.getTypes().ConvertType(A->getTypeHint()))),
619  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
620  llvm::IntegerType::get(Context, 32),
621  llvm::APInt(32, (uint64_t)(IsSignedInteger ? 1 : 0))))};
622  Fn->setMetadata("vec_type_hint", llvm::MDNode::get(Context, AttrMDArgs));
623  }
624 
625  if (const WorkGroupSizeHintAttr *A = FD->getAttr<WorkGroupSizeHintAttr>()) {
626  llvm::Metadata *AttrMDArgs[] = {
627  llvm::ConstantAsMetadata::get(Builder.getInt32(A->getXDim())),
628  llvm::ConstantAsMetadata::get(Builder.getInt32(A->getYDim())),
629  llvm::ConstantAsMetadata::get(Builder.getInt32(A->getZDim()))};
630  Fn->setMetadata("work_group_size_hint", llvm::MDNode::get(Context, AttrMDArgs));
631  }
632 
633  if (const ReqdWorkGroupSizeAttr *A = FD->getAttr<ReqdWorkGroupSizeAttr>()) {
634  llvm::Metadata *AttrMDArgs[] = {
635  llvm::ConstantAsMetadata::get(Builder.getInt32(A->getXDim())),
636  llvm::ConstantAsMetadata::get(Builder.getInt32(A->getYDim())),
637  llvm::ConstantAsMetadata::get(Builder.getInt32(A->getZDim()))};
638  Fn->setMetadata("reqd_work_group_size", llvm::MDNode::get(Context, AttrMDArgs));
639  }
640 
641  if (const OpenCLIntelReqdSubGroupSizeAttr *A =
642  FD->getAttr<OpenCLIntelReqdSubGroupSizeAttr>()) {
643  llvm::Metadata *AttrMDArgs[] = {
644  llvm::ConstantAsMetadata::get(Builder.getInt32(A->getSubGroupSize()))};
645  Fn->setMetadata("intel_reqd_sub_group_size",
646  llvm::MDNode::get(Context, AttrMDArgs));
647  }
648 }
649 
650 /// Determine whether the function F ends with a return stmt.
651 static bool endsWithReturn(const Decl* F) {
652  const Stmt *Body = nullptr;
653  if (auto *FD = dyn_cast_or_null<FunctionDecl>(F))
654  Body = FD->getBody();
655  else if (auto *OMD = dyn_cast_or_null<ObjCMethodDecl>(F))
656  Body = OMD->getBody();
657 
658  if (auto *CS = dyn_cast_or_null<CompoundStmt>(Body)) {
659  auto LastStmt = CS->body_rbegin();
660  if (LastStmt != CS->body_rend())
661  return isa<ReturnStmt>(*LastStmt);
662  }
663  return false;
664 }
665 
667  if (SanOpts.has(SanitizerKind::Thread)) {
668  Fn->addFnAttr("sanitize_thread_no_checking_at_run_time");
669  Fn->removeFnAttr(llvm::Attribute::SanitizeThread);
670  }
671 }
672 
673 /// Check if the return value of this function requires sanitization.
674 bool CodeGenFunction::requiresReturnValueCheck() const {
675  return requiresReturnValueNullabilityCheck() ||
676  (SanOpts.has(SanitizerKind::ReturnsNonnullAttribute) && CurCodeDecl &&
677  CurCodeDecl->getAttr<ReturnsNonNullAttr>());
678 }
679 
680 static bool matchesStlAllocatorFn(const Decl *D, const ASTContext &Ctx) {
681  auto *MD = dyn_cast_or_null<CXXMethodDecl>(D);
682  if (!MD || !MD->getDeclName().getAsIdentifierInfo() ||
683  !MD->getDeclName().getAsIdentifierInfo()->isStr("allocate") ||
684  (MD->getNumParams() != 1 && MD->getNumParams() != 2))
685  return false;
686 
687  if (MD->parameters()[0]->getType().getCanonicalType() != Ctx.getSizeType())
688  return false;
689 
690  if (MD->getNumParams() == 2) {
691  auto *PT = MD->parameters()[1]->getType()->getAs<PointerType>();
692  if (!PT || !PT->isVoidPointerType() ||
693  !PT->getPointeeType().isConstQualified())
694  return false;
695  }
696 
697  return true;
698 }
699 
700 /// Return the UBSan prologue signature for \p FD if one is available.
701 static llvm::Constant *getPrologueSignature(CodeGenModule &CGM,
702  const FunctionDecl *FD) {
703  if (const auto *MD = dyn_cast<CXXMethodDecl>(FD))
704  if (!MD->isStatic())
705  return nullptr;
707 }
708 
710  llvm::Function *Fn,
711  const CGFunctionInfo &FnInfo,
712  const FunctionArgList &Args,
713  SourceLocation Loc,
714  SourceLocation StartLoc) {
715  assert(!CurFn &&
716  "Do not use a CodeGenFunction object for more than one function");
717 
718  const Decl *D = GD.getDecl();
719 
720  DidCallStackSave = false;
721  CurCodeDecl = D;
722  const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
723  if (FD && FD->usesSEHTry())
724  CurSEHParent = FD;
725  CurFuncDecl = (D ? D->getNonClosureContext() : nullptr);
726  FnRetTy = RetTy;
727  CurFn = Fn;
728  CurFnInfo = &FnInfo;
729  assert(CurFn->isDeclaration() && "Function already has body?");
730 
731  // If this function is ignored for any of the enabled sanitizers,
732  // disable the sanitizer for the function.
733  do {
734 #define SANITIZER(NAME, ID) \
735  if (SanOpts.empty()) \
736  break; \
737  if (SanOpts.has(SanitizerKind::ID)) \
738  if (CGM.isInNoSanitizeList(SanitizerKind::ID, Fn, Loc)) \
739  SanOpts.set(SanitizerKind::ID, false);
740 
741 #include "clang/Basic/Sanitizers.def"
742 #undef SANITIZER
743  } while (false);
744 
745  if (D) {
746  bool NoSanitizeCoverage = false;
747 
748  for (auto Attr : D->specific_attrs<NoSanitizeAttr>()) {
749  // Apply the no_sanitize* attributes to SanOpts.
750  SanitizerMask mask = Attr->getMask();
751  SanOpts.Mask &= ~mask;
752  if (mask & SanitizerKind::Address)
753  SanOpts.set(SanitizerKind::KernelAddress, false);
754  if (mask & SanitizerKind::KernelAddress)
755  SanOpts.set(SanitizerKind::Address, false);
756  if (mask & SanitizerKind::HWAddress)
757  SanOpts.set(SanitizerKind::KernelHWAddress, false);
758  if (mask & SanitizerKind::KernelHWAddress)
759  SanOpts.set(SanitizerKind::HWAddress, false);
760 
761  // SanitizeCoverage is not handled by SanOpts.
762  if (Attr->hasCoverage())
763  NoSanitizeCoverage = true;
764  }
765 
766  if (NoSanitizeCoverage && CGM.getCodeGenOpts().hasSanitizeCoverage())
767  Fn->addFnAttr(llvm::Attribute::NoSanitizeCoverage);
768  }
769 
770  // Apply sanitizer attributes to the function.
771  if (SanOpts.hasOneOf(SanitizerKind::Address | SanitizerKind::KernelAddress))
772  Fn->addFnAttr(llvm::Attribute::SanitizeAddress);
773  if (SanOpts.hasOneOf(SanitizerKind::HWAddress | SanitizerKind::KernelHWAddress))
774  Fn->addFnAttr(llvm::Attribute::SanitizeHWAddress);
775  if (SanOpts.has(SanitizerKind::MemTag))
776  Fn->addFnAttr(llvm::Attribute::SanitizeMemTag);
777  if (SanOpts.has(SanitizerKind::Thread))
778  Fn->addFnAttr(llvm::Attribute::SanitizeThread);
779  if (SanOpts.hasOneOf(SanitizerKind::Memory | SanitizerKind::KernelMemory))
780  Fn->addFnAttr(llvm::Attribute::SanitizeMemory);
781  if (SanOpts.has(SanitizerKind::SafeStack))
782  Fn->addFnAttr(llvm::Attribute::SafeStack);
783  if (SanOpts.has(SanitizerKind::ShadowCallStack))
784  Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
785 
786  // Apply fuzzing attribute to the function.
787  if (SanOpts.hasOneOf(SanitizerKind::Fuzzer | SanitizerKind::FuzzerNoLink))
788  Fn->addFnAttr(llvm::Attribute::OptForFuzzing);
789 
790  // Ignore TSan memory acesses from within ObjC/ObjC++ dealloc, initialize,
791  // .cxx_destruct, __destroy_helper_block_ and all of their calees at run time.
792  if (SanOpts.has(SanitizerKind::Thread)) {
793  if (const auto *OMD = dyn_cast_or_null<ObjCMethodDecl>(D)) {
794  IdentifierInfo *II = OMD->getSelector().getIdentifierInfoForSlot(0);
795  if (OMD->getMethodFamily() == OMF_dealloc ||
796  OMD->getMethodFamily() == OMF_initialize ||
797  (OMD->getSelector().isUnarySelector() && II->isStr(".cxx_destruct"))) {
799  }
800  }
801  }
802 
803  // Ignore unrelated casts in STL allocate() since the allocator must cast
804  // from void* to T* before object initialization completes. Don't match on the
805  // namespace because not all allocators are in std::
806  if (D && SanOpts.has(SanitizerKind::CFIUnrelatedCast)) {
808  SanOpts.Mask &= ~SanitizerKind::CFIUnrelatedCast;
809  }
810 
811  // Ignore null checks in coroutine functions since the coroutines passes
812  // are not aware of how to move the extra UBSan instructions across the split
813  // coroutine boundaries.
814  if (D && SanOpts.has(SanitizerKind::Null))
815  if (FD && FD->getBody() &&
816  FD->getBody()->getStmtClass() == Stmt::CoroutineBodyStmtClass)
818 
819  // Apply xray attributes to the function (as a string, for now)
820  bool AlwaysXRayAttr = false;
821  if (const auto *XRayAttr = D ? D->getAttr<XRayInstrumentAttr>() : nullptr) {
826  if (XRayAttr->alwaysXRayInstrument() && ShouldXRayInstrumentFunction()) {
827  Fn->addFnAttr("function-instrument", "xray-always");
828  AlwaysXRayAttr = true;
829  }
830  if (XRayAttr->neverXRayInstrument())
831  Fn->addFnAttr("function-instrument", "xray-never");
832  if (const auto *LogArgs = D->getAttr<XRayLogArgsAttr>())
834  Fn->addFnAttr("xray-log-args",
835  llvm::utostr(LogArgs->getArgumentCount()));
836  }
837  } else {
839  Fn->addFnAttr(
840  "xray-instruction-threshold",
841  llvm::itostr(CGM.getCodeGenOpts().XRayInstructionThreshold));
842  }
843 
845  if (CGM.getCodeGenOpts().XRayIgnoreLoops)
846  Fn->addFnAttr("xray-ignore-loops");
847 
850  Fn->addFnAttr("xray-skip-exit");
851 
854  Fn->addFnAttr("xray-skip-entry");
855 
856  auto FuncGroups = CGM.getCodeGenOpts().XRayTotalFunctionGroups;
857  if (FuncGroups > 1) {
858  auto FuncName = llvm::makeArrayRef<uint8_t>(
859  CurFn->getName().bytes_begin(), CurFn->getName().bytes_end());
860  auto Group = crc32(FuncName) % FuncGroups;
861  if (Group != CGM.getCodeGenOpts().XRaySelectedFunctionGroup &&
862  !AlwaysXRayAttr)
863  Fn->addFnAttr("function-instrument", "xray-never");
864  }
865  }
866 
867  if (CGM.getCodeGenOpts().getProfileInstr() != CodeGenOptions::ProfileNone)
868  if (CGM.isProfileInstrExcluded(Fn, Loc))
869  Fn->addFnAttr(llvm::Attribute::NoProfile);
870 
871  unsigned Count, Offset;
872  if (const auto *Attr =
873  D ? D->getAttr<PatchableFunctionEntryAttr>() : nullptr) {
874  Count = Attr->getCount();
875  Offset = Attr->getOffset();
876  } else {
877  Count = CGM.getCodeGenOpts().PatchableFunctionEntryCount;
878  Offset = CGM.getCodeGenOpts().PatchableFunctionEntryOffset;
879  }
880  if (Count && Offset <= Count) {
881  Fn->addFnAttr("patchable-function-entry", std::to_string(Count - Offset));
882  if (Offset)
883  Fn->addFnAttr("patchable-function-prefix", std::to_string(Offset));
884  }
885  // Instruct that functions for COFF/CodeView targets should start with a
886  // patchable instruction, but only on x86/x64. Don't forward this to ARM/ARM64
887  // backends as they don't need it -- instructions on these architectures are
888  // always atomically patchable at runtime.
889  if (CGM.getCodeGenOpts().HotPatch &&
890  getContext().getTargetInfo().getTriple().isX86())
891  Fn->addFnAttr("patchable-function", "prologue-short-redirect");
892 
893  // Add no-jump-tables value.
894  if (CGM.getCodeGenOpts().NoUseJumpTables)
895  Fn->addFnAttr("no-jump-tables", "true");
896 
897  // Add no-inline-line-tables value.
898  if (CGM.getCodeGenOpts().NoInlineLineTables)
899  Fn->addFnAttr("no-inline-line-tables");
900 
901  // Add profile-sample-accurate value.
902  if (CGM.getCodeGenOpts().ProfileSampleAccurate)
903  Fn->addFnAttr("profile-sample-accurate");
904 
905  if (!CGM.getCodeGenOpts().SampleProfileFile.empty())
906  Fn->addFnAttr("use-sample-profile");
907 
908  if (D && D->hasAttr<CFICanonicalJumpTableAttr>())
909  Fn->addFnAttr("cfi-canonical-jump-table");
910 
911  if (D && D->hasAttr<NoProfileFunctionAttr>())
912  Fn->addFnAttr(llvm::Attribute::NoProfile);
913 
914  if (FD && getLangOpts().OpenCL) {
915  // Add metadata for a kernel function.
916  EmitOpenCLKernelMetadata(FD, Fn);
917  }
918 
919  // If we are checking function types, emit a function type signature as
920  // prologue data.
921  if (FD && getLangOpts().CPlusPlus && SanOpts.has(SanitizerKind::Function)) {
922  if (llvm::Constant *PrologueSig = getPrologueSignature(CGM, FD)) {
923  // Remove any (C++17) exception specifications, to allow calling e.g. a
924  // noexcept function through a non-noexcept pointer.
926  FD->getType(), EST_None);
927  llvm::Constant *FTRTTIConst =
928  CGM.GetAddrOfRTTIDescriptor(ProtoTy, /*ForEH=*/true);
929  llvm::Constant *FTRTTIConstEncoded =
930  EncodeAddrForUseInPrologue(Fn, FTRTTIConst);
931  llvm::Constant *PrologueStructElems[] = {PrologueSig, FTRTTIConstEncoded};
932  llvm::Constant *PrologueStructConst =
933  llvm::ConstantStruct::getAnon(PrologueStructElems, /*Packed=*/true);
934  Fn->setPrologueData(PrologueStructConst);
935  }
936  }
937 
938  // If we're checking nullability, we need to know whether we can check the
939  // return value. Initialize the flag to 'true' and refine it in EmitParmDecl.
940  if (SanOpts.has(SanitizerKind::NullabilityReturn)) {
943  if (!(SanOpts.has(SanitizerKind::ReturnsNonnullAttribute) &&
944  CurCodeDecl && CurCodeDecl->getAttr<ReturnsNonNullAttr>()))
945  RetValNullabilityPrecondition =
946  llvm::ConstantInt::getTrue(getLLVMContext());
947  }
948  }
949 
950  // If we're in C++ mode and the function name is "main", it is guaranteed
951  // to be norecurse by the standard (3.6.1.3 "The function main shall not be
952  // used within a program").
953  //
954  // OpenCL C 2.0 v2.2-11 s6.9.i:
955  // Recursion is not supported.
956  //
957  // SYCL v1.2.1 s3.10:
958  // kernels cannot include RTTI information, exception classes,
959  // recursive code, virtual functions or make use of C++ libraries that
960  // are not compiled for the device.
961  if (FD && ((getLangOpts().CPlusPlus && FD->isMain()) ||
962  getLangOpts().OpenCL || getLangOpts().SYCLIsDevice ||
963  (getLangOpts().CUDA && FD->hasAttr<CUDAGlobalAttr>())))
964  Fn->addFnAttr(llvm::Attribute::NoRecurse);
965 
966  llvm::RoundingMode RM = getLangOpts().getFPRoundingMode();
967  llvm::fp::ExceptionBehavior FPExceptionBehavior =
968  ToConstrainedExceptMD(getLangOpts().getFPExceptionMode());
969  Builder.setDefaultConstrainedRounding(RM);
970  Builder.setDefaultConstrainedExcept(FPExceptionBehavior);
971  if ((FD && (FD->UsesFPIntrin() || FD->hasAttr<StrictFPAttr>())) ||
972  (!FD && (FPExceptionBehavior != llvm::fp::ebIgnore ||
973  RM != llvm::RoundingMode::NearestTiesToEven))) {
974  Builder.setIsFPConstrained(true);
975  Fn->addFnAttr(llvm::Attribute::StrictFP);
976  }
977 
978  // If a custom alignment is used, force realigning to this alignment on
979  // any main function which certainly will need it.
980  if (FD && ((FD->isMain() || FD->isMSVCRTEntryPoint()) &&
981  CGM.getCodeGenOpts().StackAlignment))
982  Fn->addFnAttr("stackrealign");
983 
984  llvm::BasicBlock *EntryBB = createBasicBlock("entry", CurFn);
985 
986  // Create a marker to make it easy to insert allocas into the entryblock
987  // later. Don't create this with the builder, because we don't want it
988  // folded.
989  llvm::Value *Undef = llvm::UndefValue::get(Int32Ty);
990  AllocaInsertPt = new llvm::BitCastInst(Undef, Int32Ty, "allocapt", EntryBB);
991 
993 
994  Builder.SetInsertPoint(EntryBB);
995 
996  // If we're checking the return value, allocate space for a pointer to a
997  // precise source location of the checked return statement.
998  if (requiresReturnValueCheck()) {
999  ReturnLocation = CreateDefaultAlignTempAlloca(Int8PtrTy, "return.sloc.ptr");
1000  Builder.CreateStore(llvm::ConstantPointerNull::get(Int8PtrTy),
1001  ReturnLocation);
1002  }
1003 
1004  // Emit subprogram debug descriptor.
1005  if (CGDebugInfo *DI = getDebugInfo()) {
1006  // Reconstruct the type from the argument list so that implicit parameters,
1007  // such as 'this' and 'vtt', show up in the debug info. Preserve the calling
1008  // convention.
1009  DI->emitFunctionStart(GD, Loc, StartLoc,
1010  DI->getFunctionType(FD, RetTy, Args), CurFn,
1011  CurFuncIsThunk);
1012  }
1013 
1014  if (ShouldInstrumentFunction()) {
1015  if (CGM.getCodeGenOpts().InstrumentFunctions)
1016  CurFn->addFnAttr("instrument-function-entry", "__cyg_profile_func_enter");
1017  if (CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining)
1018  CurFn->addFnAttr("instrument-function-entry-inlined",
1019  "__cyg_profile_func_enter");
1020  if (CGM.getCodeGenOpts().InstrumentFunctionEntryBare)
1021  CurFn->addFnAttr("instrument-function-entry-inlined",
1022  "__cyg_profile_func_enter_bare");
1023  }
1024 
1025  // Since emitting the mcount call here impacts optimizations such as function
1026  // inlining, we just add an attribute to insert a mcount call in backend.
1027  // The attribute "counting-function" is set to mcount function name which is
1028  // architecture dependent.
1029  if (CGM.getCodeGenOpts().InstrumentForProfiling) {
1030  // Calls to fentry/mcount should not be generated if function has
1031  // the no_instrument_function attribute.
1032  if (!CurFuncDecl || !CurFuncDecl->hasAttr<NoInstrumentFunctionAttr>()) {
1033  if (CGM.getCodeGenOpts().CallFEntry)
1034  Fn->addFnAttr("fentry-call", "true");
1035  else {
1036  Fn->addFnAttr("instrument-function-entry-inlined",
1037  getTarget().getMCountName());
1038  }
1039  if (CGM.getCodeGenOpts().MNopMCount) {
1040  if (!CGM.getCodeGenOpts().CallFEntry)
1041  CGM.getDiags().Report(diag::err_opt_not_valid_without_opt)
1042  << "-mnop-mcount" << "-mfentry";
1043  Fn->addFnAttr("mnop-mcount");
1044  }
1045 
1046  if (CGM.getCodeGenOpts().RecordMCount) {
1047  if (!CGM.getCodeGenOpts().CallFEntry)
1048  CGM.getDiags().Report(diag::err_opt_not_valid_without_opt)
1049  << "-mrecord-mcount" << "-mfentry";
1050  Fn->addFnAttr("mrecord-mcount");
1051  }
1052  }
1053  }
1054 
1055  if (CGM.getCodeGenOpts().PackedStack) {
1056  if (getContext().getTargetInfo().getTriple().getArch() !=
1057  llvm::Triple::systemz)
1058  CGM.getDiags().Report(diag::err_opt_not_valid_on_target)
1059  << "-mpacked-stack";
1060  Fn->addFnAttr("packed-stack");
1061  }
1062 
1063  if (CGM.getCodeGenOpts().WarnStackSize != UINT_MAX &&
1064  !CGM.getDiags().isIgnored(diag::warn_fe_backend_frame_larger_than, Loc))
1065  Fn->addFnAttr("warn-stack-size",
1066  std::to_string(CGM.getCodeGenOpts().WarnStackSize));
1067 
1068  if (RetTy->isVoidType()) {
1069  // Void type; nothing to return.
1071 
1072  // Count the implicit return.
1073  if (!endsWithReturn(D))
1074  ++NumReturnExprs;
1075  } else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect) {
1076  // Indirect return; emit returned value directly into sret slot.
1077  // This reduces code size, and affects correctness in C++.
1078  auto AI = CurFn->arg_begin();
1080  ++AI;
1081  ReturnValue = Address(&*AI, ConvertType(RetTy),
1085  CreateDefaultAlignTempAlloca(Int8PtrTy, "result.ptr");
1089  }
1090  } else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::InAlloca &&
1092  // Load the sret pointer from the argument struct and return into that.
1093  unsigned Idx = CurFnInfo->getReturnInfo().getInAllocaFieldIndex();
1094  llvm::Function::arg_iterator EI = CurFn->arg_end();
1095  --EI;
1097  EI->getType()->getPointerElementType(), &*EI, Idx);
1098  llvm::Type *Ty =
1099  cast<llvm::GetElementPtrInst>(Addr)->getResultElementType();
1101  Addr = Builder.CreateAlignedLoad(Ty, Addr, getPointerAlign(), "agg.result");
1103  } else {
1104  ReturnValue = CreateIRTemp(RetTy, "retval");
1105 
1106  // Tell the epilog emitter to autorelease the result. We do this
1107  // now so that various specialized functions can suppress it
1108  // during their IR-generation.
1109  if (getLangOpts().ObjCAutoRefCount &&
1111  RetTy->isObjCRetainableType())
1112  AutoreleaseResult = true;
1113  }
1114 
1116 
1118 
1119  // Emit OpenMP specific initialization of the device functions.
1120  if (getLangOpts().OpenMP && CurCodeDecl)
1122 
1124 
1125  if (D && isa<CXXMethodDecl>(D) && cast<CXXMethodDecl>(D)->isInstance()) {
1127  const CXXMethodDecl *MD = cast<CXXMethodDecl>(D);
1128  if (MD->getParent()->isLambda() &&
1129  MD->getOverloadedOperator() == OO_Call) {
1130  // We're in a lambda; figure out the captures.
1133  if (LambdaThisCaptureField) {
1134  // If the lambda captures the object referred to by '*this' - either by
1135  // value or by reference, make sure CXXThisValue points to the correct
1136  // object.
1137 
1138  // Get the lvalue for the field (which is a copy of the enclosing object
1139  // or contains the address of the enclosing object).
1142  // If the enclosing object was captured by value, just use its address.
1143  CXXThisValue = ThisFieldLValue.getAddress(*this).getPointer();
1144  } else {
1145  // Load the lvalue pointed to by the field, since '*this' was captured
1146  // by reference.
1147  CXXThisValue =
1148  EmitLoadOfLValue(ThisFieldLValue, SourceLocation()).getScalarVal();
1149  }
1150  }
1151  for (auto *FD : MD->getParent()->fields()) {
1152  if (FD->hasCapturedVLAType()) {
1153  auto *ExprArg = EmitLoadOfLValue(EmitLValueForLambdaField(FD),
1155  auto VAT = FD->getCapturedVLAType();
1156  VLASizeMap[VAT->getSizeExpr()] = ExprArg;
1157  }
1158  }
1159  } else {
1160  // Not in a lambda; just use 'this' from the method.
1161  // FIXME: Should we generate a new load for each use of 'this'? The
1162  // fast register allocator would be happier...
1163  CXXThisValue = CXXABIThisValue;
1164  }
1165 
1166  // Check the 'this' pointer once per function, if it's available.
1167  if (CXXABIThisValue) {
1168  SanitizerSet SkippedChecks;
1169  SkippedChecks.set(SanitizerKind::ObjectSize, true);
1170  QualType ThisTy = MD->getThisType();
1171 
1172  // If this is the call operator of a lambda with no capture-default, it
1173  // may have a static invoker function, which may call this operator with
1174  // a null 'this' pointer.
1175  if (isLambdaCallOperator(MD) &&
1177  SkippedChecks.set(SanitizerKind::Null, true);
1178 
1179  EmitTypeCheck(
1180  isa<CXXConstructorDecl>(MD) ? TCK_ConstructorCall : TCK_MemberCall,
1181  Loc, CXXABIThisValue, ThisTy, CXXABIThisAlignment, SkippedChecks);
1182  }
1183  }
1184 
1185  // If any of the arguments have a variably modified type, make sure to
1186  // emit the type size.
1187  for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
1188  i != e; ++i) {
1189  const VarDecl *VD = *i;
1190 
1191  // Dig out the type as written from ParmVarDecls; it's unclear whether
1192  // the standard (C99 6.9.1p10) requires this, but we're following the
1193  // precedent set by gcc.
1194  QualType Ty;
1195  if (const ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(VD))
1196  Ty = PVD->getOriginalType();
1197  else
1198  Ty = VD->getType();
1199 
1200  if (Ty->isVariablyModifiedType())
1202  }
1203  // Emit a location at the end of the prologue.
1204  if (CGDebugInfo *DI = getDebugInfo())
1205  DI->EmitLocation(Builder, StartLoc);
1206 
1207  // TODO: Do we need to handle this in two places like we do with
1208  // target-features/target-cpu?
1209  if (CurFuncDecl)
1210  if (const auto *VecWidth = CurFuncDecl->getAttr<MinVectorWidthAttr>())
1211  LargestVectorWidth = VecWidth->getVectorWidth();
1212 }
1213 
1216  if (const CompoundStmt *S = dyn_cast<CompoundStmt>(Body))
1218  else
1219  EmitStmt(Body);
1220 
1221  // This is checked after emitting the function body so we know if there
1222  // are any permitted infinite loops.
1224  CurFn->addFnAttr(llvm::Attribute::MustProgress);
1225 }
1226 
1227 /// When instrumenting to collect profile data, the counts for some blocks
1228 /// such as switch cases need to not include the fall-through counts, so
1229 /// emit a branch around the instrumentation code. When not instrumenting,
1230 /// this just calls EmitBlock().
1232  const Stmt *S) {
1233  llvm::BasicBlock *SkipCountBB = nullptr;
1235  // When instrumenting for profiling, the fallthrough to certain
1236  // statements needs to skip over the instrumentation code so that we
1237  // get an accurate count.
1238  SkipCountBB = createBasicBlock("skipcount");
1239  EmitBranch(SkipCountBB);
1240  }
1241  EmitBlock(BB);
1242  uint64_t CurrentCount = getCurrentProfileCount();
1245  if (SkipCountBB)
1246  EmitBlock(SkipCountBB);
1247 }
1248 
1249 /// Tries to mark the given function nounwind based on the
1250 /// non-existence of any throwing calls within it. We believe this is
1251 /// lightweight enough to do at -O0.
1252 static void TryMarkNoThrow(llvm::Function *F) {
1253  // LLVM treats 'nounwind' on a function as part of the type, so we
1254  // can't do this on functions that can be overwritten.
1255  if (F->isInterposable()) return;
1256 
1257  for (llvm::BasicBlock &BB : *F)
1258  for (llvm::Instruction &I : BB)
1259  if (I.mayThrow())
1260  return;
1261 
1262  F->setDoesNotThrow();
1263 }
1264 
1266  FunctionArgList &Args) {
1267  const FunctionDecl *FD = cast<FunctionDecl>(GD.getDecl());
1268  QualType ResTy = FD->getReturnType();
1269 
1270  const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD);
1271  if (MD && MD->isInstance()) {
1272  if (CGM.getCXXABI().HasThisReturn(GD))
1273  ResTy = MD->getThisType();
1274  else if (CGM.getCXXABI().hasMostDerivedReturn(GD))
1275  ResTy = CGM.getContext().VoidPtrTy;
1276  CGM.getCXXABI().buildThisParam(*this, Args);
1277  }
1278 
1279  // The base version of an inheriting constructor whose constructed base is a
1280  // virtual base is not passed any arguments (because it doesn't actually call
1281  // the inherited constructor).
1282  bool PassedParams = true;
1283  if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(FD))
1284  if (auto Inherited = CD->getInheritedConstructor())
1285  PassedParams =
1286  getTypes().inheritingCtorHasParams(Inherited, GD.getCtorType());
1287 
1288  if (PassedParams) {
1289  for (auto *Param : FD->parameters()) {
1290  Args.push_back(Param);
1291  if (!Param->hasAttr<PassObjectSizeAttr>())
1292  continue;
1293 
1294  auto *Implicit = ImplicitParamDecl::Create(
1295  getContext(), Param->getDeclContext(), Param->getLocation(),
1296  /*Id=*/nullptr, getContext().getSizeType(), ImplicitParamDecl::Other);
1297  SizeArguments[Param] = Implicit;
1298  Args.push_back(Implicit);
1299  }
1300  }
1301 
1302  if (MD && (isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD)))
1303  CGM.getCXXABI().addImplicitStructorParams(*this, ResTy, Args);
1304 
1305  return ResTy;
1306 }
1307 
1308 void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
1309  const CGFunctionInfo &FnInfo) {
1310  assert(Fn && "generating code for null Function");
1311  const FunctionDecl *FD = cast<FunctionDecl>(GD.getDecl());
1312  CurGD = GD;
1313 
1314  FunctionArgList Args;
1315  QualType ResTy = BuildFunctionArgList(GD, Args);
1316 
1317  if (FD->isInlineBuiltinDeclaration()) {
1318  // When generating code for a builtin with an inline declaration, use a
1319  // mangled name to hold the actual body, while keeping an external
1320  // definition in case the function pointer is referenced somewhere.
1321  std::string FDInlineName = (Fn->getName() + ".inline").str();
1322  llvm::Module *M = Fn->getParent();
1323  llvm::Function *Clone = M->getFunction(FDInlineName);
1324  if (!Clone) {
1325  Clone = llvm::Function::Create(Fn->getFunctionType(),
1327  Fn->getAddressSpace(), FDInlineName, M);
1328  Clone->addFnAttr(llvm::Attribute::AlwaysInline);
1329  }
1330  Fn->setLinkage(llvm::GlobalValue::ExternalLinkage);
1331  Fn = Clone;
1332  } else {
1333  // Detect the unusual situation where an inline version is shadowed by a
1334  // non-inline version. In that case we should pick the external one
1335  // everywhere. That's GCC behavior too. Unfortunately, I cannot find a way
1336  // to detect that situation before we reach codegen, so do some late
1337  // replacement.
1338  for (const FunctionDecl *PD = FD->getPreviousDecl(); PD;
1339  PD = PD->getPreviousDecl()) {
1340  if (LLVM_UNLIKELY(PD->isInlineBuiltinDeclaration())) {
1341  std::string FDInlineName = (Fn->getName() + ".inline").str();
1342  llvm::Module *M = Fn->getParent();
1343  if (llvm::Function *Clone = M->getFunction(FDInlineName)) {
1344  Clone->replaceAllUsesWith(Fn);
1345  Clone->eraseFromParent();
1346  }
1347  break;
1348  }
1349  }
1350  }
1351 
1352  // Check if we should generate debug info for this function.
1353  if (FD->hasAttr<NoDebugAttr>()) {
1354  // Clear non-distinct debug info that was possibly attached to the function
1355  // due to an earlier declaration without the nodebug attribute
1356  Fn->setSubprogram(nullptr);
1357  // Disable debug info indefinitely for this function
1358  DebugInfo = nullptr;
1359  }
1360 
1361  // The function might not have a body if we're generating thunks for a
1362  // function declaration.
1363  SourceRange BodyRange;
1364  if (Stmt *Body = FD->getBody())
1365  BodyRange = Body->getSourceRange();
1366  else
1367  BodyRange = FD->getLocation();
1368  CurEHLocation = BodyRange.getEnd();
1369 
1370  // Use the location of the start of the function to determine where
1371  // the function definition is located. By default use the location
1372  // of the declaration as the location for the subprogram. A function
1373  // may lack a declaration in the source code if it is created by code
1374  // gen. (examples: _GLOBAL__I_a, __cxx_global_array_dtor, thunk).
1375  SourceLocation Loc = FD->getLocation();
1376 
1377  // If this is a function specialization then use the pattern body
1378  // as the location for the function.
1379  if (const FunctionDecl *SpecDecl = FD->getTemplateInstantiationPattern())
1380  if (SpecDecl->hasBody(SpecDecl))
1381  Loc = SpecDecl->getLocation();
1382 
1383  Stmt *Body = FD->getBody();
1384 
1385  if (Body) {
1386  // Coroutines always emit lifetime markers.
1387  if (isa<CoroutineBodyStmt>(Body))
1388  ShouldEmitLifetimeMarkers = true;
1389 
1390  // Initialize helper which will detect jumps which can cause invalid
1391  // lifetime markers.
1392  if (ShouldEmitLifetimeMarkers)
1393  Bypasses.Init(Body);
1394  }
1395 
1396  // Emit the standard function prologue.
1397  StartFunction(GD, ResTy, Fn, FnInfo, Args, Loc, BodyRange.getBegin());
1398 
1399  // Save parameters for coroutine function.
1400  if (Body && isa_and_nonnull<CoroutineBodyStmt>(Body))
1401  for (const auto *ParamDecl : FD->parameters())
1402  FnArgs.push_back(ParamDecl);
1403 
1404  // Generate the body of the function.
1405  PGO.assignRegionCounters(GD, CurFn);
1406  if (isa<CXXDestructorDecl>(FD))
1407  EmitDestructorBody(Args);
1408  else if (isa<CXXConstructorDecl>(FD))
1409  EmitConstructorBody(Args);
1410  else if (getLangOpts().CUDA &&
1411  !getLangOpts().CUDAIsDevice &&
1412  FD->hasAttr<CUDAGlobalAttr>())
1413  CGM.getCUDARuntime().emitDeviceStub(*this, Args);
1414  else if (isa<CXXMethodDecl>(FD) &&
1415  cast<CXXMethodDecl>(FD)->isLambdaStaticInvoker()) {
1416  // The lambda static invoker function is special, because it forwards or
1417  // clones the body of the function call operator (but is actually static).
1418  EmitLambdaStaticInvokeBody(cast<CXXMethodDecl>(FD));
1419  } else if (FD->isDefaulted() && isa<CXXMethodDecl>(FD) &&
1420  (cast<CXXMethodDecl>(FD)->isCopyAssignmentOperator() ||
1421  cast<CXXMethodDecl>(FD)->isMoveAssignmentOperator())) {
1422  // Implicit copy-assignment gets the same special treatment as implicit
1423  // copy-constructors.
1425  } else if (Body) {
1426  EmitFunctionBody(Body);
1427  } else
1428  llvm_unreachable("no definition for emitted function");
1429 
1430  // C++11 [stmt.return]p2:
1431  // Flowing off the end of a function [...] results in undefined behavior in
1432  // a value-returning function.
1433  // C11 6.9.1p12:
1434  // If the '}' that terminates a function is reached, and the value of the
1435  // function call is used by the caller, the behavior is undefined.
1437  !FD->getReturnType()->isVoidType() && Builder.GetInsertBlock()) {
1438  bool ShouldEmitUnreachable =
1439  CGM.getCodeGenOpts().StrictReturn ||
1441  if (SanOpts.has(SanitizerKind::Return)) {
1442  SanitizerScope SanScope(this);
1443  llvm::Value *IsFalse = Builder.getFalse();
1444  EmitCheck(std::make_pair(IsFalse, SanitizerKind::Return),
1445  SanitizerHandler::MissingReturn,
1446  EmitCheckSourceLocation(FD->getLocation()), None);
1447  } else if (ShouldEmitUnreachable) {
1448  if (CGM.getCodeGenOpts().OptimizationLevel == 0)
1449  EmitTrapCall(llvm::Intrinsic::trap);
1450  }
1451  if (SanOpts.has(SanitizerKind::Return) || ShouldEmitUnreachable) {
1452  Builder.CreateUnreachable();
1453  Builder.ClearInsertionPoint();
1454  }
1455  }
1456 
1457  // Emit the standard function epilogue.
1458  FinishFunction(BodyRange.getEnd());
1459 
1460  // If we haven't marked the function nothrow through other means, do
1461  // a quick pass now to see if we can.
1462  if (!CurFn->doesNotThrow())
1464 }
1465 
1466 /// ContainsLabel - Return true if the statement contains a label in it. If
1467 /// this statement is not executed normally, it not containing a label means
1468 /// that we can just remove the code.
1469 bool CodeGenFunction::ContainsLabel(const Stmt *S, bool IgnoreCaseStmts) {
1470  // Null statement, not a label!
1471  if (!S) return false;
1472 
1473  // If this is a label, we have to emit the code, consider something like:
1474  // if (0) { ... foo: bar(); } goto foo;
1475  //
1476  // TODO: If anyone cared, we could track __label__'s, since we know that you
1477  // can't jump to one from outside their declared region.
1478  if (isa<LabelStmt>(S))
1479  return true;
1480 
1481  // If this is a case/default statement, and we haven't seen a switch, we have
1482  // to emit the code.
1483  if (isa<SwitchCase>(S) && !IgnoreCaseStmts)
1484  return true;
1485 
1486  // If this is a switch statement, we want to ignore cases below it.
1487  if (isa<SwitchStmt>(S))
1488  IgnoreCaseStmts = true;
1489 
1490  // Scan subexpressions for verboten labels.
1491  for (const Stmt *SubStmt : S->children())
1492  if (ContainsLabel(SubStmt, IgnoreCaseStmts))
1493  return true;
1494 
1495  return false;
1496 }
1497 
1498 /// containsBreak - Return true if the statement contains a break out of it.
1499 /// If the statement (recursively) contains a switch or loop with a break
1500 /// inside of it, this is fine.
1502  // Null statement, not a label!
1503  if (!S) return false;
1504 
1505  // If this is a switch or loop that defines its own break scope, then we can
1506  // include it and anything inside of it.
1507  if (isa<SwitchStmt>(S) || isa<WhileStmt>(S) || isa<DoStmt>(S) ||
1508  isa<ForStmt>(S))
1509  return false;
1510 
1511  if (isa<BreakStmt>(S))
1512  return true;
1513 
1514  // Scan subexpressions for verboten breaks.
1515  for (const Stmt *SubStmt : S->children())
1516  if (containsBreak(SubStmt))
1517  return true;
1518 
1519  return false;
1520 }
1521 
1523  if (!S) return false;
1524 
1525  // Some statement kinds add a scope and thus never add a decl to the current
1526  // scope. Note, this list is longer than the list of statements that might
1527  // have an unscoped decl nested within them, but this way is conservatively
1528  // correct even if more statement kinds are added.
1529  if (isa<IfStmt>(S) || isa<SwitchStmt>(S) || isa<WhileStmt>(S) ||
1530  isa<DoStmt>(S) || isa<ForStmt>(S) || isa<CompoundStmt>(S) ||
1531  isa<CXXForRangeStmt>(S) || isa<CXXTryStmt>(S) ||
1532  isa<ObjCForCollectionStmt>(S) || isa<ObjCAtTryStmt>(S))
1533  return false;
1534 
1535  if (isa<DeclStmt>(S))
1536  return true;
1537 
1538  for (const Stmt *SubStmt : S->children())
1539  if (mightAddDeclToScope(SubStmt))
1540  return true;
1541 
1542  return false;
1543 }
1544 
1545 /// ConstantFoldsToSimpleInteger - If the specified expression does not fold
1546 /// to a constant, or if it does but contains a label, return false. If it
1547 /// constant folds return true and set the boolean result in Result.
1549  bool &ResultBool,
1550  bool AllowLabels) {
1551  llvm::APSInt ResultInt;
1552  if (!ConstantFoldsToSimpleInteger(Cond, ResultInt, AllowLabels))
1553  return false;
1554 
1555  ResultBool = ResultInt.getBoolValue();
1556  return true;
1557 }
1558 
1559 /// ConstantFoldsToSimpleInteger - If the specified expression does not fold
1560 /// to a constant, or if it does but contains a label, return false. If it
1561 /// constant folds return true and set the folded value.
1563  llvm::APSInt &ResultInt,
1564  bool AllowLabels) {
1565  // FIXME: Rename and handle conversion of other evaluatable things
1566  // to bool.
1567  Expr::EvalResult Result;
1568  if (!Cond->EvaluateAsInt(Result, getContext()))
1569  return false; // Not foldable, not integer or not fully evaluatable.
1570 
1571  llvm::APSInt Int = Result.Val.getInt();
1572  if (!AllowLabels && CodeGenFunction::ContainsLabel(Cond))
1573  return false; // Contains a label.
1574 
1575  ResultInt = Int;
1576  return true;
1577 }
1578 
1579 /// Determine whether the given condition is an instrumentable condition
1580 /// (i.e. no "&&" or "||").
1582  // Bypass simplistic logical-NOT operator before determining whether the
1583  // condition contains any other logical operator.
1584  if (const UnaryOperator *UnOp = dyn_cast<UnaryOperator>(C->IgnoreParens()))
1585  if (UnOp->getOpcode() == UO_LNot)
1586  C = UnOp->getSubExpr();
1587 
1588  const BinaryOperator *BOp = dyn_cast<BinaryOperator>(C->IgnoreParens());
1589  return (!BOp || !BOp->isLogicalOp());
1590 }
1591 
1592 /// EmitBranchToCounterBlock - Emit a conditional branch to a new block that
1593 /// increments a profile counter based on the semantics of the given logical
1594 /// operator opcode. This is used to instrument branch condition coverage for
1595 /// logical operators.
1597  const Expr *Cond, BinaryOperator::Opcode LOp, llvm::BasicBlock *TrueBlock,
1598  llvm::BasicBlock *FalseBlock, uint64_t TrueCount /* = 0 */,
1599  Stmt::Likelihood LH /* =None */, const Expr *CntrIdx /* = nullptr */) {
1600  // If not instrumenting, just emit a branch.
1601  bool InstrumentRegions = CGM.getCodeGenOpts().hasProfileClangInstr();
1602  if (!InstrumentRegions || !isInstrumentedCondition(Cond))
1603  return EmitBranchOnBoolExpr(Cond, TrueBlock, FalseBlock, TrueCount, LH);
1604 
1605  llvm::BasicBlock *ThenBlock = nullptr;
1606  llvm::BasicBlock *ElseBlock = nullptr;
1607  llvm::BasicBlock *NextBlock = nullptr;
1608 
1609  // Create the block we'll use to increment the appropriate counter.
1610  llvm::BasicBlock *CounterIncrBlock = createBasicBlock("lop.rhscnt");
1611 
1612  // Set block pointers according to Logical-AND (BO_LAnd) semantics. This
1613  // means we need to evaluate the condition and increment the counter on TRUE:
1614  //
1615  // if (Cond)
1616  // goto CounterIncrBlock;
1617  // else
1618  // goto FalseBlock;
1619  //
1620  // CounterIncrBlock:
1621  // Counter++;
1622  // goto TrueBlock;
1623 
1624  if (LOp == BO_LAnd) {
1625  ThenBlock = CounterIncrBlock;
1626  ElseBlock = FalseBlock;
1627  NextBlock = TrueBlock;
1628  }
1629 
1630  // Set block pointers according to Logical-OR (BO_LOr) semantics. This means
1631  // we need to evaluate the condition and increment the counter on FALSE:
1632  //
1633  // if (Cond)
1634  // goto TrueBlock;
1635  // else
1636  // goto CounterIncrBlock;
1637  //
1638  // CounterIncrBlock:
1639  // Counter++;
1640  // goto FalseBlock;
1641 
1642  else if (LOp == BO_LOr) {
1643  ThenBlock = TrueBlock;
1644  ElseBlock = CounterIncrBlock;
1645  NextBlock = FalseBlock;
1646  } else {
1647  llvm_unreachable("Expected Opcode must be that of a Logical Operator");
1648  }
1649 
1650  // Emit Branch based on condition.
1651  EmitBranchOnBoolExpr(Cond, ThenBlock, ElseBlock, TrueCount, LH);
1652 
1653  // Emit the block containing the counter increment(s).
1654  EmitBlock(CounterIncrBlock);
1655 
1656  // Increment corresponding counter; if index not provided, use Cond as index.
1657  incrementProfileCounter(CntrIdx ? CntrIdx : Cond);
1658 
1659  // Go to the next block.
1660  EmitBranch(NextBlock);
1661 }
1662 
1663 /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an if
1664 /// statement) to the specified blocks. Based on the condition, this might try
1665 /// to simplify the codegen of the conditional based on the branch.
1666 /// \param LH The value of the likelihood attribute on the True branch.
1668  llvm::BasicBlock *TrueBlock,
1669  llvm::BasicBlock *FalseBlock,
1670  uint64_t TrueCount,
1671  Stmt::Likelihood LH) {
1672  Cond = Cond->IgnoreParens();
1673 
1674  if (const BinaryOperator *CondBOp = dyn_cast<BinaryOperator>(Cond)) {
1675 
1676  // Handle X && Y in a condition.
1677  if (CondBOp->getOpcode() == BO_LAnd) {
1678  // If we have "1 && X", simplify the code. "0 && X" would have constant
1679  // folded if the case was simple enough.
1680  bool ConstantBool = false;
1681  if (ConstantFoldsToSimpleInteger(CondBOp->getLHS(), ConstantBool) &&
1682  ConstantBool) {
1683  // br(1 && X) -> br(X).
1684  incrementProfileCounter(CondBOp);
1685  return EmitBranchToCounterBlock(CondBOp->getRHS(), BO_LAnd, TrueBlock,
1686  FalseBlock, TrueCount, LH);
1687  }
1688 
1689  // If we have "X && 1", simplify the code to use an uncond branch.
1690  // "X && 0" would have been constant folded to 0.
1691  if (ConstantFoldsToSimpleInteger(CondBOp->getRHS(), ConstantBool) &&
1692  ConstantBool) {
1693  // br(X && 1) -> br(X).
1694  return EmitBranchToCounterBlock(CondBOp->getLHS(), BO_LAnd, TrueBlock,
1695  FalseBlock, TrueCount, LH, CondBOp);
1696  }
1697 
1698  // Emit the LHS as a conditional. If the LHS conditional is false, we
1699  // want to jump to the FalseBlock.
1700  llvm::BasicBlock *LHSTrue = createBasicBlock("land.lhs.true");
1701  // The counter tells us how often we evaluate RHS, and all of TrueCount
1702  // can be propagated to that branch.
1703  uint64_t RHSCount = getProfileCount(CondBOp->getRHS());
1704 
1705  ConditionalEvaluation eval(*this);
1706  {
1707  ApplyDebugLocation DL(*this, Cond);
1708  // Propagate the likelihood attribute like __builtin_expect
1709  // __builtin_expect(X && Y, 1) -> X and Y are likely
1710  // __builtin_expect(X && Y, 0) -> only Y is unlikely
1711  EmitBranchOnBoolExpr(CondBOp->getLHS(), LHSTrue, FalseBlock, RHSCount,
1712  LH == Stmt::LH_Unlikely ? Stmt::LH_None : LH);
1713  EmitBlock(LHSTrue);
1714  }
1715 
1716  incrementProfileCounter(CondBOp);
1717  setCurrentProfileCount(getProfileCount(CondBOp->getRHS()));
1718 
1719  // Any temporaries created here are conditional.
1720  eval.begin(*this);
1721  EmitBranchToCounterBlock(CondBOp->getRHS(), BO_LAnd, TrueBlock,
1722  FalseBlock, TrueCount, LH);
1723  eval.end(*this);
1724 
1725  return;
1726  }
1727 
1728  if (CondBOp->getOpcode() == BO_LOr) {
1729  // If we have "0 || X", simplify the code. "1 || X" would have constant
1730  // folded if the case was simple enough.
1731  bool ConstantBool = false;
1732  if (ConstantFoldsToSimpleInteger(CondBOp->getLHS(), ConstantBool) &&
1733  !ConstantBool) {
1734  // br(0 || X) -> br(X).
1735  incrementProfileCounter(CondBOp);
1736  return EmitBranchToCounterBlock(CondBOp->getRHS(), BO_LOr, TrueBlock,
1737  FalseBlock, TrueCount, LH);
1738  }
1739 
1740  // If we have "X || 0", simplify the code to use an uncond branch.
1741  // "X || 1" would have been constant folded to 1.
1742  if (ConstantFoldsToSimpleInteger(CondBOp->getRHS(), ConstantBool) &&
1743  !ConstantBool) {
1744  // br(X || 0) -> br(X).
1745  return EmitBranchToCounterBlock(CondBOp->getLHS(), BO_LOr, TrueBlock,
1746  FalseBlock, TrueCount, LH, CondBOp);
1747  }
1748 
1749  // Emit the LHS as a conditional. If the LHS conditional is true, we
1750  // want to jump to the TrueBlock.
1751  llvm::BasicBlock *LHSFalse = createBasicBlock("lor.lhs.false");
1752  // We have the count for entry to the RHS and for the whole expression
1753  // being true, so we can divy up True count between the short circuit and
1754  // the RHS.
1755  uint64_t LHSCount =
1756  getCurrentProfileCount() - getProfileCount(CondBOp->getRHS());
1757  uint64_t RHSCount = TrueCount - LHSCount;
1758 
1759  ConditionalEvaluation eval(*this);
1760  {
1761  // Propagate the likelihood attribute like __builtin_expect
1762  // __builtin_expect(X || Y, 1) -> only Y is likely
1763  // __builtin_expect(X || Y, 0) -> both X and Y are unlikely
1764  ApplyDebugLocation DL(*this, Cond);
1765  EmitBranchOnBoolExpr(CondBOp->getLHS(), TrueBlock, LHSFalse, LHSCount,
1766  LH == Stmt::LH_Likely ? Stmt::LH_None : LH);
1767  EmitBlock(LHSFalse);
1768  }
1769 
1770  incrementProfileCounter(CondBOp);
1771  setCurrentProfileCount(getProfileCount(CondBOp->getRHS()));
1772 
1773  // Any temporaries created here are conditional.
1774  eval.begin(*this);
1775  EmitBranchToCounterBlock(CondBOp->getRHS(), BO_LOr, TrueBlock, FalseBlock,
1776  RHSCount, LH);
1777 
1778  eval.end(*this);
1779 
1780  return;
1781  }
1782  }
1783 
1784  if (const UnaryOperator *CondUOp = dyn_cast<UnaryOperator>(Cond)) {
1785  // br(!x, t, f) -> br(x, f, t)
1786  if (CondUOp->getOpcode() == UO_LNot) {
1787  // Negate the count.
1788  uint64_t FalseCount = getCurrentProfileCount() - TrueCount;
1789  // The values of the enum are chosen to make this negation possible.
1790  LH = static_cast<Stmt::Likelihood>(-LH);
1791  // Negate the condition and swap the destination blocks.
1792  return EmitBranchOnBoolExpr(CondUOp->getSubExpr(), FalseBlock, TrueBlock,
1793  FalseCount, LH);
1794  }
1795  }
1796 
1797  if (const ConditionalOperator *CondOp = dyn_cast<ConditionalOperator>(Cond)) {
1798  // br(c ? x : y, t, f) -> br(c, br(x, t, f), br(y, t, f))
1799  llvm::BasicBlock *LHSBlock = createBasicBlock("cond.true");
1800  llvm::BasicBlock *RHSBlock = createBasicBlock("cond.false");
1801 
1802  // The ConditionalOperator itself has no likelihood information for its
1803  // true and false branches. This matches the behavior of __builtin_expect.
1804  ConditionalEvaluation cond(*this);
1805  EmitBranchOnBoolExpr(CondOp->getCond(), LHSBlock, RHSBlock,
1806  getProfileCount(CondOp), Stmt::LH_None);
1807 
1808  // When computing PGO branch weights, we only know the overall count for
1809  // the true block. This code is essentially doing tail duplication of the
1810  // naive code-gen, introducing new edges for which counts are not
1811  // available. Divide the counts proportionally between the LHS and RHS of
1812  // the conditional operator.
1813  uint64_t LHSScaledTrueCount = 0;
1814  if (TrueCount) {
1815  double LHSRatio =
1817  LHSScaledTrueCount = TrueCount * LHSRatio;
1818  }
1819 
1820  cond.begin(*this);
1821  EmitBlock(LHSBlock);
1822  incrementProfileCounter(CondOp);
1823  {
1824  ApplyDebugLocation DL(*this, Cond);
1825  EmitBranchOnBoolExpr(CondOp->getLHS(), TrueBlock, FalseBlock,
1826  LHSScaledTrueCount, LH);
1827  }
1828  cond.end(*this);
1829 
1830  cond.begin(*this);
1831  EmitBlock(RHSBlock);
1832  EmitBranchOnBoolExpr(CondOp->getRHS(), TrueBlock, FalseBlock,
1833  TrueCount - LHSScaledTrueCount, LH);
1834  cond.end(*this);
1835 
1836  return;
1837  }
1838 
1839  if (const CXXThrowExpr *Throw = dyn_cast<CXXThrowExpr>(Cond)) {
1840  // Conditional operator handling can give us a throw expression as a
1841  // condition for a case like:
1842  // br(c ? throw x : y, t, f) -> br(c, br(throw x, t, f), br(y, t, f)
1843  // Fold this to:
1844  // br(c, throw x, br(y, t, f))
1845  EmitCXXThrowExpr(Throw, /*KeepInsertionPoint*/false);
1846  return;
1847  }
1848 
1849  // Emit the code with the fully general case.
1850  llvm::Value *CondV;
1851  {
1852  ApplyDebugLocation DL(*this, Cond);
1853  CondV = EvaluateExprAsBool(Cond);
1854  }
1855 
1856  llvm::MDNode *Weights = nullptr;
1857  llvm::MDNode *Unpredictable = nullptr;
1858 
1859  // If the branch has a condition wrapped by __builtin_unpredictable,
1860  // create metadata that specifies that the branch is unpredictable.
1861  // Don't bother if not optimizing because that metadata would not be used.
1862  auto *Call = dyn_cast<CallExpr>(Cond->IgnoreImpCasts());
1863  if (Call && CGM.getCodeGenOpts().OptimizationLevel != 0) {
1864  auto *FD = dyn_cast_or_null<FunctionDecl>(Call->getCalleeDecl());
1865  if (FD && FD->getBuiltinID() == Builtin::BI__builtin_unpredictable) {
1866  llvm::MDBuilder MDHelper(getLLVMContext());
1867  Unpredictable = MDHelper.createUnpredictable();
1868  }
1869  }
1870 
1871  // If there is a Likelihood knowledge for the cond, lower it.
1872  // Note that if not optimizing this won't emit anything.
1873  llvm::Value *NewCondV = emitCondLikelihoodViaExpectIntrinsic(CondV, LH);
1874  if (CondV != NewCondV)
1875  CondV = NewCondV;
1876  else {
1877  // Otherwise, lower profile counts. Note that we do this even at -O0.
1878  uint64_t CurrentCount = std::max(getCurrentProfileCount(), TrueCount);
1879  Weights = createProfileWeights(TrueCount, CurrentCount - TrueCount);
1880  }
1881 
1882  Builder.CreateCondBr(CondV, TrueBlock, FalseBlock, Weights, Unpredictable);
1883 }
1884 
1885 /// ErrorUnsupported - Print out an error that codegen doesn't support the
1886 /// specified stmt yet.
1887 void CodeGenFunction::ErrorUnsupported(const Stmt *S, const char *Type) {
1889 }
1890 
1891 /// emitNonZeroVLAInit - Emit the "zero" initialization of a
1892 /// variable-length array whose elements have a non-zero bit-pattern.
1893 ///
1894 /// \param baseType the inner-most element type of the array
1895 /// \param src - a char* pointing to the bit-pattern for a single
1896 /// base element of the array
1897 /// \param sizeInChars - the total size of the VLA, in chars
1898 static void emitNonZeroVLAInit(CodeGenFunction &CGF, QualType baseType,
1899  Address dest, Address src,
1900  llvm::Value *sizeInChars) {
1901  CGBuilderTy &Builder = CGF.Builder;
1902 
1903  CharUnits baseSize = CGF.getContext().getTypeSizeInChars(baseType);
1904  llvm::Value *baseSizeInChars
1905  = llvm::ConstantInt::get(CGF.IntPtrTy, baseSize.getQuantity());
1906 
1907  Address begin =
1908  Builder.CreateElementBitCast(dest, CGF.Int8Ty, "vla.begin");
1909  llvm::Value *end = Builder.CreateInBoundsGEP(
1910  begin.getElementType(), begin.getPointer(), sizeInChars, "vla.end");
1911 
1912  llvm::BasicBlock *originBB = CGF.Builder.GetInsertBlock();
1913  llvm::BasicBlock *loopBB = CGF.createBasicBlock("vla-init.loop");
1914  llvm::BasicBlock *contBB = CGF.createBasicBlock("vla-init.cont");
1915 
1916  // Make a loop over the VLA. C99 guarantees that the VLA element
1917  // count must be nonzero.
1918  CGF.EmitBlock(loopBB);
1919 
1920  llvm::PHINode *cur = Builder.CreatePHI(begin.getType(), 2, "vla.cur");
1921  cur->addIncoming(begin.getPointer(), originBB);
1922 
1923  CharUnits curAlign =
1924  dest.getAlignment().alignmentOfArrayElement(baseSize);
1925 
1926  // memcpy the individual element bit-pattern.
1927  Builder.CreateMemCpy(Address(cur, curAlign), src, baseSizeInChars,
1928  /*volatile*/ false);
1929 
1930  // Go to the next element.
1931  llvm::Value *next =
1932  Builder.CreateInBoundsGEP(CGF.Int8Ty, cur, baseSizeInChars, "vla.next");
1933 
1934  // Leave if that's the end of the VLA.
1935  llvm::Value *done = Builder.CreateICmpEQ(next, end, "vla-init.isdone");
1936  Builder.CreateCondBr(done, contBB, loopBB);
1937  cur->addIncoming(next, loopBB);
1938 
1939  CGF.EmitBlock(contBB);
1940 }
1941 
1942 void
1944  // Ignore empty classes in C++.
1945  if (getLangOpts().CPlusPlus) {
1946  if (const RecordType *RT = Ty->getAs<RecordType>()) {
1947  if (cast<CXXRecordDecl>(RT->getDecl())->isEmpty())
1948  return;
1949  }
1950  }
1951 
1952  // Cast the dest ptr to the appropriate i8 pointer type.
1953  if (DestPtr.getElementType() != Int8Ty)
1954  DestPtr = Builder.CreateElementBitCast(DestPtr, Int8Ty);
1955 
1956  // Get size and alignment info for this aggregate.
1958 
1959  llvm::Value *SizeVal;
1960  const VariableArrayType *vla;
1961 
1962  // Don't bother emitting a zero-byte memset.
1963  if (size.isZero()) {
1964  // But note that getTypeInfo returns 0 for a VLA.
1965  if (const VariableArrayType *vlaType =
1966  dyn_cast_or_null<VariableArrayType>(
1967  getContext().getAsArrayType(Ty))) {
1968  auto VlaSize = getVLASize(vlaType);
1969  SizeVal = VlaSize.NumElts;
1970  CharUnits eltSize = getContext().getTypeSizeInChars(VlaSize.Type);
1971  if (!eltSize.isOne())
1972  SizeVal = Builder.CreateNUWMul(SizeVal, CGM.getSize(eltSize));
1973  vla = vlaType;
1974  } else {
1975  return;
1976  }
1977  } else {
1978  SizeVal = CGM.getSize(size);
1979  vla = nullptr;
1980  }
1981 
1982  // If the type contains a pointer to data member we can't memset it to zero.
1983  // Instead, create a null constant and copy it to the destination.
1984  // TODO: there are other patterns besides zero that we can usefully memset,
1985  // like -1, which happens to be the pattern used by member-pointers.
1986  if (!CGM.getTypes().isZeroInitializable(Ty)) {
1987  // For a VLA, emit a single element, then splat that over the VLA.
1988  if (vla) Ty = getContext().getBaseElementType(vla);
1989 
1990  llvm::Constant *NullConstant = CGM.EmitNullConstant(Ty);
1991 
1992  llvm::GlobalVariable *NullVariable =
1993  new llvm::GlobalVariable(CGM.getModule(), NullConstant->getType(),
1994  /*isConstant=*/true,
1995  llvm::GlobalVariable::PrivateLinkage,
1996  NullConstant, Twine());
1997  CharUnits NullAlign = DestPtr.getAlignment();
1998  NullVariable->setAlignment(NullAlign.getAsAlign());
1999  Address SrcPtr(Builder.CreateBitCast(NullVariable, Builder.getInt8PtrTy()),
2000  NullAlign);
2001 
2002  if (vla) return emitNonZeroVLAInit(*this, Ty, DestPtr, SrcPtr, SizeVal);
2003 
2004  // Get and call the appropriate llvm.memcpy overload.
2005  Builder.CreateMemCpy(DestPtr, SrcPtr, SizeVal, false);
2006  return;
2007  }
2008 
2009  // Otherwise, just memset the whole thing to zero. This is legal
2010  // because in LLVM, all default initializers (other than the ones we just
2011  // handled above) are guaranteed to have a bit pattern of all zeros.
2012  Builder.CreateMemSet(DestPtr, Builder.getInt8(0), SizeVal, false);
2013 }
2014 
2015 llvm::BlockAddress *CodeGenFunction::GetAddrOfLabel(const LabelDecl *L) {
2016  // Make sure that there is a block for the indirect goto.
2017  if (!IndirectBranch)
2019 
2020  llvm::BasicBlock *BB = getJumpDestForLabel(L).getBlock();
2021 
2022  // Make sure the indirect branch includes all of the address-taken blocks.
2023  IndirectBranch->addDestination(BB);
2024  return llvm::BlockAddress::get(CurFn, BB);
2025 }
2026 
2028  // If we already made the indirect branch for indirect goto, return its block.
2029  if (IndirectBranch) return IndirectBranch->getParent();
2030 
2031  CGBuilderTy TmpBuilder(*this, createBasicBlock("indirectgoto"));
2032 
2033  // Create the PHI node that indirect gotos will add entries to.
2034  llvm::Value *DestVal = TmpBuilder.CreatePHI(Int8PtrTy, 0,
2035  "indirect.goto.dest");
2036 
2037  // Create the indirect branch instruction.
2038  IndirectBranch = TmpBuilder.CreateIndirectBr(DestVal);
2039  return IndirectBranch->getParent();
2040 }
2041 
2042 /// Computes the length of an array in elements, as well as the base
2043 /// element type and a properly-typed first element pointer.
2045  QualType &baseType,
2046  Address &addr) {
2047  const ArrayType *arrayType = origArrayType;
2048 
2049  // If it's a VLA, we have to load the stored size. Note that
2050  // this is the size of the VLA in bytes, not its size in elements.
2051  llvm::Value *numVLAElements = nullptr;
2052  if (isa<VariableArrayType>(arrayType)) {
2053  numVLAElements = getVLASize(cast<VariableArrayType>(arrayType)).NumElts;
2054 
2055  // Walk into all VLAs. This doesn't require changes to addr,
2056  // which has type T* where T is the first non-VLA element type.
2057  do {
2058  QualType elementType = arrayType->getElementType();
2059  arrayType = getContext().getAsArrayType(elementType);
2060 
2061  // If we only have VLA components, 'addr' requires no adjustment.
2062  if (!arrayType) {
2063  baseType = elementType;
2064  return numVLAElements;
2065  }
2066  } while (isa<VariableArrayType>(arrayType));
2067 
2068  // We get out here only if we find a constant array type
2069  // inside the VLA.
2070  }
2071 
2072  // We have some number of constant-length arrays, so addr should
2073  // have LLVM type [M x [N x [...]]]*. Build a GEP that walks
2074  // down to the first element of addr.
2075  SmallVector<llvm::Value*, 8> gepIndices;
2076 
2077  // GEP down to the array type.
2078  llvm::ConstantInt *zero = Builder.getInt32(0);
2079  gepIndices.push_back(zero);
2080 
2081  uint64_t countFromCLAs = 1;
2082  QualType eltType;
2083 
2084  llvm::ArrayType *llvmArrayType =
2085  dyn_cast<llvm::ArrayType>(addr.getElementType());
2086  while (llvmArrayType) {
2087  assert(isa<ConstantArrayType>(arrayType));
2088  assert(cast<ConstantArrayType>(arrayType)->getSize().getZExtValue()
2089  == llvmArrayType->getNumElements());
2090 
2091  gepIndices.push_back(zero);
2092  countFromCLAs *= llvmArrayType->getNumElements();
2093  eltType = arrayType->getElementType();
2094 
2095  llvmArrayType =
2096  dyn_cast<llvm::ArrayType>(llvmArrayType->getElementType());
2097  arrayType = getContext().getAsArrayType(arrayType->getElementType());
2098  assert((!llvmArrayType || arrayType) &&
2099  "LLVM and Clang types are out-of-synch");
2100  }
2101 
2102  if (arrayType) {
2103  // From this point onwards, the Clang array type has been emitted
2104  // as some other type (probably a packed struct). Compute the array
2105  // size, and just emit the 'begin' expression as a bitcast.
2106  while (arrayType) {
2107  countFromCLAs *=
2108  cast<ConstantArrayType>(arrayType)->getSize().getZExtValue();
2109  eltType = arrayType->getElementType();
2110  arrayType = getContext().getAsArrayType(eltType);
2111  }
2112 
2113  llvm::Type *baseType = ConvertType(eltType);
2114  addr = Builder.CreateElementBitCast(addr, baseType, "array.begin");
2115  } else {
2116  // Create the actual GEP.
2117  addr = Address(Builder.CreateInBoundsGEP(
2118  addr.getElementType(), addr.getPointer(), gepIndices, "array.begin"),
2119  ConvertTypeForMem(eltType),
2120  addr.getAlignment());
2121  }
2122 
2123  baseType = eltType;
2124 
2125  llvm::Value *numElements
2126  = llvm::ConstantInt::get(SizeTy, countFromCLAs);
2127 
2128  // If we had any VLA dimensions, factor them in.
2129  if (numVLAElements)
2130  numElements = Builder.CreateNUWMul(numVLAElements, numElements);
2131 
2132  return numElements;
2133 }
2134 
2137  assert(vla && "type was not a variable array type!");
2138  return getVLASize(vla);
2139 }
2140 
2143  // The number of elements so far; always size_t.
2144  llvm::Value *numElements = nullptr;
2145 
2146  QualType elementType;
2147  do {
2148  elementType = type->getElementType();
2149  llvm::Value *vlaSize = VLASizeMap[type->getSizeExpr()];
2150  assert(vlaSize && "no size for VLA!");
2151  assert(vlaSize->getType() == SizeTy);
2152 
2153  if (!numElements) {
2154  numElements = vlaSize;
2155  } else {
2156  // It's undefined behavior if this wraps around, so mark it that way.
2157  // FIXME: Teach -fsanitize=undefined to trap this.
2158  numElements = Builder.CreateNUWMul(numElements, vlaSize);
2159  }
2160  } while ((type = getContext().getAsVariableArrayType(elementType)));
2161 
2162  return { numElements, elementType };
2163 }
2164 
2168  assert(vla && "type was not a variable array type!");
2169  return getVLAElements1D(vla);
2170 }
2171 
2174  llvm::Value *VlaSize = VLASizeMap[Vla->getSizeExpr()];
2175  assert(VlaSize && "no size for VLA!");
2176  assert(VlaSize->getType() == SizeTy);
2177  return { VlaSize, Vla->getElementType() };
2178 }
2179 
2181  assert(type->isVariablyModifiedType() &&
2182  "Must pass variably modified type to EmitVLASizes!");
2183 
2185 
2186  // We're going to walk down into the type and look for VLA
2187  // expressions.
2188  do {
2189  assert(type->isVariablyModifiedType());
2190 
2191  const Type *ty = type.getTypePtr();
2192  switch (ty->getTypeClass()) {
2193 
2194 #define TYPE(Class, Base)
2195 #define ABSTRACT_TYPE(Class, Base)
2196 #define NON_CANONICAL_TYPE(Class, Base)
2197 #define DEPENDENT_TYPE(Class, Base) case Type::Class:
2198 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base)
2199 #include "clang/AST/TypeNodes.inc"
2200  llvm_unreachable("unexpected dependent type!");
2201 
2202  // These types are never variably-modified.
2203  case Type::Builtin:
2204  case Type::Complex:
2205  case Type::Vector:
2206  case Type::ExtVector:
2207  case Type::ConstantMatrix:
2208  case Type::Record:
2209  case Type::Enum:
2210  case Type::Elaborated:
2211  case Type::Using:
2212  case Type::TemplateSpecialization:
2213  case Type::ObjCTypeParam:
2214  case Type::ObjCObject:
2215  case Type::ObjCInterface:
2216  case Type::ObjCObjectPointer:
2217  case Type::BitInt:
2218  llvm_unreachable("type class is never variably-modified!");
2219 
2220  case Type::Adjusted:
2221  type = cast<AdjustedType>(ty)->getAdjustedType();
2222  break;
2223 
2224  case Type::Decayed:
2225  type = cast<DecayedType>(ty)->getPointeeType();
2226  break;
2227 
2228  case Type::Pointer:
2229  type = cast<PointerType>(ty)->getPointeeType();
2230  break;
2231 
2232  case Type::BlockPointer:
2233  type = cast<BlockPointerType>(ty)->getPointeeType();
2234  break;
2235 
2236  case Type::LValueReference:
2237  case Type::RValueReference:
2238  type = cast<ReferenceType>(ty)->getPointeeType();
2239  break;
2240 
2241  case Type::MemberPointer:
2242  type = cast<MemberPointerType>(ty)->getPointeeType();
2243  break;
2244 
2245  case Type::ConstantArray:
2246  case Type::IncompleteArray:
2247  // Losing element qualification here is fine.
2248  type = cast<ArrayType>(ty)->getElementType();
2249  break;
2250 
2251  case Type::VariableArray: {
2252  // Losing element qualification here is fine.
2253  const VariableArrayType *vat = cast<VariableArrayType>(ty);
2254 
2255  // Unknown size indication requires no size computation.
2256  // Otherwise, evaluate and record it.
2257  if (const Expr *sizeExpr = vat->getSizeExpr()) {
2258  // It's possible that we might have emitted this already,
2259  // e.g. with a typedef and a pointer to it.
2260  llvm::Value *&entry = VLASizeMap[sizeExpr];
2261  if (!entry) {
2262  llvm::Value *size = EmitScalarExpr(sizeExpr);
2263 
2264  // C11 6.7.6.2p5:
2265  // If the size is an expression that is not an integer constant
2266  // expression [...] each time it is evaluated it shall have a value
2267  // greater than zero.
2268  if (SanOpts.has(SanitizerKind::VLABound)) {
2269  SanitizerScope SanScope(this);
2270  llvm::Value *Zero = llvm::Constant::getNullValue(size->getType());
2271  clang::QualType SEType = sizeExpr->getType();
2272  llvm::Value *CheckCondition =
2273  SEType->isSignedIntegerType()
2274  ? Builder.CreateICmpSGT(size, Zero)
2275  : Builder.CreateICmpUGT(size, Zero);
2276  llvm::Constant *StaticArgs[] = {
2277  EmitCheckSourceLocation(sizeExpr->getBeginLoc()),
2278  EmitCheckTypeDescriptor(SEType)};
2279  EmitCheck(std::make_pair(CheckCondition, SanitizerKind::VLABound),
2280  SanitizerHandler::VLABoundNotPositive, StaticArgs, size);
2281  }
2282 
2283  // Always zexting here would be wrong if it weren't
2284  // undefined behavior to have a negative bound.
2285  // FIXME: What about when size's type is larger than size_t?
2286  entry = Builder.CreateIntCast(size, SizeTy, /*signed*/ false);
2287  }
2288  }
2289  type = vat->getElementType();
2290  break;
2291  }
2292 
2293  case Type::FunctionProto:
2294  case Type::FunctionNoProto:
2295  type = cast<FunctionType>(ty)->getReturnType();
2296  break;
2297 
2298  case Type::Paren:
2299  case Type::TypeOf:
2300  case Type::UnaryTransform:
2301  case Type::Attributed:
2302  case Type::SubstTemplateTypeParm:
2303  case Type::MacroQualified:
2304  // Keep walking after single level desugaring.
2305  type = type.getSingleStepDesugaredType(getContext());
2306  break;
2307 
2308  case Type::Typedef:
2309  case Type::Decltype:
2310  case Type::Auto:
2311  case Type::DeducedTemplateSpecialization:
2312  // Stop walking: nothing to do.
2313  return;
2314 
2315  case Type::TypeOfExpr:
2316  // Stop walking: emit typeof expression.
2317  EmitIgnoredExpr(cast<TypeOfExprType>(ty)->getUnderlyingExpr());
2318  return;
2319 
2320  case Type::Atomic:
2321  type = cast<AtomicType>(ty)->getValueType();
2322  break;
2323 
2324  case Type::Pipe:
2325  type = cast<PipeType>(ty)->getElementType();
2326  break;
2327  }
2328  } while (type->isVariablyModifiedType());
2329 }
2330 
2332  if (getContext().getBuiltinVaListType()->isArrayType())
2333  return EmitPointerWithAlignment(E);
2334  return EmitLValue(E).getAddress(*this);
2335 }
2336 
2338  return EmitLValue(E).getAddress(*this);
2339 }
2340 
2342  const APValue &Init) {
2343  assert(Init.hasValue() && "Invalid DeclRefExpr initializer!");
2344  if (CGDebugInfo *Dbg = getDebugInfo())
2346  Dbg->EmitGlobalVariable(E->getDecl(), Init);
2347 }
2348 
2351  // At the moment, the only aggressive peephole we do in IR gen
2352  // is trunc(zext) folding, but if we add more, we can easily
2353  // extend this protection.
2354 
2355  if (!rvalue.isScalar()) return PeepholeProtection();
2356  llvm::Value *value = rvalue.getScalarVal();
2357  if (!isa<llvm::ZExtInst>(value)) return PeepholeProtection();
2358 
2359  // Just make an extra bitcast.
2360  assert(HaveInsertPoint());
2361  llvm::Instruction *inst = new llvm::BitCastInst(value, value->getType(), "",
2362  Builder.GetInsertBlock());
2363 
2364  PeepholeProtection protection;
2365  protection.Inst = inst;
2366  return protection;
2367 }
2368 
2370  if (!protection.Inst) return;
2371 
2372  // In theory, we could try to duplicate the peepholes now, but whatever.
2373  protection.Inst->eraseFromParent();
2374 }
2375 
2377  QualType Ty, SourceLocation Loc,
2378  SourceLocation AssumptionLoc,
2379  llvm::Value *Alignment,
2380  llvm::Value *OffsetValue) {
2381  if (Alignment->getType() != IntPtrTy)
2382  Alignment =
2383  Builder.CreateIntCast(Alignment, IntPtrTy, false, "casted.align");
2384  if (OffsetValue && OffsetValue->getType() != IntPtrTy)
2385  OffsetValue =
2386  Builder.CreateIntCast(OffsetValue, IntPtrTy, true, "casted.offset");
2387  llvm::Value *TheCheck = nullptr;
2388  if (SanOpts.has(SanitizerKind::Alignment)) {
2389  llvm::Value *PtrIntValue =
2390  Builder.CreatePtrToInt(PtrValue, IntPtrTy, "ptrint");
2391 
2392  if (OffsetValue) {
2393  bool IsOffsetZero = false;
2394  if (const auto *CI = dyn_cast<llvm::ConstantInt>(OffsetValue))
2395  IsOffsetZero = CI->isZero();
2396 
2397  if (!IsOffsetZero)
2398  PtrIntValue = Builder.CreateSub(PtrIntValue, OffsetValue, "offsetptr");
2399  }
2400 
2401  llvm::Value *Zero = llvm::ConstantInt::get(IntPtrTy, 0);
2402  llvm::Value *Mask =
2403  Builder.CreateSub(Alignment, llvm::ConstantInt::get(IntPtrTy, 1));
2404  llvm::Value *MaskedPtr = Builder.CreateAnd(PtrIntValue, Mask, "maskedptr");
2405  TheCheck = Builder.CreateICmpEQ(MaskedPtr, Zero, "maskcond");
2406  }
2407  llvm::Instruction *Assumption = Builder.CreateAlignmentAssumption(
2408  CGM.getDataLayout(), PtrValue, Alignment, OffsetValue);
2409 
2410  if (!SanOpts.has(SanitizerKind::Alignment))
2411  return;
2412  emitAlignmentAssumptionCheck(PtrValue, Ty, Loc, AssumptionLoc, Alignment,
2413  OffsetValue, TheCheck, Assumption);
2414 }
2415 
2417  const Expr *E,
2418  SourceLocation AssumptionLoc,
2419  llvm::Value *Alignment,
2420  llvm::Value *OffsetValue) {
2421  if (auto *CE = dyn_cast<CastExpr>(E))
2422  E = CE->getSubExprAsWritten();
2423  QualType Ty = E->getType();
2424  SourceLocation Loc = E->getExprLoc();
2425 
2426  emitAlignmentAssumption(PtrValue, Ty, Loc, AssumptionLoc, Alignment,
2427  OffsetValue);
2428 }
2429 
2430 llvm::Value *CodeGenFunction::EmitAnnotationCall(llvm::Function *AnnotationFn,
2431  llvm::Value *AnnotatedVal,
2432  StringRef AnnotationStr,
2433  SourceLocation Location,
2434  const AnnotateAttr *Attr) {
2436  AnnotatedVal,
2439  CGM.EmitAnnotationLineNo(Location),
2440  };
2441  if (Attr)
2442  Args.push_back(CGM.EmitAnnotationArgs(Attr));
2443  return Builder.CreateCall(AnnotationFn, Args);
2444 }
2445 
2447  assert(D->hasAttr<AnnotateAttr>() && "no annotate attribute");
2448  // FIXME We create a new bitcast for every annotation because that's what
2449  // llvm-gcc was doing.
2450  for (const auto *I : D->specific_attrs<AnnotateAttr>())
2451  EmitAnnotationCall(CGM.getIntrinsic(llvm::Intrinsic::var_annotation),
2452  Builder.CreateBitCast(V, CGM.Int8PtrTy, V->getName()),
2453  I->getAnnotation(), D->getLocation(), I);
2454 }
2455 
2457  Address Addr) {
2458  assert(D->hasAttr<AnnotateAttr>() && "no annotate attribute");
2459  llvm::Value *V = Addr.getPointer();
2460  llvm::Type *VTy = V->getType();
2461  auto *PTy = dyn_cast<llvm::PointerType>(VTy);
2462  unsigned AS = PTy ? PTy->getAddressSpace() : 0;
2463  llvm::PointerType *IntrinTy =
2464  llvm::PointerType::getWithSamePointeeType(CGM.Int8PtrTy, AS);
2465  llvm::Function *F =
2466  CGM.getIntrinsic(llvm::Intrinsic::ptr_annotation, IntrinTy);
2467 
2468  for (const auto *I : D->specific_attrs<AnnotateAttr>()) {
2469  // FIXME Always emit the cast inst so we can differentiate between
2470  // annotation on the first field of a struct and annotation on the struct
2471  // itself.
2472  if (VTy != IntrinTy)
2473  V = Builder.CreateBitCast(V, IntrinTy);
2474  V = EmitAnnotationCall(F, V, I->getAnnotation(), D->getLocation(), I);
2475  V = Builder.CreateBitCast(V, VTy);
2476  }
2477 
2478  return Address(V, Addr.getAlignment());
2479 }
2480 
2482 
2484  : CGF(CGF) {
2485  assert(!CGF->IsSanitizerScope);
2486  CGF->IsSanitizerScope = true;
2487 }
2488 
2490  CGF->IsSanitizerScope = false;
2491 }
2492 
2493 void CodeGenFunction::InsertHelper(llvm::Instruction *I,
2494  const llvm::Twine &Name,
2495  llvm::BasicBlock *BB,
2496  llvm::BasicBlock::iterator InsertPt) const {
2498  if (IsSanitizerScope)
2500 }
2501 
2503  llvm::Instruction *I, const llvm::Twine &Name, llvm::BasicBlock *BB,
2504  llvm::BasicBlock::iterator InsertPt) const {
2505  llvm::IRBuilderDefaultInserter::InsertHelper(I, Name, BB, InsertPt);
2506  if (CGF)
2507  CGF->InsertHelper(I, Name, BB, InsertPt);
2508 }
2509 
2510 // Emits an error if we don't have a valid set of target features for the
2511 // called function.
2513  const FunctionDecl *TargetDecl) {
2514  return checkTargetFeatures(E->getBeginLoc(), TargetDecl);
2515 }
2516 
2517 // Emits an error if we don't have a valid set of target features for the
2518 // called function.
2520  const FunctionDecl *TargetDecl) {
2521  // Early exit if this is an indirect call.
2522  if (!TargetDecl)
2523  return;
2524 
2525  // Get the current enclosing function if it exists. If it doesn't
2526  // we can't check the target features anyhow.
2527  const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CurCodeDecl);
2528  if (!FD)
2529  return;
2530 
2531  // Grab the required features for the call. For a builtin this is listed in
2532  // the td file with the default cpu, for an always_inline function this is any
2533  // listed cpu and any listed features.
2534  unsigned BuiltinID = TargetDecl->getBuiltinID();
2535  std::string MissingFeature;
2536  llvm::StringMap<bool> CallerFeatureMap;
2537  CGM.getContext().getFunctionFeatureMap(CallerFeatureMap, FD);
2538  if (BuiltinID) {
2539  StringRef FeatureList(
2541  // Return if the builtin doesn't have any required features.
2542  if (FeatureList.empty())
2543  return;
2544  assert(!FeatureList.contains(' ') && "Space in feature list");
2545  TargetFeatures TF(CallerFeatureMap);
2546  if (!TF.hasRequiredFeatures(FeatureList))
2547  CGM.getDiags().Report(Loc, diag::err_builtin_needs_feature)
2548  << TargetDecl->getDeclName() << FeatureList;
2549  } else if (!TargetDecl->isMultiVersion() &&
2550  TargetDecl->hasAttr<TargetAttr>()) {
2551  // Get the required features for the callee.
2552 
2553  const TargetAttr *TD = TargetDecl->getAttr<TargetAttr>();
2556 
2557  SmallVector<StringRef, 1> ReqFeatures;
2558  llvm::StringMap<bool> CalleeFeatureMap;
2559  CGM.getContext().getFunctionFeatureMap(CalleeFeatureMap, TargetDecl);
2560 
2561  for (const auto &F : ParsedAttr.Features) {
2562  if (F[0] == '+' && CalleeFeatureMap.lookup(F.substr(1)))
2563  ReqFeatures.push_back(StringRef(F).substr(1));
2564  }
2565 
2566  for (const auto &F : CalleeFeatureMap) {
2567  // Only positive features are "required".
2568  if (F.getValue())
2569  ReqFeatures.push_back(F.getKey());
2570  }
2571  if (!llvm::all_of(ReqFeatures, [&](StringRef Feature) {
2572  if (!CallerFeatureMap.lookup(Feature)) {
2573  MissingFeature = Feature.str();
2574  return false;
2575  }
2576  return true;
2577  }))
2578  CGM.getDiags().Report(Loc, diag::err_function_needs_feature)
2579  << FD->getDeclName() << TargetDecl->getDeclName() << MissingFeature;
2580  }
2581 }
2582 
2583 void CodeGenFunction::EmitSanitizerStatReport(llvm::SanitizerStatKind SSK) {
2584  if (!CGM.getCodeGenOpts().SanitizeStats)
2585  return;
2586 
2587  llvm::IRBuilder<> IRB(Builder.GetInsertBlock(), Builder.GetInsertPoint());
2588  IRB.SetCurrentDebugLocation(Builder.getCurrentDebugLocation());
2589  CGM.getSanStats().create(IRB, SSK);
2590 }
2591 
2592 llvm::Value *
2593 CodeGenFunction::FormResolverCondition(const MultiVersionResolverOption &RO) {
2594  llvm::Value *Condition = nullptr;
2595 
2596  if (!RO.Conditions.Architecture.empty())
2597  Condition = EmitX86CpuIs(RO.Conditions.Architecture);
2598 
2599  if (!RO.Conditions.Features.empty()) {
2600  llvm::Value *FeatureCond = EmitX86CpuSupports(RO.Conditions.Features);
2601  Condition =
2602  Condition ? Builder.CreateAnd(Condition, FeatureCond) : FeatureCond;
2603  }
2604  return Condition;
2605 }
2606 
2608  llvm::Function *Resolver,
2610  llvm::Function *FuncToReturn,
2611  bool SupportsIFunc) {
2612  if (SupportsIFunc) {
2613  Builder.CreateRet(FuncToReturn);
2614  return;
2615  }
2616 
2618  llvm::for_each(Resolver->args(),
2619  [&](llvm::Argument &Arg) { Args.push_back(&Arg); });
2620 
2621  llvm::CallInst *Result = Builder.CreateCall(FuncToReturn, Args);
2622  Result->setTailCallKind(llvm::CallInst::TCK_MustTail);
2623 
2624  if (Resolver->getReturnType()->isVoidTy())
2625  Builder.CreateRetVoid();
2626  else
2627  Builder.CreateRet(Result);
2628 }
2629 
2631  llvm::Function *Resolver, ArrayRef<MultiVersionResolverOption> Options) {
2632  assert(getContext().getTargetInfo().getTriple().isX86() &&
2633  "Only implemented for x86 targets");
2634 
2635  bool SupportsIFunc = getContext().getTargetInfo().supportsIFunc();
2636 
2637  // Main function's basic block.
2638  llvm::BasicBlock *CurBlock = createBasicBlock("resolver_entry", Resolver);
2639  Builder.SetInsertPoint(CurBlock);
2640  EmitX86CpuInit();
2641 
2642  for (const MultiVersionResolverOption &RO : Options) {
2643  Builder.SetInsertPoint(CurBlock);
2644  llvm::Value *Condition = FormResolverCondition(RO);
2645 
2646  // The 'default' or 'generic' case.
2647  if (!Condition) {
2648  assert(&RO == Options.end() - 1 &&
2649  "Default or Generic case must be last");
2650  CreateMultiVersionResolverReturn(CGM, Resolver, Builder, RO.Function,
2651  SupportsIFunc);
2652  return;
2653  }
2654 
2655  llvm::BasicBlock *RetBlock = createBasicBlock("resolver_return", Resolver);
2656  CGBuilderTy RetBuilder(*this, RetBlock);
2657  CreateMultiVersionResolverReturn(CGM, Resolver, RetBuilder, RO.Function,
2658  SupportsIFunc);
2659  CurBlock = createBasicBlock("resolver_else", Resolver);
2660  Builder.CreateCondBr(Condition, RetBlock, CurBlock);
2661  }
2662 
2663  // If no generic/default, emit an unreachable.
2664  Builder.SetInsertPoint(CurBlock);
2665  llvm::CallInst *TrapCall = EmitTrapCall(llvm::Intrinsic::trap);
2666  TrapCall->setDoesNotReturn();
2667  TrapCall->setDoesNotThrow();
2668  Builder.CreateUnreachable();
2669  Builder.ClearInsertionPoint();
2670 }
2671 
2672 // Loc - where the diagnostic will point, where in the source code this
2673 // alignment has failed.
2674 // SecondaryLoc - if present (will be present if sufficiently different from
2675 // Loc), the diagnostic will additionally point a "Note:" to this location.
2676 // It should be the location where the __attribute__((assume_aligned))
2677 // was written e.g.
2679  llvm::Value *Ptr, QualType Ty, SourceLocation Loc,
2680  SourceLocation SecondaryLoc, llvm::Value *Alignment,
2681  llvm::Value *OffsetValue, llvm::Value *TheCheck,
2682  llvm::Instruction *Assumption) {
2683  assert(Assumption && isa<llvm::CallInst>(Assumption) &&
2684  cast<llvm::CallInst>(Assumption)->getCalledOperand() ==
2685  llvm::Intrinsic::getDeclaration(
2686  Builder.GetInsertBlock()->getParent()->getParent(),
2687  llvm::Intrinsic::assume) &&
2688  "Assumption should be a call to llvm.assume().");
2689  assert(&(Builder.GetInsertBlock()->back()) == Assumption &&
2690  "Assumption should be the last instruction of the basic block, "
2691  "since the basic block is still being generated.");
2692 
2693  if (!SanOpts.has(SanitizerKind::Alignment))
2694  return;
2695 
2696  // Don't check pointers to volatile data. The behavior here is implementation-
2697  // defined.
2698  if (Ty->getPointeeType().isVolatileQualified())
2699  return;
2700 
2701  // We need to temorairly remove the assumption so we can insert the
2702  // sanitizer check before it, else the check will be dropped by optimizations.
2703  Assumption->removeFromParent();
2704 
2705  {
2706  SanitizerScope SanScope(this);
2707 
2708  if (!OffsetValue)
2709  OffsetValue = Builder.getInt1(false); // no offset.
2710 
2711  llvm::Constant *StaticData[] = {EmitCheckSourceLocation(Loc),
2712  EmitCheckSourceLocation(SecondaryLoc),
2714  llvm::Value *DynamicData[] = {EmitCheckValue(Ptr),
2715  EmitCheckValue(Alignment),
2716  EmitCheckValue(OffsetValue)};
2717  EmitCheck({std::make_pair(TheCheck, SanitizerKind::Alignment)},
2718  SanitizerHandler::AlignmentAssumption, StaticData, DynamicData);
2719  }
2720 
2721  // We are now in the (new, empty) "cont" basic block.
2722  // Reintroduce the assumption.
2723  Builder.Insert(Assumption);
2724  // FIXME: Assumption still has it's original basic block as it's Parent.
2725 }
2726 
2728  if (CGDebugInfo *DI = getDebugInfo())
2729  return DI->SourceLocToDebugLoc(Location);
2730 
2731  return llvm::DebugLoc();
2732 }
2733 
2734 llvm::Value *
2735 CodeGenFunction::emitCondLikelihoodViaExpectIntrinsic(llvm::Value *Cond,
2736  Stmt::Likelihood LH) {
2737  switch (LH) {
2738  case Stmt::LH_None:
2739  return Cond;
2740  case Stmt::LH_Likely:
2741  case Stmt::LH_Unlikely:
2742  // Don't generate llvm.expect on -O0 as the backend won't use it for
2743  // anything.
2744  if (CGM.getCodeGenOpts().OptimizationLevel == 0)
2745  return Cond;
2746  llvm::Type *CondTy = Cond->getType();
2747  assert(CondTy->isIntegerTy(1) && "expecting condition to be a boolean");
2748  llvm::Function *FnExpect =
2749  CGM.getIntrinsic(llvm::Intrinsic::expect, CondTy);
2750  llvm::Value *ExpectedValueOfCond =
2751  llvm::ConstantInt::getBool(CondTy, LH == Stmt::LH_Likely);
2752  return Builder.CreateCall(FnExpect, {Cond, ExpectedValueOfCond},
2753  Cond->getName() + ".expval");
2754  }
2755  llvm_unreachable("Unknown Likelihood");
2756 }
clang::OpenCL
@ OpenCL
Definition: LangStandard.h:58
clang::CXXMethodDecl::getThisType
QualType getThisType() const
Return the type of the this pointer.
Definition: DeclCXX.cpp:2453
clang::InternalLinkage
@ InternalLinkage
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
Definition: Linkage.h:31
clang::Language::CUDA
@ CUDA
clang::CodeGen::CodeGenFunction::SanitizerScope
RAII object to set/unset CodeGenFunction::IsSanitizerScope.
Definition: CodeGenFunction.h:523
clang::CodeGen::CodeGenFunction::ConvertTypeForMem
llvm::Type * ConvertTypeForMem(QualType T)
Definition: CodeGenFunction.cpp:208
clang::ASTContext::getTypeSizeInChars
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
Definition: ASTContext.cpp:2453
clang::Type::getNullability
Optional< NullabilityKind > getNullability(const ASTContext &context) const
Determine the nullability of the given type.
Definition: Type.cpp:4056
clang::CharUnits::isOne
bool isOne() const
isOne - Test whether the quantity equals one.
Definition: CharUnits.h:119
clang::CodeGen::CodeGenFunction::ShouldXRayInstrumentFunction
bool ShouldXRayInstrumentFunction() const
ShouldXRayInstrument - Return true if the current function should be instrumented with XRay nop sleds...
Definition: CodeGenFunction.cpp:543
Builtins.h
clang::CodeGen::CGBuilderTy::CreateMemCpy
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
Definition: CGBuilder.h:312
clang::CodeGen::CodeGenFunction::EmitAnnotationCall
llvm::Value * EmitAnnotationCall(llvm::Function *AnnotationFn, llvm::Value *AnnotatedVal, StringRef AnnotationStr, SourceLocation Location, const AnnotateAttr *Attr)
Emit an annotation call (intrinsic).
Definition: CodeGenFunction.cpp:2430
clang::CodeGen::CodeGenFunction::emitAlignmentAssumptionCheck
void emitAlignmentAssumptionCheck(llvm::Value *Ptr, QualType Ty, SourceLocation Loc, SourceLocation AssumptionLoc, llvm::Value *Alignment, llvm::Value *OffsetValue, llvm::Value *TheCheck, llvm::Instruction *Assumption)
Definition: CodeGenFunction.cpp:2678
clang::CodeGen::CodeGenTypeCache::SizeTy
llvm::IntegerType * SizeTy
Definition: CodeGenTypeCache.h:50
max
__DEVICE__ int max(int __a, int __b)
Definition: __clang_cuda_math.h:196
clang::Decl::getASTContext
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:414
matchesStlAllocatorFn
static bool matchesStlAllocatorFn(const Decl *D, const ASTContext &Ctx)
Definition: CodeGenFunction.cpp:680
clang::isLambdaCallOperator
bool isLambdaCallOperator(const CXXMethodDecl *MD)
Definition: ASTLambda.h:27
clang::CodeGen::CodeGenFunction::EmitTrapCall
llvm::CallInst * EmitTrapCall(llvm::Intrinsic::ID IntrID)
Emit a call to trap or debugtrap and attach function attribute "trap-func-name" if specified.
Definition: CGExpr.cpp:3521
clang::FunctionDecl::isDefaulted
bool isDefaulted() const
Whether this function is defaulted.
Definition: Decl.h:2214
clang::CodeGen::CodeGenFunction::EmitLambdaStaticInvokeBody
void EmitLambdaStaticInvokeBody(const CXXMethodDecl *MD)
Definition: CGClass.cpp:2960
clang::CodeGen::LValueBaseInfo
Definition: CGValue.h:154
clang::CodeGen::CodeGenFunction::getProfileCount
uint64_t getProfileCount(const Stmt *S)
Get the profiler's count for the given statement.
Definition: CodeGenFunction.h:1525
clang::CodeGen::CodeGenFunction::EmitFunctionEpilog
void EmitFunctionEpilog(const CGFunctionInfo &FI, bool EmitRetDbgLoc, SourceLocation EndLoc)
EmitFunctionEpilog - Emit the target specific LLVM code to return the given temporary.
Definition: CGCall.cpp:3414
clang::CodeGen::CodeGenTypeCache::Int8PtrTy
llvm::PointerType * Int8PtrTy
Definition: CodeGenTypeCache.h:57
getPrologueSignature
static llvm::Constant * getPrologueSignature(CodeGenModule &CGM, const FunctionDecl *FD)
Return the UBSan prologue signature for FD if one is available.
Definition: CodeGenFunction.cpp:701
llvm
YAML serialization mapping.
Definition: Dominators.h:30
clang::CXXConstructorDecl
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2400
clang::CodeGen::CodeGenFunction::EmitEndEHSpec
void EmitEndEHSpec(const Decl *D)
EmitEndEHSpec - Emit the end of the exception spec.
Definition: CGException.cpp:569
clang::CodeGen::CodeGenFunction::EmitNullInitialization
void EmitNullInitialization(Address DestPtr, QualType Ty)
EmitNullInitialization - Generate code to set a value of the given type to null, If the type contains...
Definition: CodeGenFunction.cpp:1943
clang::CodeGen::CodeGenFunction::markAsIgnoreThreadCheckingAtRuntime
void markAsIgnoreThreadCheckingAtRuntime(llvm::Function *Fn)
Annotate the function with an attribute that disables TSan checking at runtime.
Definition: CodeGenFunction.cpp:666
clang::CharUnits::getAsAlign
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
Definition: CharUnits.h:183
clang::interp::APInt
llvm::APInt APInt
Definition: Integral.h:27
clang::CodeGen::CodeGenModule::EmitNullConstant
llvm::Constant * EmitNullConstant(QualType T)
Return the result of value-initializing the given type, i.e.
Definition: CGExprConstant.cpp:2311
clang::CharUnits::alignmentOfArrayElement
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
Definition: CharUnits.h:201
clang::CodeGen::TEK_Aggregate
@ TEK_Aggregate
Definition: CodeGenFunction.h:109
clang::CodeGen::CodeGenFunction::getJumpDestForLabel
JumpDest getJumpDestForLabel(const LabelDecl *S)
getBasicBlockForLabel - Return the LLVM basicblock that the specified label maps to.
Definition: CGStmt.cpp:587
clang::CodeGen::RValue
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
Definition: CGValue.h:39
type
clang::CodeGen::CodeGenFunction::ConstantFoldsToSimpleInteger
bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result, bool AllowLabels=false)
ConstantFoldsToSimpleInteger - If the specified expression does not fold to a constant,...
Definition: CodeGenFunction.cpp:1548
clang::FunctionDecl::getReturnType
QualType getReturnType() const
Definition: Decl.h:2540
clang::CodeGen::CodeGenFunction::EmitCheckSourceLocation
llvm::Constant * EmitCheckSourceLocation(SourceLocation Loc)
Emit a description of a source location in a format suitable for passing to a runtime sanitizer handl...
Definition: CGExpr.cpp:3068
clang::CodeGen::CodeGenFunction::AutoreleaseResult
bool AutoreleaseResult
In ARC, whether we should autorelease the return value.
Definition: CodeGenFunction.h:535
clang::CodeGen::ABIArgInfo::getKind
Kind getKind() const
Definition: CGFunctionInfo.h:295
clang::CallExpr::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:1568
clang::Type::isObjCRetainableType
bool isObjCRetainableType() const
Definition: Type.cpp:4302
clang::ento::Nullability
Nullability
Definition: CheckerHelpers.h:55
CodeGenFunction.h
clang::CodeGen::CodeGenFunction::EmitFunctionProlog
void EmitFunctionProlog(const CGFunctionInfo &FI, llvm::Function *Fn, const FunctionArgList &Args)
EmitFunctionProlog - Emit the target specific LLVM code to load the arguments for the given function.
Definition: CGCall.cpp:2594
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:210
clang::CodeGen::CodeGenFunction::MakeNaturalAlignPointeeAddrLValue
LValue MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T)
Given a value of type T* that may not be to a complete object, construct an l-value with the natural ...
Definition: CodeGenFunction.cpp:198
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::ASTContext::getFunctionFeatureMap
void getFunctionFeatureMap(llvm::StringMap< bool > &FeatureMap, const FunctionDecl *) const
Definition: ASTContext.cpp:11806
clang::Decl::hasAttr
bool hasAttr() const
Definition: DeclBase.h:541
clang::CodeGen::CodeGenFunction::LambdaCaptureFields
llvm::DenseMap< const VarDecl *, FieldDecl * > LambdaCaptureFields
Definition: CodeGenFunction.h:605
clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope
Address EmitCompoundStmtWithoutScope(const CompoundStmt &S, bool GetLast=false, AggValueSlot AVS=AggValueSlot::ignored())
Definition: CGStmt.cpp:458
clang::XRayInstrKind::FunctionEntry
constexpr XRayInstrMask FunctionEntry
Definition: XRayInstr.h:39
clang::XRayInstrSet::Mask
XRayInstrMask Mask
Definition: XRayInstr.h:65
clang::CodeGen::CodeGenFunction::CurCodeDecl
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
Definition: CodeGenFunction.h:321
clang::CodeGen::CodeGenFunction::EmitBranchToCounterBlock
void EmitBranchToCounterBlock(const Expr *Cond, BinaryOperator::Opcode LOp, llvm::BasicBlock *TrueBlock, llvm::BasicBlock *FalseBlock, uint64_t TrueCount=0, Stmt::Likelihood LH=Stmt::LH_None, const Expr *CntrIdx=nullptr)
EmitBranchToCounterBlock - Emit a conditional branch to a new block that increments a profile counter...
Definition: CodeGenFunction.cpp:1596
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:118
clang::CodeGen::CodeGenFunction::EmitMultiVersionResolver
void EmitMultiVersionResolver(llvm::Function *Resolver, ArrayRef< MultiVersionResolverOption > Options)
Definition: CodeGenFunction.cpp:2630
clang::CodeGen::CodeGenFunction::ShouldInstrumentFunction
bool ShouldInstrumentFunction()
ShouldInstrumentFunction - Return true if the current function should be instrumented with __cyg_prof...
Definition: CodeGenFunction.cpp:525
clang::CodeGen::Address::getAlignment
CharUnits getAlignment() const
Return the alignment of this pointer.
Definition: Address.h:78
clang::CodeGen::CodeGenFunction::AlwaysEmitXRayTypedEvents
bool AlwaysEmitXRayTypedEvents() const
AlwaysEmitXRayTypedEvents - Return true if clang must unconditionally emit XRay typed event handling ...
Definition: CodeGenFunction.cpp:556
llvm::SmallVector
Definition: LLVM.h:38
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::CodeGen::CodeGenFunction::setCurrentProfileCount
void setCurrentProfileCount(uint64_t Count)
Set the profiler's current count.
Definition: CodeGenFunction.h:1533
clang::DiagnosticsEngine::isIgnored
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
Definition: Diagnostic.h:909
clang::CodeGen::CodeGenFunction::PrologueCleanupDepth
EHScopeStack::stable_iterator PrologueCleanupDepth
PrologueCleanupDepth - The cleanup depth enclosing all the cleanups associated with the parameters.
Definition: CodeGenFunction.h:348
clang::CodeGen::CGCXXABI::getMangleContext
MangleContext & getMangleContext()
Gets the mangle context.
Definition: CGCXXABI.h:108
clang::CodeGen::LValue::getAddress
Address getAddress(CodeGenFunction &CGF) const
Definition: CGValue.h:341
clang::CodeGen::CodeGenFunction::EmitDestructorBody
void EmitDestructorBody(FunctionArgList &Args)
EmitDestructorBody - Emits the body of the current destructor.
Definition: CGClass.cpp:1436
clang::ASTContext::BuiltinInfo
Builtin::Context & BuiltinInfo
Definition: ASTContext.h:648
clang::SourceRange::getBegin
SourceLocation getBegin() const
Definition: SourceLocation.h:219
clang::LangOptions::FPE_MayTrap
@ FPE_MayTrap
Transformations do not cause new exceptions but may hide some.
Definition: LangOptions.h:229
CodeGenPGO.h
TargetInfo.h
clang::MultiVersionKind::Target
@ Target
clang::CodeGen::CodeGenFunction::emitArrayLength
llvm::Value * emitArrayLength(const ArrayType *arrayType, QualType &baseType, Address &addr)
emitArrayLength - Compute the length of an array, even if it's a VLA, and drill down to the base elem...
Definition: CodeGenFunction.cpp:2044
clang::CodeGen::CodeGenModule::getSize
llvm::ConstantInt * getSize(CharUnits numChars)
Emit the given number of characters as a value of type size_t.
Definition: CodeGenModule.cpp:1027
clang::ParsedTargetAttr
Contains information gathered from parsing the contents of TargetAttr.
Definition: Attr.h:351
clang::CodeGen::CodeGenTypeCache::getPointerAlign
CharUnits getPointerAlign() const
Definition: CodeGenTypeCache.h:117
clang::CodeGen::CodeGenFunction::checkIfFunctionMustProgress
bool checkIfFunctionMustProgress()
Returns true if a function must make progress, which means the mustprogress attribute can be added.
Definition: CodeGenFunction.h:560
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:674
Attr.h
clang::CodeGenOptions::hasSanitizeCoverage
bool hasSanitizeCoverage() const
Definition: CodeGenOptions.h:472
clang::EST_None
@ EST_None
no exception specification
Definition: ExceptionSpecificationType.h:21
clang::CodeGen::SanitizerMetadata::disableSanitizerForInstruction
void disableSanitizerForInstruction(llvm::Instruction *I)
Definition: SanitizerMetadata.cpp:87
clang::SanitizerSet::has
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
Definition: Sanitizers.h:155
clang::CodeGen::CodeGenModule::getContext
ASTContext & getContext() const
Definition: CodeGenModule.h:692
clang::SanitizerSet::hasOneOf
bool hasOneOf(SanitizerMask K) const
Check if one or more sanitizers are enabled.
Definition: Sanitizers.h:161
clang::FieldDecl
Represents a member of a struct/union/class.
Definition: Decl.h:2838
clang::CodeGen::Address::isValid
bool isValid() const
Definition: Address.h:49
clang::ASTContext::getBaseElementType
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
Definition: ASTContext.cpp:6372
clang::CodeGen::CodeGenFunction::MultiVersionResolverOption
Definition: CodeGenFunction.h:4757
clang::CodeGen::ABIArgInfo::isSRetAfterThis
bool isSRetAfterThis() const
Definition: CGFunctionInfo.h:426
clang::CodeGen::CodeGenFunction::EmitLValueForLambdaField
LValue EmitLValueForLambdaField(const FieldDecl *Field)
Given that we are currently emitting a lambda, emit an l-value for one of its members.
Definition: CGExpr.cpp:4190
clang::ParmVarDecl
Represents a parameter to a function.
Definition: Decl.h:1663
DeclCXX.h
clang::CodeGenOptions::SampleProfileFile
std::string SampleProfileFile
Name of the profile file to use with -fprofile-sample-use.
Definition: CodeGenOptions.h:251
clang::CodeGen::EHScopeStack::containsOnlyLifetimeMarkers
bool containsOnlyLifetimeMarkers(stable_iterator Old) const
Definition: CGCleanup.cpp:141
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:2421
clang::CodeGen::TargetFeatures
TargetFeatures - This class is used to check whether the builtin function has the required tagert spe...
Definition: CodeGenFunction.h:4808
clang::CodeGen::CodeGenFunction::emitImplicitAssignmentOperatorBody
void emitImplicitAssignmentOperatorBody(FunctionArgList &Args)
Definition: CGClass.cpp:1549
clang::CodeGen::CGBuilderTy::CreateStore
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
Definition: CGBuilder.h:96
clang::FunctionDecl::hasImplicitReturnZero
bool hasImplicitReturnZero() const
Whether falling off this function implicitly returns null/zero.
Definition: Decl.h:2240
llvm::Optional
Definition: LLVM.h:40
clang::UnaryOperator
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2163
clang::CodeGen::CodeGenFunction::protectFromPeepholes
PeepholeProtection protectFromPeepholes(RValue rvalue)
protectFromPeepholes - Protect a value that we're intending to store to the side, but which will prob...
Definition: CodeGenFunction.cpp:2350
clang::FunctionDecl::UsesFPIntrin
bool UsesFPIntrin() const
Determine whether the function was declared in source context that requires constrained FP intrinsics...
Definition: Decl.h:2604
clang::CodeGen::CodeGenModule::getLangOpts
const LangOptions & getLangOpts() const
Definition: CodeGenModule.h:693
clang::CodeGen::CodeGenFunction::mightAddDeclToScope
static bool mightAddDeclToScope(const Stmt *S)
Determine if the given statement might introduce a declaration into the current scope,...
Definition: CodeGenFunction.cpp:1522
clang::Type::isVoidType
bool isVoidType() const
Definition: Type.h:6981
clang::QualType::isVolatileQualified
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition: Type.h:6520
clang::CodeGen::CodeGenFunction::HaveInsertPoint
bool HaveInsertPoint() const
HaveInsertPoint - True if an insertion point is defined.
Definition: CodeGenFunction.h:2462
clang::Decl::getAttr
T * getAttr() const
Definition: DeclBase.h:537
ASTLambda.h
clang::diag::Group
Group
Definition: DiagnosticCategories.h:23
clang::CodeGen::CodeGenModule::getTargetCodeGenInfo
const TargetCodeGenInfo & getTargetCodeGenInfo()
Definition: TargetInfo.cpp:11189
clang::CodeGen::LoopInfoStack::InsertHelper
void InsertHelper(llvm::Instruction *I) const
Function called by the CodeGenFunction when an instruction is created.
Definition: CGLoopInfo.cpp:810
clang::CodeGen::CGBuilderTy
Definition: CGBuilder.h:43
clang::CodeGen::CGBuilderTy::CreateStructGEP
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name="")
Definition: CGBuilder.h:192
clang::CodeGen::CodeGenFunction::EmitStmt
void EmitStmt(const Stmt *S, ArrayRef< const Attr * > Attrs=None)
EmitStmt - Emit the code for the statement.
Definition: CGStmt.cpp:53
clang::Expr::IgnoreImpCasts
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:2913
clang::CodeGen::CodeGenFunction::JumpDest::getBlock
llvm::BasicBlock * getBlock() const
Definition: CodeGenFunction.h:245
clang::CodeGen::CGFunctionInfo::getReturnType
CanQualType getReturnType() const
Definition: CGFunctionInfo.h:706
clang::TargetInfo::getVScaleRange
virtual Optional< std::pair< unsigned, unsigned > > getVScaleRange(const LangOptions &LangOpts) const
Returns target-specific min and max values VScale_Range.
Definition: TargetInfo.h:904
clang::CodeGen::CodeGenFunction::Builder
CGBuilderTy Builder
Definition: CodeGenFunction.h:268
clang::CodeGen::CodeGenModule::EmitAnnotationUnit
llvm::Constant * EmitAnnotationUnit(SourceLocation Loc)
Emit the annotation's translation unit.
Definition: CodeGenModule.cpp:2595
CGDebugInfo.h
clang::CodeGen::CodeGenTypes::ConvertType
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
Definition: CodeGenTypes.cpp:395
Paren
@ Paren
Definition: PPMacroExpansion.cpp:630
clang::CodeGen::CGBuilderTy::CreateBitCast
Address CreateBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Definition: CGBuilder.h:154
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1491
clang::CodeGen::CodeGenFunction::InsertHelper
void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name, llvm::BasicBlock *BB, llvm::BasicBlock::iterator InsertPt) const
CGBuilder insert helper.
Definition: CodeGenFunction.cpp:2493
Decl.h
clang::ConditionalOperator
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:4147
clang::CodeGen::CodeGenFunction::NormalCleanupDest
Address NormalCleanupDest
i32s containing the indexes of the cleanup destinations.
Definition: CodeGenFunction.h:648
clang::CXXThrowExpr
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:1181
clang::CodeGen::CodeGenFunction::AlwaysEmitXRayCustomEvents
bool AlwaysEmitXRayCustomEvents() const
AlwaysEmitXRayCustomEvents - Return true if we must unconditionally emit XRay custom event handling c...
Definition: CodeGenFunction.cpp:549
Offset
unsigned Offset
Definition: Format.cpp:2431
clang::CodeGen::CodeGenModule::getOpenMPRuntime
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
Definition: CodeGenModule.h:606
clang::SanitizerSet::Mask
SanitizerMask Mask
Bitmask of enabled sanitizers.
Definition: Sanitizers.h:176
clang::CodeGen::CodeGenFunction::EmitVariablyModifiedType
void EmitVariablyModifiedType(QualType Ty)
EmitVLASize - Capture all the sizes for the VLA expressions in the given variably-modified type and s...
Definition: CodeGenFunction.cpp:2180
clang::GlobalDecl
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:56
clang::CodeGen::CodeGenFunction::GenerateCode
void GenerateCode(GlobalDecl GD, llvm::Function *Fn, const CGFunctionInfo &FnInfo)
Definition: CodeGenFunction.cpp:1308
clang::CodeGen::TypeEvaluationKind
TypeEvaluationKind
The kind of evaluation to perform on values of a particular type.
Definition: CodeGenFunction.h:106
clang::CodeGen::CodeGenFunction::EmitSanitizerStatReport
void EmitSanitizerStatReport(llvm::SanitizerStatKind SSK)
Definition: CodeGenFunction.cpp:2583
CodeGenOptions.h
APSInt
llvm::APSInt APSInt
Definition: ByteCodeEmitter.cpp:19
clang::CodeGen::LValue::MakeAddr
static LValue MakeAddr(Address address, QualType type, ASTContext &Context, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
Definition: CGValue.h:402
clang::CodeGen::CodeGenTypes::ConvertTypeForMem
llvm::Type * ConvertTypeForMem(QualType T, bool ForBitField=false)
ConvertTypeForMem - Convert type T into a llvm::Type.
Definition: CodeGenTypes.cpp:90
clang::IdentifierInfo::isStr
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
Definition: IdentifierTable.h:176
clang::CodeGen::CodeGenModule::isProfileInstrExcluded
bool isProfileInstrExcluded(llvm::Function *Fn, SourceLocation Loc) const
Returns true if function at the given location should be excluded from profile instrumentation.
Definition: CodeGenModule.cpp:2757
clang::CodeGen::CodeGenFunction::CreateDefaultAlignTempAlloca
Address CreateDefaultAlignTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
CreateDefaultAlignedTempAlloca - This creates an alloca with the default ABI alignment of the given L...
Definition: CGExpr.cpp:123
clang::CodeGen::CodeGenModule::MayDropFunctionReturn
bool MayDropFunctionReturn(const ASTContext &Context, QualType ReturnType)
Whether this function's return type has no side effects, and thus may be trivially discarded if it is...
Definition: CGCall.cpp:1764
clang::CodeGen::CGOpenMPRuntime::emitFunctionProlog
virtual void emitFunctionProlog(CodeGenFunction &CGF, const Decl *D)
Emits OpenMP-specific function prolog.
Definition: CGOpenMPRuntime.cpp:12207
clang::CodeGen::CGCXXABI::buildThisParam
void buildThisParam(CodeGenFunction &CGF, FunctionArgList &Params)
Build a parameter variable suitable for 'this'.
Definition: CGCXXABI.cpp:122
clang::CodeGen::CodeGenFunction::IsSanitizerScope
bool IsSanitizerScope
True if CodeGen currently emits code implementing sanitizer checks.
Definition: CodeGenFunction.h:520
V
#define V(N, I)
Definition: ASTContext.h:3127
clang::CodeGen::CodeGenFunction::CGFPOptionsRAII::~CGFPOptionsRAII
~CGFPOptionsRAII()
Definition: CodeGenFunction.cpp:181
clang::CodeGen::CGOpenMPRuntime::getOMPBuilder
llvm::OpenMPIRBuilder & getOMPBuilder()
Definition: CGOpenMPRuntime.h:300
clang::CodeGen::CodeGenTypeCache
This structure provides a set of types that are commonly used during IR emission.
Definition: CodeGenTypeCache.h:32
clang::CodeGen::TBAAAccessInfo
Definition: CodeGenTBAA.h:41
clang::CodeGen::CodeGenFunction::getVLAElements1D
VlaSizePair getVLAElements1D(const VariableArrayType *vla)
Return the number of elements for a single dimension for the given array type.
Definition: CodeGenFunction.cpp:2173
clang::CXXRecordDecl::getLambdaCaptureDefault
LambdaCaptureDefault getLambdaCaptureDefault() const
Definition: DeclCXX.h:1032
clang::CodeGen::CodeGenModule::GenOpenCLArgMetadata
void GenOpenCLArgMetadata(llvm::Function *FN, const FunctionDecl *FD=nullptr, CodeGenFunction *CGF=nullptr)
OpenCL v1.2 s5.6.4.6 allows the compiler to store kernel argument information in the program executab...
Definition: CodeGenModule.cpp:1642
clang::CodeGen::CodeGenFunction::hasScalarEvaluationKind
static bool hasScalarEvaluationKind(QualType T)
Definition: CodeGenFunction.h:2412
clang::RecordType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4635
clang::CompoundStmt
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1404
clang::CodeGen::CodeGenFunction::getCurrentProfileCount
uint64_t getCurrentProfileCount()
Get the profiler's current count.
Definition: CodeGenFunction.h:1539
clang::SanitizerSet
Definition: Sanitizers.h:153
clang::CodeGen::CodeGenFunction::EHResumeBlock
llvm::BasicBlock * EHResumeBlock
EHResumeBlock - Unified block containing a call to llvm.eh.resume.
Definition: CodeGenFunction.h:653
clang::CXXMethodDecl::isInstance
bool isInstance() const
Definition: DeclCXX.h:1974
clang::Decl::specific_attrs
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
Definition: DeclBase.h:523
clang::CodeGen::TargetCodeGenInfo::getUBSanFunctionSignature
virtual llvm::Constant * getUBSanFunctionSignature(CodeGen::CodeGenModule &CGM) const
Return a constant used by UBSan as a signature to identify functions possessing type information,...
Definition: TargetInfo.h:190
clang::CodeGenOptions::ProfileNone
@ ProfileNone
Definition: CodeGenOptions.h:86
clang::Decl::getNonClosureContext
Decl * getNonClosureContext()
Find the innermost non-closure ancestor of this declaration, walking up through blocks,...
Definition: DeclBase.cpp:1045
clang::BinaryOperator
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3809
clang::CodeGen::CodeGenModule::getSanStats
llvm::SanitizerStatReport & getSanStats()
Definition: CodeGenModule.cpp:6526
clang::CodeGen::CodeGenFunction::EmitCheck
void EmitCheck(ArrayRef< std::pair< llvm::Value *, SanitizerMask >> Checked, SanitizerHandler Check, ArrayRef< llvm::Constant * > StaticArgs, ArrayRef< llvm::Value * > DynamicArgs)
Create a basic block that will either trap or call a handler function in the UBSan runtime with the p...
Definition: CGExpr.cpp:3202
clang::FunctionDecl::getTemplateInstantiationPattern
FunctionDecl * getTemplateInstantiationPattern(bool ForDefinition=true) const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
Definition: Decl.cpp:3771
clang::Builtin::Context::getRequiredFeatures
const char * getRequiredFeatures(unsigned ID) const
Definition: Builtins.h:213
clang::CodeGen::CodeGenFunction::CurSEHParent
const NamedDecl * CurSEHParent
Definition: CodeGenFunction.h:541
clang::CodeGen::CodeGenFunction::GetIndirectGotoBlock
llvm::BasicBlock * GetIndirectGotoBlock()
Definition: CodeGenFunction.cpp:2027
clang::ASTContext::getAsArrayType
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
Definition: ASTContext.cpp:6261
clang::SourceRange::getEnd
SourceLocation getEnd() const
Definition: SourceLocation.h:220
clang::ASTContext::getFunctionTypeWithExceptionSpec
QualType getFunctionTypeWithExceptionSpec(QualType Orig, const FunctionProtoType::ExceptionSpecInfo &ESI)
Get a function type and produce the equivalent function type with the specified exception specificati...
Definition: ASTContext.cpp:3135
clang::CodeGen::CGBuilderTy::CreatePointerBitCastOrAddrSpaceCast
Address CreatePointerBitCastOrAddrSpaceCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Definition: CGBuilder.h:177
CGOpenMPRuntime.h
clang::OMF_dealloc
@ OMF_dealloc
Definition: IdentifierTable.h:703
clang::CodeGen::CodeGenModule::getCodeGenOpts
const CodeGenOptions & getCodeGenOpts() const
Definition: CodeGenModule.h:698
clang::CodeGen::Address::getType
llvm::PointerType * getType() const
Return the type of the pointer value.
Definition: Address.h:57
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:209
clang::LangOptions::FPExceptionModeKind
FPExceptionModeKind
Possible floating point exception behavior.
Definition: LangOptions.h:225
clang::CodeGen::CodeGenModule::EmitAnnotationArgs
llvm::Constant * EmitAnnotationArgs(const AnnotateAttr *Attr)
Emit additional args of the annotation.
Definition: CodeGenModule.cpp:2611
clang::ASTContext::getSizeType
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
Definition: ASTContext.cpp:5784
CGFunctionInfo.h
clang::CPlusPlus
@ CPlusPlus
Definition: LangStandard.h:48
clang::ArrayType
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2884
clang::CodeGen::TEK_Complex
@ TEK_Complex
Definition: CodeGenFunction.h:108
clang::FunctionDecl::getBody
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:3038
clang::CodeGen::CodeGenFunction::EmitTypeCheck
void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *V, QualType Type, CharUnits Alignment=CharUnits::Zero(), SanitizerSet SkippedChecks=SanitizerSet(), llvm::Value *ArraySize=nullptr)
Emit a check that V is the address of storage of the appropriate size and alignment for an object of ...
Definition: CGExpr.cpp:663
CGCleanup.h
clang::CodeGen::CodeGenFunction::EnsureInsertPoint
void EnsureInsertPoint()
EnsureInsertPoint - Ensure that an insertion point is defined so that emitted IR has a place to go.
Definition: CodeGenFunction.h:2470
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7187
clang::CodeGen::CodeGenFunction::getTarget
const TargetInfo & getTarget() const
Definition: CodeGenFunction.h:2016
clang::CodeGen::CodeGenFunction::getDebugInfo
CGDebugInfo * getDebugInfo()
Definition: CodeGenFunction.h:1975
clang::ASTContext::getAsVariableArrayType
const VariableArrayType * getAsVariableArrayType(QualType T) const
Definition: ASTContext.h:2642
clang::CodeGen::ABIArgInfo::InAlloca
@ InAlloca
InAlloca - Pass the argument directly using the LLVM inalloca attribute.
Definition: CGFunctionInfo.h:85
clang::ASTContext::filterFunctionTargetAttrs
ParsedTargetAttr filterFunctionTargetAttrs(const TargetAttr *TD) const
Parses the target attributes passed in, and returns only the ones that are valid feature names.
Definition: ASTContext.cpp:11796
clang::FPOptions
Definition: LangOptions.h:481
clang::CodeGen::CodeGenFunction::EmitBranchOnBoolExpr
void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, llvm::BasicBlock *FalseBlock, uint64_t TrueCount, Stmt::Likelihood LH=Stmt::LH_None)
EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g.
Definition: CodeGenFunction.cpp:1667
clang::CodeGen::CodeGenFunction::SanitizerScope::SanitizerScope
SanitizerScope(CodeGenFunction *CGF)
Definition: CodeGenFunction.cpp:2483
clang::LabelDecl
Represents the declaration of a label.
Definition: Decl.h:494
clang::CodeGen::CodeGenFunction::CGFPOptionsRAII::CGFPOptionsRAII
CGFPOptionsRAII(CodeGenFunction &CGF, FPOptions FPFeatures)
Definition: CodeGenFunction.cpp:130
clang::CodeGen::CodeGenModule::getModule
llvm::Module & getModule() const
Definition: CodeGenModule.h:699
clang::Stmt::LH_None
@ LH_None
No attribute set or branches of the IfStmt have the same attribute.
Definition: Stmt.h:1108
clang::CodeGen::CodeGenFunction::DecodeAddrUsedInPrologue
llvm::Value * DecodeAddrUsedInPrologue(llvm::Value *F, llvm::Value *EncodedAddr)
Decode an address used in a function prologue, encoded by EncodeAddrForUseInPrologue.
Definition: CodeGenFunction.cpp:587
CreateMultiVersionResolverReturn
static void CreateMultiVersionResolverReturn(CodeGenModule &CGM, llvm::Function *Resolver, CGBuilderTy &Builder, llvm::Function *FuncToReturn, bool SupportsIFunc)
Definition: CodeGenFunction.cpp:2607
clang::CodeGen::CGDebugInfo
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Definition: CGDebugInfo.h:55
clang::DeclRefExpr::getDecl
ValueDecl * getDecl()
Definition: Expr.h:1295
clang::VariableArrayType::getSizeExpr
Expr * getSizeExpr() const
Definition: Type.h:3053
clang::CodeGen::EHScopeStack::empty
bool empty() const
Determines whether the exception-scopes stack is empty.
Definition: EHScopeStack.h:350
clang::ParsedAttr
ParsedAttr - Represents a syntactic attribute.
Definition: ParsedAttr.h:209
Expr.h
clang::Expr::EvalResult
EvalResult is a struct with detailed info about an evaluated expression.
Definition: Expr.h:612
clang::CodeGen::CodeGenFunction::FnArgs
llvm::SmallVector< const ParmVarDecl *, 4 > FnArgs
Save Parameter Decl for coroutine.
Definition: CodeGenFunction.h:327
clang::CodeGen::CodeGenFunction::ConditionalEvaluation::begin
void begin(CodeGenFunction &CGF)
Definition: CodeGenFunction.h:1180
ASTContext.h
clang::interp::Zero
bool Zero(InterpState &S, CodePtr OpPC)
Definition: Interp.h:814
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:874
shouldEmitLifetimeMarkers
static bool shouldEmitLifetimeMarkers(const CodeGenOptions &CGOpts, const LangOptions &LangOpts)
shouldEmitLifetimeMarkers - Decide whether we need emit the life-time markers.
Definition: CodeGenFunction.cpp:54
clang::CodeGen::CodeGenModule::imbueXRayAttrs
bool imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc, StringRef Category=StringRef()) const
Imbue XRay attributes to a function, applying the always/never attribute lists in the process.
Definition: CodeGenModule.cpp:2731
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::CodeGen::CodeGenFunction::CreateIRTemp
Address CreateIRTemp(QualType T, const Twine &Name="tmp")
CreateIRTemp - Create a temporary IR object of the given type, with appropriate alignment.
Definition: CGExpr.cpp:130
clang::CodeGen::CodeGenModule::getTypes
CodeGenTypes & getTypes()
Definition: CodeGenModule.h:716
clang::Stmt::LH_Likely
@ LH_Likely
Branch has the [[likely]] attribute.
Definition: Stmt.h:1110
clang::CodeGen::CodeGenFunction::getVLASize
VlaSizePair getVLASize(const VariableArrayType *vla)
Returns an LLVM value that corresponds to the size, in non-variably-sized elements,...
Definition: CodeGenFunction.cpp:2142
clang::Type::isVariablyModifiedType
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
Definition: Type.h:2193
clang::CodeGen::CodeGenFunction::getLLVMContext
llvm::LLVMContext & getLLVMContext()
Definition: CodeGenFunction.h:2017
clang::CodeGen::CodeGenFunction::getContext
ASTContext & getContext() const
Definition: CodeGenFunction.h:1974
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::Redeclarable::getPreviousDecl
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Definition: Redeclarable.h:204
clang::CodeGen::CodeGenTypes::inheritingCtorHasParams
bool inheritingCtorHasParams(const InheritedConstructor &Inherited, CXXCtorType Type)
Determine if a C++ inheriting constructor should have parameters matching those of its inherited cons...
Definition: CGCall.cpp:300
clang::CodeGen::CodeGenFunction::EmitReturnBlock
llvm::DebugLoc EmitReturnBlock()
Emit the unified return block, trying to avoid its emission when possible.
Definition: CodeGenFunction.cpp:272
clang::CodeGen::CodeGenFunction::incrementProfileCounter
void incrementProfileCounter(const Stmt *S, llvm::Value *StepV=nullptr)
Increment the profiler's counter for the given statement by StepV.
Definition: CodeGenFunction.h:1517
clang::CodeGen::CodeGenFunction::FinishFunction
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
Definition: CodeGenFunction.cpp:325
clang::OMF_initialize
@ OMF_initialize
Definition: IdentifierTable.h:709
clang::CodeGen::Address
An aligned address.
Definition: Address.h:24
clang::CodeGen::CGFunctionInfo::isReturnsRetained
bool isReturnsRetained() const
In ARC, whether this function retains its return value.
Definition: CGFunctionInfo.h:669
clang::CodeGen::CodeGenFunction::getJumpDestInCurrentScope
JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target)
The given basic block lies in the current EH scope, but may be a target of a potentially scope-crossi...
Definition: CodeGenFunction.h:1139
CodeGenModule.h
clang::LCD_None
@ LCD_None
Definition: Lambda.h:23
clang::FunctionDecl::getOverloadedOperator
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any.
Definition: Decl.cpp:3661
clang::CodeGen::CodeGenFunction::SanOpts
SanitizerSet SanOpts
Sanitizers enabled for this function.
Definition: CodeGenFunction.h:517
clang::CodeGen::CodeGenFunction::getEvaluationKind
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
Definition: CodeGenFunction.cpp:216
clang::CodeGen::CodeGenFunction::TCK_ConstructorCall
@ TCK_ConstructorCall
Checking the 'this' pointer for a constructor call.
Definition: CodeGenFunction.h:2957
double
__device__ double
Definition: __clang_hip_libdevice_declares.h:165
clang::CodeGen::CodeGenFunction::EmitCheckValue
llvm::Value * EmitCheckValue(llvm::Value *V)
Convert a value into a format suitable for passing to a runtime sanitizer handler.
Definition: CGExpr.cpp:3030
clang::CodeGen::CodeGenFunction::ConditionalEvaluation
An object to manage conditionally-evaluated expressions.
Definition: CodeGenFunction.h:1173
clang::CodeGenOptions
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
Definition: CodeGenOptions.h:49
clang::ast_matchers::arrayType
const AstTypeMatcher< ArrayType > arrayType
Matches all kinds of arrays.
Definition: ASTMatchersInternal.cpp:1034
clang::CodeGen::CodeGenFunction::EmitConstructorBody
void EmitConstructorBody(FunctionArgList &Args)
EmitConstructorBody - Emits the body of the current constructor.
Definition: CGClass.cpp:837
clang::Type::getTypeClass
TypeClass getTypeClass() const
Definition: Type.h:1859
StmtObjC.h
clang::interp::Null
bool Null(InterpState &S, CodePtr OpPC)
Definition: Interp.h:820
clang::XRayInstrKind::FunctionExit
constexpr XRayInstrMask FunctionExit
Definition: XRayInstr.h:40
clang::CodeGen::CodeGenFunction::Bypasses
VarBypassDetector Bypasses
Definition: CodeGenFunction.h:272
clang::CodeGen::CodeGenFunction::CurGD
GlobalDecl CurGD
CurGD - The GlobalDecl for the current function being compiled.
Definition: CodeGenFunction.h:344
clang::CodeGen::CGBuilderInserter
This is an IRBuilder insertion helper that forwards to CodeGenFunction::InsertHelper,...
Definition: CGBuilder.h:25
clang::CodeGen::CodeGenTypeCache::Int32Ty
llvm::IntegerType * Int32Ty
Definition: CodeGenTypeCache.h:37
clang::CodeGen::CodeGenFunction::EmitIgnoredExpr
void EmitIgnoredExpr(const Expr *E)
EmitIgnoredExpr - Emit an expression in a context which ignores the result.
Definition: CGExpr.cpp:190
clang::CodeGenOptions::XRayInstrumentationBundle
XRayInstrSet XRayInstrumentationBundle
Set of XRay instrumentation kinds to emit.
Definition: CodeGenOptions.h:365
clang::CodeGen::CodeGenFunction::isInstrumentedCondition
static bool isInstrumentedCondition(const Expr *C)
isInstrumentedCondition - Determine whether the given condition is an instrumentable condition (i....
Definition: CodeGenFunction.cpp:1581
clang::LangOptions::Sanitize
SanitizerSet Sanitize
Set of enabled sanitizers.
Definition: LangOptions.h:295
clang::CodeGen::CodeGenFunction::ContainsLabel
static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts=false)
ContainsLabel - Return true if the statement contains a label in it.
Definition: CodeGenFunction.cpp:1469
clang::CodeGen::CodeGenModule::getDataLayout
const llvm::DataLayout & getDataLayout() const
Definition: CodeGenModule.h:701
clang::CodeGen::CodeGenFunction::CurFPFeatures
FPOptions CurFPFeatures
Definition: CodeGenFunction.h:721
clang::CodeGen::ApplyDebugLocation
A scoped helper to set the current debug location to the specified location or preferred location of ...
Definition: CGDebugInfo.h:784
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:709
clang::CodeGen::CodeGenFunction::VlaSizePair::NumElts
llvm::Value * NumElts
Definition: CodeGenFunction.h:2772
clang::CodeGen::CodeGenFunction::LoopStack
LoopInfoStack LoopStack
Definition: CodeGenFunction.h:267
emitNonZeroVLAInit
static void emitNonZeroVLAInit(CodeGenFunction &CGF, QualType baseType, Address dest, Address src, llvm::Value *sizeInChars)
emitNonZeroVLAInit - Emit the "zero" initialization of a variable-length array whose elements have a ...
Definition: CodeGenFunction.cpp:1898
clang::CodeGen::LValue
LValue - This represents an lvalue references.
Definition: CGValue.h:171
clang::CodeGen::CodeGenFunction::EHStack
EHScopeStack EHStack
Definition: CodeGenFunction.h:612
clang::CodeGen::CodeGenFunction::PeepholeProtection
An object which temporarily prevents a value from being destroyed by aggressive peephole optimization...
Definition: CodeGenFunction.h:1235
clang::CodeGen::CodeGenFunction::MakeNaturalAlignAddrLValue
LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T)
Definition: CodeGenFunction.cpp:187
clang::CodeGen::CodeGenFunction::EmitFunctionBody
void EmitFunctionBody(const Stmt *Body)
Definition: CodeGenFunction.cpp:1214
clang::FunctionDecl::usesSEHTry
bool usesSEHTry() const
Indicates the function uses __try.
Definition: Decl.h:2315
clang::VariableArrayType
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:3034
clang::ASTContext::VoidPtrTy
CanQualType VoidPtrTy
Definition: ASTContext.h:1100
clang::Stmt::getStmtClass
StmtClass getStmtClass() const
Definition: Stmt.h:1163
clang::Type::isPointerType
bool isPointerType() const
Definition: Type.h:6698
clang::CodeGen::CGCXXABI::addImplicitStructorParams
virtual void addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy, FunctionArgList &Params)=0
Insert any ABI-specific implicit parameters into the parameter list for a function.
clang::CodeGen::Address::getPointer
llvm::Value * getPointer() const
Definition: Address.h:51
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:1010
UINT_MAX
#define UINT_MAX
Definition: limits.h:56
clang::CodeGen::CodeGenFunction
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Definition: CodeGenFunction.h:230
clang::CodeGen::CodeGenFunction::SawAsmBlock
bool SawAsmBlock
Whether we processed a Microsoft-style asm block during CodeGen.
Definition: CodeGenFunction.h:539
clang::CodeGen::ABIArgInfo::getInAllocaFieldIndex
unsigned getInAllocaFieldIndex() const
Definition: CGFunctionInfo.h:435
clang::CharUnits::isZero
bool isZero() const
isZero - Test whether the quantity equals zero.
Definition: CharUnits.h:116
clang::CodeGen::CodeGenModule::getCXXABI
CGCXXABI & getCXXABI() const
Definition: CodeGenModule.h:709
clang::FunctionDecl::isMultiVersion
bool isMultiVersion() const
True if this function is considered a multiversioned function.
Definition: Decl.h:2434
clang::Expr::getExprLoc
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:246
clang::CodeGen::CodeGenModule
This class organizes the cross-function state that is used while generating LLVM code.
Definition: CodeGenModule.h:274
clang::RecordDecl::fields
field_range fields() const
Definition: Decl.h:4086
clang::CodeGen::ABIArgInfo::getIndirectByVal
bool getIndirectByVal() const
Definition: CGFunctionInfo.h:398
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:6386
llvm::ArrayRef
Definition: LLVM.h:34
clang::Stmt::Likelihood
Likelihood
The likelihood of a branch being taken.
Definition: Stmt.h:1106
Value
Value
Definition: UninitializedValues.cpp:102
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
clang::SanitizerKind
Definition: Sanitizers.h:131
clang::CodeGen::ApplyDebugLocation::CreateDefaultArtificial
static ApplyDebugLocation CreateDefaultArtificial(CodeGenFunction &CGF, SourceLocation TemporaryLocation)
Apply TemporaryLocation if it is valid.
Definition: CGDebugInfo.h:823
clang::CodeGen::CodeGenFunction::checkTargetFeatures
void checkTargetFeatures(const CallExpr *E, const FunctionDecl *TargetDecl)
Definition: CodeGenFunction.cpp:2512
clang::CodeGen::CodeGenFunction::BuildFunctionArgList
QualType BuildFunctionArgList(GlobalDecl GD, FunctionArgList &Args)
Definition: CodeGenFunction.cpp:1265
clang::CodeGen::Address::invalid
static Address invalid()
Definition: Address.h:48
clang::CodeGen::CGBuilderTy::CreateAlignedLoad
llvm::LoadInst * CreateAlignedLoad(llvm::Type *Ty, llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
Definition: CGBuilder.h:86
clang::CodeGen::FunctionArgList
FunctionArgList - Type for representing both the decl and type of parameters to a function.
Definition: CGCall.h:355
clang::CodeGen::CGFunctionInfo::getReturnInfo
ABIArgInfo & getReturnInfo()
Definition: CGFunctionInfo.h:708
clang::CodeGen::CodeGenFunction::SourceLocToDebugLoc
llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Location)
Converts Location to a DebugLoc, if debug information is enabled.
Definition: CodeGenFunction.cpp:2727
clang::CodeGen::CodeGenFunction::getTypes
CodeGenTypes & getTypes() const
Definition: CodeGenFunction.h:1973
clang::ToConstrainedExceptMD
llvm::fp::ExceptionBehavior ToConstrainedExceptMD(LangOptions::FPExceptionModeKind Kind)
Definition: CodeGenFunction.cpp:102
clang::CodeGen::CodeGenFunction::emitAlignmentAssumption
void emitAlignmentAssumption(llvm::Value *PtrValue, QualType Ty, SourceLocation Loc, SourceLocation AssumptionLoc, llvm::Value *Alignment, llvm::Value *OffsetValue=nullptr)
Definition: CodeGenFunction.cpp:2376
clang::CodeGen::CGCXXABI::hasMostDerivedReturn
virtual bool hasMostDerivedReturn(GlobalDecl GD) const
Definition: CGCXXABI.h:120
clang::Type::isSignedIntegerType
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
Definition: Type.cpp:2013
clang::CodeGen::CodeGenFunction::ConvertType
llvm::Type * ConvertType(QualType T)
Definition: CodeGenFunction.cpp:212
clang::CodeGen::CodeGenFunction::EmitBlockWithFallThrough
void EmitBlockWithFallThrough(llvm::BasicBlock *BB, const Stmt *S)
When instrumenting to collect profile data, the counts for some blocks such as switch cases need to n...
Definition: CodeGenFunction.cpp:1231
clang::CodeGen::CodeGenFunction::EmitDeclRefExprDbgValue
void EmitDeclRefExprDbgValue(const DeclRefExpr *E, const APValue &Init)
Definition: CodeGenFunction.cpp:2341
clang::CodeGen::CodeGenFunction::EmitVAListRef
Address EmitVAListRef(const Expr *E)
Definition: CodeGenFunction.cpp:2331
clang::CodeGenOptions::hasReducedDebugInfo
bool hasReducedDebugInfo() const
Check if type and variable info should be emitted.
Definition: CodeGenOptions.h:462
clang::BinaryOperatorKind
BinaryOperatorKind
Definition: OperationKinds.h:25
clang::CodeGen::Address::getElementType
llvm::Type * getElementType() const
Return the type of the values stored in this address.
Definition: Address.h:62
clang::CodeGen::CodeGenFunction::MakeAddrLValue
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
Definition: CodeGenFunction.h:2483
clang::CodeGenOptions::hasProfileClangInstr
bool hasProfileClangInstr() const
Check if Clang profile instrumenation is on.
Definition: CodeGenOptions.h:433
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:84
TryMarkNoThrow
static void TryMarkNoThrow(llvm::Function *F)
Tries to mark the given function nounwind based on the non-existence of any throwing calls within it.
Definition: CodeGenFunction.cpp:1252
clang::Expr::EvaluateAsInt
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer,...
Definition: ExprConstant.cpp:14865
clang::ASTContext::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:745
clang::CodeGen::CodeGenFunction::ErrorUnsupported
void ErrorUnsupported(const Stmt *S, const char *Type)
ErrorUnsupported - Print out an error that codegen doesn't support the specified stmt yet.
Definition: CodeGenFunction.cpp:1887
clang::CodeGen::CGBuilderTy::CreateElementBitCast
Address CreateElementBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Cast the element type of the given address to a different type, preserving information like the align...
Definition: CGBuilder.h:169
clang::Stmt::LH_Unlikely
@ LH_Unlikely
Branch has the [[unlikely]] attribute.
Definition: Stmt.h:1107
clang::CodeGen::CodeGenFunction::EmitScalarExpr
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type,...
Definition: CGExprScalar.cpp:4860
clang::CodeGen::CodeGenFunction::isCoroutine
bool isCoroutine() const
Definition: CodeGenFunction.h:339
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:58
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::CodeGen::CGFunctionInfo
CGFunctionInfo - Class to encapsulate the information about a function definition.
Definition: CGFunctionInfo.h:546
clang::CodeGen::CodeGenFunction::PopCleanupBlocks
void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize, std::initializer_list< llvm::Value ** > ValuesToReload={})
Takes the old cleanup stack size and emits the cleanup blocks that have been added.
Definition: CGCleanup.cpp:420
clang::CodeGen::CodeGenFunction::LifetimeExtendedCleanupStack
llvm::SmallVector< char, 256 > LifetimeExtendedCleanupStack
Definition: CodeGenFunction.h:613
CGCXXABI.h
clang::CodeGen::CodeGenFunction::EmitLoadOfLValue
RValue EmitLoadOfLValue(LValue V, SourceLocation Loc)
EmitLoadOfLValue - Given an expression that represents a value lvalue, this method emits the address ...
Definition: CGExpr.cpp:1885
clang::CodeGen::CodeGenFunction::JumpDest::isValid
bool isValid() const
Definition: CodeGenFunction.h:244
clang::CodeGen::CodeGenFunction::EmitMSVAListRef
Address EmitMSVAListRef(const Expr *E)
Emit a "reference" to a __builtin_ms_va_list; this is always the value of the expression,...
Definition: CodeGenFunction.cpp:2337
clang::CodeGen::CodeGenFunction::FnRetTy
QualType FnRetTy
Definition: CodeGenFunction.h:323
clang::CodeGen::CodeGenPGO::assignRegionCounters
void assignRegionCounters(GlobalDecl GD, llvm::Function *Fn)
Assign counters to regions and configure them for PGO of a given function.
Definition: CodeGenPGO.cpp:794
clang::PointerType
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2641
clang::FunctionDecl::isMSVCRTEntryPoint
bool isMSVCRTEntryPoint() const
Determines whether this function is a MSVCRT user defined entry point.
Definition: Decl.cpp:3078
clang::BinaryOperator::isLogicalOp
static bool isLogicalOp(Opcode Opc)
Definition: Expr.h:3941
clang::CodeGen::CodeGenFunction::EmitVarAnnotations
void EmitVarAnnotations(const VarDecl *D, llvm::Value *V)
Emit local annotations for the local variable V, declared by D.
Definition: CodeGenFunction.cpp:2446
clang::FunctionDecl::isMain
bool isMain() const
Determines whether this function is "main", which is the entry point into an executable program.
Definition: Decl.cpp:3070
clang::CodeGen::CodeGenFunction::SanitizerScope::~SanitizerScope
~SanitizerScope()
Definition: CodeGenFunction.cpp:2489
clang::CodeGen::CodeGenFunction::CGM
CodeGenModule & CGM
Definition: CodeGenFunction.h:260
clang::CodeGen::CodeGenFunction::VlaSizePair
Definition: CodeGenFunction.h:2771
clang::ImplicitParamDecl::Create
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)
Create implicit parameter.
Definition: Decl.cpp:4888
clang::CodeGen::TEK_Scalar
@ TEK_Scalar
Definition: CodeGenFunction.h:107
clang::CodeGen::CodeGenFunction::EvaluateExprAsBool
llvm::Value * EvaluateExprAsBool(const Expr *E)
EvaluateExprAsBool - Perform the usual unary conversions on the specified expression and compare the ...
Definition: CGExpr.cpp:171
CGBlocks.h
clang::CodeGen::CodeGenFunction::CurFn
llvm::Function * CurFn
Definition: CodeGenFunction.h:324
clang::Expr::IgnoreParens
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:2929
clang
Definition: CalledOnceCheck.h:17
clang::TargetInfo::supportsIFunc
bool supportsIFunc() const
Identify whether this target supports IFuncs.
Definition: TargetInfo.h:1327
clang::VectorType::getElementType
QualType getElementType() const
Definition: Type.h:3271
clang::CodeGen::CodeGenFunction::JumpDest
A jump destination is an abstract label, branching to which may require a jump out through normal cle...
Definition: CodeGenFunction.h:238
clang::CodeGen::CodeGenFunction::ShouldSkipSanitizerInstrumentation
bool ShouldSkipSanitizerInstrumentation()
ShouldSkipSanitizerInstrumentation - Return true if the current function should not be instrumented w...
Definition: CodeGenFunction.cpp:535
clang::CodeGen::CodeGenFunction::SetFastMathFlags
void SetFastMathFlags(FPOptions FPFeatures)
Set the codegen fast-math flags.
Definition: CodeGenFunction.cpp:112
clang::Expr::getFPFeaturesInEffect
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Returns the set of floating point options that apply to this expression.
Definition: Expr.cpp:3683
FrontendDiagnostic.h
clang::ExternalLinkage
@ ExternalLinkage
External linkage, which indicates that the entity can be referred to from other translation units.
Definition: Linkage.h:59
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:69
clang::CodeGen::TargetFeatures::hasRequiredFeatures
bool hasRequiredFeatures(StringRef FeatureList)
Definition: CodeGenFunction.h:4858
CGCUDARuntime.h
clang::XRayInstrSet::has
bool has(XRayInstrMask K) const
Definition: XRayInstr.h:48
clang::CodeGen::CodeGenTypeCache::IntPtrTy
llvm::IntegerType * IntPtrTy
Definition: CodeGenTypeCache.h:49
clang::DeclaratorContext::Condition
@ Condition
clang::CodeGen::CodeGenModule::getNaturalTypeAlignment
CharUnits getNaturalTypeAlignment(QualType T, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr, bool forPointeeType=false)
Definition: CodeGenModule.cpp:6550
clang::CXXRecordDecl::getCaptureFields
void getCaptureFields(llvm::DenseMap< const VarDecl *, FieldDecl * > &Captures, FieldDecl *&ThisCapture) const
For a closure type, retrieve the mapping from captured variables and this to the non-static data memb...
Definition: DeclCXX.cpp:1559
clang::Expr::getType
QualType getType() const
Definition: Expr.h:141
clang::MangleContext::startNewFunction
virtual void startNewFunction()
Definition: Mangle.h:76
clang::LangOptions::FPE_Ignore
@ FPE_Ignore
Assume that floating-point exceptions are masked.
Definition: LangOptions.h:227
clang::Attr
Attr - This represents one attribute.
Definition: Attr.h:41
clang::NamedDecl::getDeclName
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:311
clang::CodeGen::CGCXXABI::EmitInstanceFunctionProlog
virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF)=0
Emit the ABI-specific prolog for the function.
clang::CodeGen::CodeGenFunction::CGCapturedStmtInfo::~CGCapturedStmtInfo
virtual ~CGCapturedStmtInfo()
Definition: CodeGenFunction.cpp:2481
clang::CodeGen::RValue::getScalarVal
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
Definition: CGValue.h:61
clang::LangOptions::FPE_Strict
@ FPE_Strict
Strictly preserve the floating-point exception semantics.
Definition: LangOptions.h:231
clang::GlobalDecl::getCtorType
CXXCtorType getCtorType() const
Definition: GlobalDecl.h:105
clang::CodeGen::CodeGenModule::getDiags
DiagnosticsEngine & getDiags() const
Definition: CodeGenModule.h:700
clang::CodeGen::CodeGenFunction::CurFuncIsThunk
bool CurFuncIsThunk
In C++, whether we are code generating a thunk.
Definition: CodeGenFunction.h:532
clang::CodeGen::CodeGenFunction::ReturnValuePointer
Address ReturnValuePointer
ReturnValuePointer - The temporary alloca to hold a pointer to sret.
Definition: CodeGenFunction.h:359
clang::CodeGen::EHScopeStack::setCGF
void setCGF(CodeGenFunction *inCGF)
Definition: EHScopeStack.h:320
clang::CodeGen::CodeGenFunction::LambdaThisCaptureField
FieldDecl * LambdaThisCaptureField
Definition: CodeGenFunction.h:606
clang::CodeGen::ABIArgInfo::getIndirectAlign
CharUnits getIndirectAlign() const
Definition: CGFunctionInfo.h:389
clang::CodeGen::RValue::isScalar
bool isScalar() const
Definition: CGValue.h:54
clang::CodeGen::EHScopeStack::stable_begin
stable_iterator stable_begin() const
Create a stable reference to the top of the EH stack.
Definition: EHScopeStack.h:384
clang::SanitizerSet::set
void set(SanitizerMask K, bool Value)
Enable or disable a certain (single) sanitizer.
Definition: Sanitizers.h:164
clang::GlobalDecl::getDecl
const Decl * getDecl() const
Definition: GlobalDecl.h:103
clang::CodeGen::CodeGenModule::getCUDARuntime
CGCUDARuntime & getCUDARuntime()
Return a reference to the configured CUDA runtime.
Definition: CodeGenModule.h:612
clang::CodeGen::CodeGenModule::EmitAnnotationString
llvm::Constant * EmitAnnotationString(StringRef Str)
Emit an annotation string.
Definition: CodeGenModule.cpp:2579
clang::CodeGen::CodeGenFunction::EmitLValue
LValue EmitLValue(const Expr *E)
EmitLValue - Emit code to compute a designator that specifies the location of the expression.
Definition: CGExpr.cpp:1275
clang::CodeGen::CodeGenFunction::EmitStartEHSpec
void EmitStartEHSpec(const Decl *D)
EmitStartEHSpec - Emit the start of the exception spec.
Definition: CGException.cpp:462
clang::ExtVectorType
ExtVectorType - Extended vector type.
Definition: Type.h:3351
clang::CodeGen::CGBuilderInserter::InsertHelper
void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name, llvm::BasicBlock *BB, llvm::BasicBlock::iterator InsertPt) const override
This forwards to CodeGenFunction::InsertHelper.
Definition: CodeGenFunction.cpp:2502
clang::CodeGen::CodeGenFunction::EmitFieldAnnotations
Address EmitFieldAnnotations(const FieldDecl *D, Address V)
Emit field annotations for the given field & value.
Definition: CodeGenFunction.cpp:2456
clang::CharUnits
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
clang::CodeGen::CodeGenFunction::TCK_MemberCall
@ TCK_MemberCall
Checking the 'this' pointer for a call to a non-static member function.
Definition: CodeGenFunction.h:2955
clang::CodeGen::CodeGenTypes::isZeroInitializable
bool isZeroInitializable(QualType T)
IsZeroInitializable - Return whether a type can be zero-initialized (in the C++ sense) with an LLVM z...
Definition: CodeGenTypes.cpp:899
clang::XRayInstrKind::Custom
constexpr XRayInstrMask Custom
Definition: XRayInstr.h:41
clang::CXXRecordDecl::isLambda
bool isLambda() const
Determine whether this class describes a lambda function object.
Definition: DeclCXX.h:991
clang::APValue
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
clang::CodeGen::CodeGenFunction::CurFnInfo
const CGFunctionInfo * CurFnInfo
Definition: CodeGenFunction.h:322
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:685
clang::CodeGen::CodeGenFunction::containsBreak
static bool containsBreak(const Stmt *S)
containsBreak - Return true if the statement contains a break out of it.
Definition: CodeGenFunction.cpp:1501
clang::FunctionDecl::getBuiltinID
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
Definition: Decl.cpp:3328
clang::ArrayType::getElementType
QualType getElementType() const
Definition: Type.h:2905
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::CodeGen::CodeGenFunction::EmitPointerWithAlignment
Address EmitPointerWithAlignment(const Expr *Addr, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
EmitPointerWithAlignment - Given an expression with a pointer type, emit the value and compute our be...
Definition: CGExpr.cpp:1059
clang::FPOptions::allowFPContractAcrossStatement
bool allowFPContractAcrossStatement() const
Definition: LangOptions.h:550
clang::CodeGen::CodeGenTypeCache::Int8Ty
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Definition: CodeGenTypeCache.h:37
endsWithReturn
static bool endsWithReturn(const Decl *F)
Determine whether the function F ends with a return stmt.
Definition: CodeGenFunction.cpp:651
clang::CodeGen::CodeGenModule::getIntrinsic
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=None)
Definition: CodeGenModule.cpp:5201
clang::CodeGen::CGCUDARuntime::emitDeviceStub
virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args)=0
Emits a kernel launch stub.
EmitIfUsed
static void EmitIfUsed(CodeGenFunction &CGF, llvm::BasicBlock *BB)
Definition: CodeGenFunction.cpp:318
clang::NullabilityKind::NonNull
@ NonNull
Values of this type can never be null.
clang::CodeGen::CodeGenFunction::unprotectFromPeepholes
void unprotectFromPeepholes(PeepholeProtection protection)
Definition: CodeGenFunction.cpp:2369
clang::FunctionDecl::parameters
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2486
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:424
clang::DeclRefExpr
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1223
clang::CodeGen::CGBuilderTy::CreateMemSet
llvm::CallInst * CreateMemSet(Address Dest, llvm::Value *Value, llvm::Value *Size, bool IsVolatile=false)
Definition: CGBuilder.h:341
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1855
clang::CodeGen::CodeGenTypeCache::Int8PtrPtrTy
llvm::PointerType * Int8PtrPtrTy
Definition: CodeGenTypeCache.h:63
clang::CallExpr
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2801
clang::CodeGen::CodeGenFunction::EmitBlock
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
Definition: CGStmt.cpp:532
clang::CodeGen::CodeGenModule::getSanitizerMetadata
SanitizerMetadata * getSanitizerMetadata()
Definition: CodeGenModule.h:1310
clang::CodeGen::CodeGenFunction::AllocaInsertPt
llvm::AssertingVH< llvm::Instruction > AllocaInsertPt
AllocaInsertPoint - This is an instruction in the entry block before which we prefer to insert alloca...
Definition: CodeGenFunction.h:374
StmtCXX.h
clang::CodeGen::CodeGenModule::EmitAnnotationLineNo
llvm::Constant * EmitAnnotationLineNo(SourceLocation L)
Emit the annotation line number.
Definition: CodeGenModule.cpp:2603
clang::CodeGen::CodeGenFunction::ReturnBlock
JumpDest ReturnBlock
ReturnBlock - Unified return block.
Definition: CodeGenFunction.h:351
clang::CharUnits::getQuantity
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:179
clang::CodeGen::CodeGenFunction::getLangOpts
const LangOptions & getLangOpts() const
Definition: CodeGenFunction.h:1987
clang::XRayInstrKind::Typed
constexpr XRayInstrMask Typed
Definition: XRayInstr.h:42
clang::SanitizerMask
Definition: Sanitizers.h:30
clang::FunctionDecl::isInlineBuiltinDeclaration
bool isInlineBuiltinDeclaration() const
Determine if this function provides an inline implementation of a builtin.
Definition: Decl.cpp:3197
clang::CodeGen::VarBypassDetector::Init
void Init(const Stmt *Body)
Clear the object and pre-process for the given statement, usually function body statement.
Definition: VarBypassDetector.cpp:20
clang::CodeGen::CodeGenFunction::EncodeAddrForUseInPrologue
llvm::Constant * EncodeAddrForUseInPrologue(llvm::Function *F, llvm::Constant *Addr)
Encode an address into a form suitable for use in a function prologue.
Definition: CodeGenFunction.cpp:564
clang::CodeGen::CodeGenFunction::EmitCXXThrowExpr
void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint=true)
Definition: CGException.cpp:441
clang::CodeGen::CodeGenFunction::GetAddrOfLabel
llvm::BlockAddress * GetAddrOfLabel(const LabelDecl *L)
Definition: CodeGenFunction.cpp:2015
clang::CodeGen::CGOpenMPRuntime::functionFinished
virtual void functionFinished(CodeGenFunction &CGF)
Cleans up references to the objects in finished function.
Definition: CGOpenMPRuntime.cpp:1522
clang::CodeGen::CodeGenFunction::CurFuncDecl
const Decl * CurFuncDecl
CurFuncDecl - Holds the Decl for the current outermost non-closure context.
Definition: CodeGenFunction.h:319
clang::DiagnosticsEngine::Report
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1523
clang::CodeGen::CodeGenFunction::EmitCheckTypeDescriptor
llvm::Constant * EmitCheckTypeDescriptor(QualType T)
Emit a description of a type in a format suitable for passing to a runtime sanitizer handler.
Definition: CGExpr.cpp:2987
clang::CodeGen::CodeGenFunction::~CodeGenFunction
~CodeGenFunction()
Definition: CodeGenFunction.cpp:84
clang::ImplicitParamDecl::Other
@ Other
Other implicit parameter.
Definition: Decl.h:1623
clang::CodeGen::CGBuilderTy::CreateLoad
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
Definition: CGBuilder.h:68
clang::CodeGen::CodeGenFunction::EmitBranch
void EmitBranch(llvm::BasicBlock *Block)
EmitBranch - Emit a branch to the specified basic block from the current insert block,...
Definition: CGStmt.cpp:552
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:2062
clang::CXXMethodDecl
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1947
clang::CodeGen::CodeGenFunction::ConditionalEvaluation::end
void end(CodeGenFunction &CGF)
Definition: CodeGenFunction.h:1186
clang::CodeGen::CodeGenFunction::ReturnValue
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
Definition: CodeGenFunction.h:355