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