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