clang  16.0.0git
CGException.cpp
Go to the documentation of this file.
1 //===--- CGException.cpp - Emit LLVM Code for C++ exceptions ----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This contains code dealing with C++ exception related code generation.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "CGCXXABI.h"
14 #include "CGCleanup.h"
15 #include "CGObjCRuntime.h"
16 #include "CodeGenFunction.h"
17 #include "ConstantEmitter.h"
18 #include "TargetInfo.h"
19 #include "clang/AST/Mangle.h"
20 #include "clang/AST/StmtCXX.h"
21 #include "clang/AST/StmtObjC.h"
22 #include "clang/AST/StmtVisitor.h"
25 #include "llvm/IR/IntrinsicInst.h"
26 #include "llvm/IR/Intrinsics.h"
27 #include "llvm/IR/IntrinsicsWebAssembly.h"
28 #include "llvm/Support/SaveAndRestore.h"
29 
30 using namespace clang;
31 using namespace CodeGen;
32 
33 static llvm::FunctionCallee getFreeExceptionFn(CodeGenModule &CGM) {
34  // void __cxa_free_exception(void *thrown_exception);
35 
36  llvm::FunctionType *FTy =
37  llvm::FunctionType::get(CGM.VoidTy, CGM.Int8PtrTy, /*isVarArg=*/false);
38 
39  return CGM.CreateRuntimeFunction(FTy, "__cxa_free_exception");
40 }
41 
42 static llvm::FunctionCallee getSehTryBeginFn(CodeGenModule &CGM) {
43  llvm::FunctionType *FTy =
44  llvm::FunctionType::get(CGM.VoidTy, /*isVarArg=*/false);
45  return CGM.CreateRuntimeFunction(FTy, "llvm.seh.try.begin");
46 }
47 
48 static llvm::FunctionCallee getSehTryEndFn(CodeGenModule &CGM) {
49  llvm::FunctionType *FTy =
50  llvm::FunctionType::get(CGM.VoidTy, /*isVarArg=*/false);
51  return CGM.CreateRuntimeFunction(FTy, "llvm.seh.try.end");
52 }
53 
54 static llvm::FunctionCallee getUnexpectedFn(CodeGenModule &CGM) {
55  // void __cxa_call_unexpected(void *thrown_exception);
56 
57  llvm::FunctionType *FTy =
58  llvm::FunctionType::get(CGM.VoidTy, CGM.Int8PtrTy, /*isVarArg=*/false);
59 
60  return CGM.CreateRuntimeFunction(FTy, "__cxa_call_unexpected");
61 }
62 
63 llvm::FunctionCallee CodeGenModule::getTerminateFn() {
64  // void __terminate();
65 
66  llvm::FunctionType *FTy =
67  llvm::FunctionType::get(VoidTy, /*isVarArg=*/false);
68 
69  StringRef name;
70 
71  // In C++, use std::terminate().
72  if (getLangOpts().CPlusPlus &&
73  getTarget().getCXXABI().isItaniumFamily()) {
74  name = "_ZSt9terminatev";
75  } else if (getLangOpts().CPlusPlus &&
76  getTarget().getCXXABI().isMicrosoft()) {
77  if (getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2015))
78  name = "__std_terminate";
79  else
80  name = "?terminate@@YAXXZ";
81  } else if (getLangOpts().ObjC &&
83  name = "objc_terminate";
84  else
85  name = "abort";
86  return CreateRuntimeFunction(FTy, name);
87 }
88 
89 static llvm::FunctionCallee getCatchallRethrowFn(CodeGenModule &CGM,
90  StringRef Name) {
91  llvm::FunctionType *FTy =
92  llvm::FunctionType::get(CGM.VoidTy, CGM.Int8PtrTy, /*isVarArg=*/false);
93 
94  return CGM.CreateRuntimeFunction(FTy, Name);
95 }
96 
97 const EHPersonality EHPersonality::GNU_C = { "__gcc_personality_v0", nullptr };
98 const EHPersonality
99 EHPersonality::GNU_C_SJLJ = { "__gcc_personality_sj0", nullptr };
100 const EHPersonality
101 EHPersonality::GNU_C_SEH = { "__gcc_personality_seh0", nullptr };
102 const EHPersonality
103 EHPersonality::NeXT_ObjC = { "__objc_personality_v0", nullptr };
104 const EHPersonality
105 EHPersonality::GNU_CPlusPlus = { "__gxx_personality_v0", nullptr };
106 const EHPersonality
107 EHPersonality::GNU_CPlusPlus_SJLJ = { "__gxx_personality_sj0", nullptr };
108 const EHPersonality
109 EHPersonality::GNU_CPlusPlus_SEH = { "__gxx_personality_seh0", nullptr };
110 const EHPersonality
111 EHPersonality::GNU_ObjC = {"__gnu_objc_personality_v0", "objc_exception_throw"};
112 const EHPersonality
113 EHPersonality::GNU_ObjC_SJLJ = {"__gnu_objc_personality_sj0", "objc_exception_throw"};
114 const EHPersonality
115 EHPersonality::GNU_ObjC_SEH = {"__gnu_objc_personality_seh0", "objc_exception_throw"};
116 const EHPersonality
117 EHPersonality::GNU_ObjCXX = { "__gnustep_objcxx_personality_v0", nullptr };
118 const EHPersonality
119 EHPersonality::GNUstep_ObjC = { "__gnustep_objc_personality_v0", nullptr };
120 const EHPersonality
121 EHPersonality::MSVC_except_handler = { "_except_handler3", nullptr };
122 const EHPersonality
123 EHPersonality::MSVC_C_specific_handler = { "__C_specific_handler", nullptr };
124 const EHPersonality
125 EHPersonality::MSVC_CxxFrameHandler3 = { "__CxxFrameHandler3", nullptr };
126 const EHPersonality
127 EHPersonality::GNU_Wasm_CPlusPlus = { "__gxx_wasm_personality_v0", nullptr };
128 const EHPersonality EHPersonality::XL_CPlusPlus = {"__xlcxx_personality_v1",
129  nullptr};
130 
131 static const EHPersonality &getCPersonality(const TargetInfo &Target,
132  const LangOptions &L) {
133  const llvm::Triple &T = Target.getTriple();
134  if (T.isWindowsMSVCEnvironment())
136  if (L.hasSjLjExceptions())
138  if (L.hasDWARFExceptions())
139  return EHPersonality::GNU_C;
140  if (L.hasSEHExceptions())
142  return EHPersonality::GNU_C;
143 }
144 
145 static const EHPersonality &getObjCPersonality(const TargetInfo &Target,
146  const LangOptions &L) {
147  const llvm::Triple &T = Target.getTriple();
148  if (T.isWindowsMSVCEnvironment())
150 
151  switch (L.ObjCRuntime.getKind()) {
153  return getCPersonality(Target, L);
154  case ObjCRuntime::MacOSX:
155  case ObjCRuntime::iOS:
159  if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
161  [[fallthrough]];
162  case ObjCRuntime::GCC:
163  case ObjCRuntime::ObjFW:
164  if (L.hasSjLjExceptions())
166  if (L.hasSEHExceptions())
169  }
170  llvm_unreachable("bad runtime kind");
171 }
172 
173 static const EHPersonality &getCXXPersonality(const TargetInfo &Target,
174  const LangOptions &L) {
175  const llvm::Triple &T = Target.getTriple();
176  if (T.isWindowsMSVCEnvironment())
178  if (T.isOSAIX())
180  if (L.hasSjLjExceptions())
182  if (L.hasDWARFExceptions())
184  if (L.hasSEHExceptions())
186  if (L.hasWasmExceptions())
189 }
190 
191 /// Determines the personality function to use when both C++
192 /// and Objective-C exceptions are being caught.
193 static const EHPersonality &getObjCXXPersonality(const TargetInfo &Target,
194  const LangOptions &L) {
195  if (Target.getTriple().isWindowsMSVCEnvironment())
197 
198  switch (L.ObjCRuntime.getKind()) {
199  // In the fragile ABI, just use C++ exception handling and hope
200  // they're not doing crazy exception mixing.
202  return getCXXPersonality(Target, L);
203 
204  // The ObjC personality defers to the C++ personality for non-ObjC
205  // handlers. Unlike the C++ case, we use the same personality
206  // function on targets using (backend-driven) SJLJ EH.
207  case ObjCRuntime::MacOSX:
208  case ObjCRuntime::iOS:
210  return getObjCPersonality(Target, L);
211 
214 
215  // The GCC runtime's personality function inherently doesn't support
216  // mixed EH. Use the ObjC personality just to avoid returning null.
217  case ObjCRuntime::GCC:
218  case ObjCRuntime::ObjFW:
219  return getObjCPersonality(Target, L);
220  }
221  llvm_unreachable("bad runtime kind");
222 }
223 
224 static const EHPersonality &getSEHPersonalityMSVC(const llvm::Triple &T) {
225  if (T.getArch() == llvm::Triple::x86)
228 }
229 
231  const FunctionDecl *FD) {
232  const llvm::Triple &T = CGM.getTarget().getTriple();
233  const LangOptions &L = CGM.getLangOpts();
234  const TargetInfo &Target = CGM.getTarget();
235 
236  // Functions using SEH get an SEH personality.
237  if (FD && FD->usesSEHTry())
238  return getSEHPersonalityMSVC(T);
239 
240  if (L.ObjC)
241  return L.CPlusPlus ? getObjCXXPersonality(Target, L)
243  return L.CPlusPlus ? getCXXPersonality(Target, L)
244  : getCPersonality(Target, L);
245 }
246 
248  const auto *FD = CGF.CurCodeDecl;
249  // For outlined finallys and filters, use the SEH personality in case they
250  // contain more SEH. This mostly only affects finallys. Filters could
251  // hypothetically use gnu statement expressions to sneak in nested SEH.
252  FD = FD ? FD : CGF.CurSEHParent.getDecl();
253  return get(CGF.CGM, dyn_cast_or_null<FunctionDecl>(FD));
254 }
255 
256 static llvm::FunctionCallee getPersonalityFn(CodeGenModule &CGM,
257  const EHPersonality &Personality) {
258  return CGM.CreateRuntimeFunction(llvm::FunctionType::get(CGM.Int32Ty, true),
259  Personality.PersonalityFn,
260  llvm::AttributeList(), /*Local=*/true);
261 }
262 
263 static llvm::Constant *getOpaquePersonalityFn(CodeGenModule &CGM,
264  const EHPersonality &Personality) {
265  llvm::FunctionCallee Fn = getPersonalityFn(CGM, Personality);
266  llvm::PointerType* Int8PtrTy = llvm::PointerType::get(
267  llvm::Type::getInt8Ty(CGM.getLLVMContext()),
268  CGM.getDataLayout().getProgramAddressSpace());
269 
270  return llvm::ConstantExpr::getBitCast(cast<llvm::Constant>(Fn.getCallee()),
271  Int8PtrTy);
272 }
273 
274 /// Check whether a landingpad instruction only uses C++ features.
275 static bool LandingPadHasOnlyCXXUses(llvm::LandingPadInst *LPI) {
276  for (unsigned I = 0, E = LPI->getNumClauses(); I != E; ++I) {
277  // Look for something that would've been returned by the ObjC
278  // runtime's GetEHType() method.
279  llvm::Value *Val = LPI->getClause(I)->stripPointerCasts();
280  if (LPI->isCatch(I)) {
281  // Check if the catch value has the ObjC prefix.
282  if (llvm::GlobalVariable *GV = dyn_cast<llvm::GlobalVariable>(Val))
283  // ObjC EH selector entries are always global variables with
284  // names starting like this.
285  if (GV->getName().startswith("OBJC_EHTYPE"))
286  return false;
287  } else {
288  // Check if any of the filter values have the ObjC prefix.
289  llvm::Constant *CVal = cast<llvm::Constant>(Val);
290  for (llvm::User::op_iterator
291  II = CVal->op_begin(), IE = CVal->op_end(); II != IE; ++II) {
292  if (llvm::GlobalVariable *GV =
293  cast<llvm::GlobalVariable>((*II)->stripPointerCasts()))
294  // ObjC EH selector entries are always global variables with
295  // names starting like this.
296  if (GV->getName().startswith("OBJC_EHTYPE"))
297  return false;
298  }
299  }
300  }
301  return true;
302 }
303 
304 /// Check whether a personality function could reasonably be swapped
305 /// for a C++ personality function.
306 static bool PersonalityHasOnlyCXXUses(llvm::Constant *Fn) {
307  for (llvm::User *U : Fn->users()) {
308  // Conditionally white-list bitcasts.
309  if (llvm::ConstantExpr *CE = dyn_cast<llvm::ConstantExpr>(U)) {
310  if (CE->getOpcode() != llvm::Instruction::BitCast) return false;
311  if (!PersonalityHasOnlyCXXUses(CE))
312  return false;
313  continue;
314  }
315 
316  // Otherwise it must be a function.
317  llvm::Function *F = dyn_cast<llvm::Function>(U);
318  if (!F) return false;
319 
320  for (auto BB = F->begin(), E = F->end(); BB != E; ++BB) {
321  if (BB->isLandingPad())
322  if (!LandingPadHasOnlyCXXUses(BB->getLandingPadInst()))
323  return false;
324  }
325  }
326 
327  return true;
328 }
329 
330 /// Try to use the C++ personality function in ObjC++. Not doing this
331 /// can cause some incompatibilities with gcc, which is more
332 /// aggressive about only using the ObjC++ personality in a function
333 /// when it really needs it.
334 void CodeGenModule::SimplifyPersonality() {
335  // If we're not in ObjC++ -fexceptions, there's nothing to do.
336  if (!LangOpts.CPlusPlus || !LangOpts.ObjC || !LangOpts.Exceptions)
337  return;
338 
339  // Both the problem this endeavors to fix and the way the logic
340  // above works is specific to the NeXT runtime.
341  if (!LangOpts.ObjCRuntime.isNeXTFamily())
342  return;
343 
344  const EHPersonality &ObjCXX = EHPersonality::get(*this, /*FD=*/nullptr);
345  const EHPersonality &CXX = getCXXPersonality(getTarget(), LangOpts);
346  if (&ObjCXX == &CXX)
347  return;
348 
349  assert(std::strcmp(ObjCXX.PersonalityFn, CXX.PersonalityFn) != 0 &&
350  "Different EHPersonalities using the same personality function.");
351 
352  llvm::Function *Fn = getModule().getFunction(ObjCXX.PersonalityFn);
353 
354  // Nothing to do if it's unused.
355  if (!Fn || Fn->use_empty()) return;
356 
357  // Can't do the optimization if it has non-C++ uses.
358  if (!PersonalityHasOnlyCXXUses(Fn)) return;
359 
360  // Create the C++ personality function and kill off the old
361  // function.
362  llvm::FunctionCallee CXXFn = getPersonalityFn(*this, CXX);
363 
364  // This can happen if the user is screwing with us.
365  if (Fn->getType() != CXXFn.getCallee()->getType())
366  return;
367 
368  Fn->replaceAllUsesWith(CXXFn.getCallee());
369  Fn->eraseFromParent();
370 }
371 
372 /// Returns the value to inject into a selector to indicate the
373 /// presence of a catch-all.
374 static llvm::Constant *getCatchAllValue(CodeGenFunction &CGF) {
375  // Possibly we should use @llvm.eh.catch.all.value here.
376  return llvm::ConstantPointerNull::get(CGF.Int8PtrTy);
377 }
378 
379 namespace {
380  /// A cleanup to free the exception object if its initialization
381  /// throws.
382  struct FreeException final : EHScopeStack::Cleanup {
383  llvm::Value *exn;
384  FreeException(llvm::Value *exn) : exn(exn) {}
385  void Emit(CodeGenFunction &CGF, Flags flags) override {
387  }
388  };
389 } // end anonymous namespace
390 
391 // Emits an exception expression into the given location. This
392 // differs from EmitAnyExprToMem only in that, if a final copy-ctor
393 // call is required, an exception within that copy ctor causes
394 // std::terminate to be invoked.
396  // Make sure the exception object is cleaned up if there's an
397  // exception during initialization.
398  pushFullExprCleanup<FreeException>(EHCleanup, addr.getPointer());
400 
401  // __cxa_allocate_exception returns a void*; we need to cast this
402  // to the appropriate type for the object.
403  llvm::Type *ty = ConvertTypeForMem(e->getType());
404  Address typedAddr = Builder.CreateElementBitCast(addr, ty);
405 
406  // FIXME: this isn't quite right! If there's a final unelided call
407  // to a copy constructor, then according to [except.terminate]p1 we
408  // must call std::terminate() if that constructor throws, because
409  // technically that copy occurs after the exception expression is
410  // evaluated but before the exception is caught. But the best way
411  // to handle that is to teach EmitAggExpr to do the final copy
412  // differently if it can't be elided.
413  EmitAnyExprToMem(e, typedAddr, e->getType().getQualifiers(),
414  /*IsInit*/ true);
415 
416  // Deactivate the cleanup block.
418  cast<llvm::Instruction>(typedAddr.getPointer()));
419 }
420 
422  if (!ExceptionSlot)
425 }
426 
428  if (!EHSelectorSlot)
429  EHSelectorSlot = CreateTempAlloca(Int32Ty, "ehselector.slot");
431 }
432 
434  return Builder.CreateLoad(getExceptionSlot(), "exn");
435 }
436 
438  return Builder.CreateLoad(getEHSelectorSlot(), "sel");
439 }
440 
442  bool KeepInsertionPoint) {
443  if (const Expr *SubExpr = E->getSubExpr()) {
444  QualType ThrowType = SubExpr->getType();
445  if (ThrowType->isObjCObjectPointerType()) {
446  const Stmt *ThrowStmt = E->getSubExpr();
447  const ObjCAtThrowStmt S(E->getExprLoc(), const_cast<Stmt *>(ThrowStmt));
448  CGM.getObjCRuntime().EmitThrowStmt(*this, S, false);
449  } else {
450  CGM.getCXXABI().emitThrow(*this, E);
451  }
452  } else {
453  CGM.getCXXABI().emitRethrow(*this, /*isNoReturn=*/true);
454  }
455 
456  // throw is an expression, and the expression emitters expect us
457  // to leave ourselves at a valid insertion point.
458  if (KeepInsertionPoint)
459  EmitBlock(createBasicBlock("throw.cont"));
460 }
461 
463  if (!CGM.getLangOpts().CXXExceptions)
464  return;
465 
466  const FunctionDecl* FD = dyn_cast_or_null<FunctionDecl>(D);
467  if (!FD) {
468  // Check if CapturedDecl is nothrow and create terminate scope for it.
469  if (const CapturedDecl* CD = dyn_cast_or_null<CapturedDecl>(D)) {
470  if (CD->isNothrow())
472  }
473  return;
474  }
475  const FunctionProtoType *Proto = FD->getType()->getAs<FunctionProtoType>();
476  if (!Proto)
477  return;
478 
480  // In C++17 and later, 'throw()' aka EST_DynamicNone is treated the same way
481  // as noexcept. In earlier standards, it is handled in this block, along with
482  // 'throw(X...)'.
483  if (EST == EST_Dynamic ||
484  (EST == EST_DynamicNone && !getLangOpts().CPlusPlus17)) {
485  // TODO: Revisit exception specifications for the MS ABI. There is a way to
486  // encode these in an object file but MSVC doesn't do anything with it.
487  if (getTarget().getCXXABI().isMicrosoft())
488  return;
489  // In Wasm EH we currently treat 'throw()' in the same way as 'noexcept'. In
490  // case of throw with types, we ignore it and print a warning for now.
491  // TODO Correctly handle exception specification in Wasm EH
493  if (EST == EST_DynamicNone)
495  else
497  diag::warn_wasm_dynamic_exception_spec_ignored)
499  return;
500  }
501  // Currently Emscripten EH only handles 'throw()' but not 'throw' with
502  // types. 'throw()' handling will be done in JS glue code so we don't need
503  // to do anything in that case. Just print a warning message in case of
504  // throw with types.
505  // TODO Correctly handle exception specification in Emscripten EH
506  if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly &&
507  CGM.getLangOpts().getExceptionHandling() ==
509  EST == EST_Dynamic)
511  diag::warn_wasm_dynamic_exception_spec_ignored)
513 
514  unsigned NumExceptions = Proto->getNumExceptions();
515  EHFilterScope *Filter = EHStack.pushFilter(NumExceptions);
516 
517  for (unsigned I = 0; I != NumExceptions; ++I) {
518  QualType Ty = Proto->getExceptionType(I);
519  QualType ExceptType = Ty.getNonReferenceType().getUnqualifiedType();
520  llvm::Value *EHType = CGM.GetAddrOfRTTIDescriptor(ExceptType,
521  /*ForEH=*/true);
522  Filter->setFilter(I, EHType);
523  }
524  } else if (Proto->canThrow() == CT_Cannot) {
525  // noexcept functions are simple terminate scopes.
526  if (!getLangOpts().EHAsynch) // -EHa: HW exception still can occur
528  }
529 }
530 
531 /// Emit the dispatch block for a filter scope if necessary.
533  EHFilterScope &filterScope) {
534  llvm::BasicBlock *dispatchBlock = filterScope.getCachedEHDispatchBlock();
535  if (!dispatchBlock) return;
536  if (dispatchBlock->use_empty()) {
537  delete dispatchBlock;
538  return;
539  }
540 
541  CGF.EmitBlockAfterUses(dispatchBlock);
542 
543  // If this isn't a catch-all filter, we need to check whether we got
544  // here because the filter triggered.
545  if (filterScope.getNumFilters()) {
546  // Load the selector value.
547  llvm::Value *selector = CGF.getSelectorFromSlot();
548  llvm::BasicBlock *unexpectedBB = CGF.createBasicBlock("ehspec.unexpected");
549 
550  llvm::Value *zero = CGF.Builder.getInt32(0);
551  llvm::Value *failsFilter =
552  CGF.Builder.CreateICmpSLT(selector, zero, "ehspec.fails");
553  CGF.Builder.CreateCondBr(failsFilter, unexpectedBB,
554  CGF.getEHResumeBlock(false));
555 
556  CGF.EmitBlock(unexpectedBB);
557  }
558 
559  // Call __cxa_call_unexpected. This doesn't need to be an invoke
560  // because __cxa_call_unexpected magically filters exceptions
561  // according to the last landing pad the exception was thrown
562  // into. Seriously.
563  llvm::Value *exn = CGF.getExceptionFromSlot();
564  CGF.EmitRuntimeCall(getUnexpectedFn(CGF.CGM), exn)
565  ->setDoesNotReturn();
566  CGF.Builder.CreateUnreachable();
567 }
568 
570  if (!CGM.getLangOpts().CXXExceptions)
571  return;
572 
573  const FunctionDecl* FD = dyn_cast_or_null<FunctionDecl>(D);
574  if (!FD) {
575  // Check if CapturedDecl is nothrow and pop terminate scope for it.
576  if (const CapturedDecl* CD = dyn_cast_or_null<CapturedDecl>(D)) {
577  if (CD->isNothrow() && !EHStack.empty())
579  }
580  return;
581  }
582  const FunctionProtoType *Proto = FD->getType()->getAs<FunctionProtoType>();
583  if (!Proto)
584  return;
585 
587  if (EST == EST_Dynamic ||
588  (EST == EST_DynamicNone && !getLangOpts().CPlusPlus17)) {
589  // TODO: Revisit exception specifications for the MS ABI. There is a way to
590  // encode these in an object file but MSVC doesn't do anything with it.
591  if (getTarget().getCXXABI().isMicrosoft())
592  return;
593  // In wasm we currently treat 'throw()' in the same way as 'noexcept'. In
594  // case of throw with types, we ignore it and print a warning for now.
595  // TODO Correctly handle exception specification in wasm
597  if (EST == EST_DynamicNone)
599  return;
600  }
601  EHFilterScope &filterScope = cast<EHFilterScope>(*EHStack.begin());
602  emitFilterDispatchBlock(*this, filterScope);
603  EHStack.popFilter();
604  } else if (Proto->canThrow() == CT_Cannot &&
605  /* possible empty when under async exceptions */
606  !EHStack.empty()) {
608  }
609 }
610 
612  EnterCXXTryStmt(S);
613  EmitStmt(S.getTryBlock());
614  ExitCXXTryStmt(S);
615 }
616 
617 void CodeGenFunction::EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock) {
618  unsigned NumHandlers = S.getNumHandlers();
619  EHCatchScope *CatchScope = EHStack.pushCatch(NumHandlers);
620 
621  for (unsigned I = 0; I != NumHandlers; ++I) {
622  const CXXCatchStmt *C = S.getHandler(I);
623 
624  llvm::BasicBlock *Handler = createBasicBlock("catch");
625  if (C->getExceptionDecl()) {
626  // FIXME: Dropping the reference type on the type into makes it
627  // impossible to correctly implement catch-by-reference
628  // semantics for pointers. Unfortunately, this is what all
629  // existing compilers do, and it's not clear that the standard
630  // personality routine is capable of doing this right. See C++ DR 388:
631  // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#388
632  Qualifiers CaughtTypeQuals;
634  C->getCaughtType().getNonReferenceType(), CaughtTypeQuals);
635 
636  CatchTypeInfo TypeInfo{nullptr, 0};
637  if (CaughtType->isObjCObjectPointerType())
638  TypeInfo.RTTI = CGM.getObjCRuntime().GetEHType(CaughtType);
639  else
641  CaughtType, C->getCaughtType());
642  CatchScope->setHandler(I, TypeInfo, Handler);
643  } else {
644  // No exception decl indicates '...', a catch-all.
645  CatchScope->setHandler(I, CGM.getCXXABI().getCatchAllTypeInfo(), Handler);
646  // Under async exceptions, catch(...) need to catch HW exception too
647  // Mark scope with SehTryBegin as a SEH __try scope
648  if (getLangOpts().EHAsynch)
650  }
651  }
652 }
653 
654 llvm::BasicBlock *
656  if (EHPersonality::get(*this).usesFuncletPads())
657  return getFuncletEHDispatchBlock(si);
658 
659  // The dispatch block for the end of the scope chain is a block that
660  // just resumes unwinding.
661  if (si == EHStack.stable_end())
662  return getEHResumeBlock(true);
663 
664  // Otherwise, we should look at the actual scope.
665  EHScope &scope = *EHStack.find(si);
666 
667  llvm::BasicBlock *dispatchBlock = scope.getCachedEHDispatchBlock();
668  if (!dispatchBlock) {
669  switch (scope.getKind()) {
670  case EHScope::Catch: {
671  // Apply a special case to a single catch-all.
672  EHCatchScope &catchScope = cast<EHCatchScope>(scope);
673  if (catchScope.getNumHandlers() == 1 &&
674  catchScope.getHandler(0).isCatchAll()) {
675  dispatchBlock = catchScope.getHandler(0).Block;
676 
677  // Otherwise, make a dispatch block.
678  } else {
679  dispatchBlock = createBasicBlock("catch.dispatch");
680  }
681  break;
682  }
683 
684  case EHScope::Cleanup:
685  dispatchBlock = createBasicBlock("ehcleanup");
686  break;
687 
688  case EHScope::Filter:
689  dispatchBlock = createBasicBlock("filter.dispatch");
690  break;
691 
692  case EHScope::Terminate:
693  dispatchBlock = getTerminateHandler();
694  break;
695  }
696  scope.setCachedEHDispatchBlock(dispatchBlock);
697  }
698  return dispatchBlock;
699 }
700 
701 llvm::BasicBlock *
703  // Returning nullptr indicates that the previous dispatch block should unwind
704  // to caller.
705  if (SI == EHStack.stable_end())
706  return nullptr;
707 
708  // Otherwise, we should look at the actual scope.
709  EHScope &EHS = *EHStack.find(SI);
710 
711  llvm::BasicBlock *DispatchBlock = EHS.getCachedEHDispatchBlock();
712  if (DispatchBlock)
713  return DispatchBlock;
714 
715  if (EHS.getKind() == EHScope::Terminate)
716  DispatchBlock = getTerminateFunclet();
717  else
718  DispatchBlock = createBasicBlock();
719  CGBuilderTy Builder(*this, DispatchBlock);
720 
721  switch (EHS.getKind()) {
722  case EHScope::Catch:
723  DispatchBlock->setName("catch.dispatch");
724  break;
725 
726  case EHScope::Cleanup:
727  DispatchBlock->setName("ehcleanup");
728  break;
729 
730  case EHScope::Filter:
731  llvm_unreachable("exception specifications not handled yet!");
732 
733  case EHScope::Terminate:
734  DispatchBlock->setName("terminate");
735  break;
736  }
737  EHS.setCachedEHDispatchBlock(DispatchBlock);
738  return DispatchBlock;
739 }
740 
741 /// Check whether this is a non-EH scope, i.e. a scope which doesn't
742 /// affect exception handling. Currently, the only non-EH scopes are
743 /// normal-only cleanup scopes.
744 static bool isNonEHScope(const EHScope &S) {
745  switch (S.getKind()) {
746  case EHScope::Cleanup:
747  return !cast<EHCleanupScope>(S).isEHCleanup();
748  case EHScope::Filter:
749  case EHScope::Catch:
750  case EHScope::Terminate:
751  return false;
752  }
753 
754  llvm_unreachable("Invalid EHScope Kind!");
755 }
756 
758  assert(EHStack.requiresLandingPad());
759  assert(!EHStack.empty());
760 
761  // If exceptions are disabled/ignored and SEH is not in use, then there is no
762  // invoke destination. SEH "works" even if exceptions are off. In practice,
763  // this means that C++ destructors and other EH cleanups don't run, which is
764  // consistent with MSVC's behavior, except in the presence of -EHa
765  const LangOptions &LO = CGM.getLangOpts();
766  if (!LO.Exceptions || LO.IgnoreExceptions) {
767  if (!LO.Borland && !LO.MicrosoftExt)
768  return nullptr;
770  return nullptr;
771  }
772 
773  // CUDA device code doesn't have exceptions.
774  if (LO.CUDA && LO.CUDAIsDevice)
775  return nullptr;
776 
777  // Check the innermost scope for a cached landing pad. If this is
778  // a non-EH cleanup, we'll check enclosing scopes in EmitLandingPad.
779  llvm::BasicBlock *LP = EHStack.begin()->getCachedLandingPad();
780  if (LP) return LP;
781 
782  const EHPersonality &Personality = EHPersonality::get(*this);
783 
784  if (!CurFn->hasPersonalityFn())
785  CurFn->setPersonalityFn(getOpaquePersonalityFn(CGM, Personality));
786 
787  if (Personality.usesFuncletPads()) {
788  // We don't need separate landing pads in the funclet model.
790  } else {
791  // Build the landing pad for this scope.
792  LP = EmitLandingPad();
793  }
794 
795  assert(LP);
796 
797  // Cache the landing pad on the innermost scope. If this is a
798  // non-EH scope, cache the landing pad on the enclosing scope, too.
799  for (EHScopeStack::iterator ir = EHStack.begin(); true; ++ir) {
800  ir->setCachedLandingPad(LP);
801  if (!isNonEHScope(*ir)) break;
802  }
803 
804  return LP;
805 }
806 
807 llvm::BasicBlock *CodeGenFunction::EmitLandingPad() {
808  assert(EHStack.requiresLandingPad());
809  assert(!CGM.getLangOpts().IgnoreExceptions &&
810  "LandingPad should not be emitted when -fignore-exceptions are in "
811  "effect.");
812  EHScope &innermostEHScope = *EHStack.find(EHStack.getInnermostEHScope());
813  switch (innermostEHScope.getKind()) {
814  case EHScope::Terminate:
815  return getTerminateLandingPad();
816 
817  case EHScope::Catch:
818  case EHScope::Cleanup:
819  case EHScope::Filter:
820  if (llvm::BasicBlock *lpad = innermostEHScope.getCachedLandingPad())
821  return lpad;
822  }
823 
824  // Save the current IR generation state.
825  CGBuilderTy::InsertPoint savedIP = Builder.saveAndClearIP();
826  auto DL = ApplyDebugLocation::CreateDefaultArtificial(*this, CurEHLocation);
827 
828  // Create and configure the landing pad.
829  llvm::BasicBlock *lpad = createBasicBlock("lpad");
830  EmitBlock(lpad);
831 
832  llvm::LandingPadInst *LPadInst =
833  Builder.CreateLandingPad(llvm::StructType::get(Int8PtrTy, Int32Ty), 0);
834 
835  llvm::Value *LPadExn = Builder.CreateExtractValue(LPadInst, 0);
837  llvm::Value *LPadSel = Builder.CreateExtractValue(LPadInst, 1);
839 
840  // Save the exception pointer. It's safe to use a single exception
841  // pointer per function because EH cleanups can never have nested
842  // try/catches.
843  // Build the landingpad instruction.
844 
845  // Accumulate all the handlers in scope.
846  bool hasCatchAll = false;
847  bool hasCleanup = false;
848  bool hasFilter = false;
849  SmallVector<llvm::Value*, 4> filterTypes;
851  for (EHScopeStack::iterator I = EHStack.begin(), E = EHStack.end(); I != E;
852  ++I) {
853 
854  switch (I->getKind()) {
855  case EHScope::Cleanup:
856  // If we have a cleanup, remember that.
857  hasCleanup = (hasCleanup || cast<EHCleanupScope>(*I).isEHCleanup());
858  continue;
859 
860  case EHScope::Filter: {
861  assert(I.next() == EHStack.end() && "EH filter is not end of EH stack");
862  assert(!hasCatchAll && "EH filter reached after catch-all");
863 
864  // Filter scopes get added to the landingpad in weird ways.
865  EHFilterScope &filter = cast<EHFilterScope>(*I);
866  hasFilter = true;
867 
868  // Add all the filter values.
869  for (unsigned i = 0, e = filter.getNumFilters(); i != e; ++i)
870  filterTypes.push_back(filter.getFilter(i));
871  goto done;
872  }
873 
874  case EHScope::Terminate:
875  // Terminate scopes are basically catch-alls.
876  assert(!hasCatchAll);
877  hasCatchAll = true;
878  goto done;
879 
880  case EHScope::Catch:
881  break;
882  }
883 
884  EHCatchScope &catchScope = cast<EHCatchScope>(*I);
885  for (unsigned hi = 0, he = catchScope.getNumHandlers(); hi != he; ++hi) {
886  EHCatchScope::Handler handler = catchScope.getHandler(hi);
887  assert(handler.Type.Flags == 0 &&
888  "landingpads do not support catch handler flags");
889 
890  // If this is a catch-all, register that and abort.
891  if (!handler.Type.RTTI) {
892  assert(!hasCatchAll);
893  hasCatchAll = true;
894  goto done;
895  }
896 
897  // Check whether we already have a handler for this type.
898  if (catchTypes.insert(handler.Type.RTTI).second)
899  // If not, add it directly to the landingpad.
900  LPadInst->addClause(handler.Type.RTTI);
901  }
902  }
903 
904  done:
905  // If we have a catch-all, add null to the landingpad.
906  assert(!(hasCatchAll && hasFilter));
907  if (hasCatchAll) {
908  LPadInst->addClause(getCatchAllValue(*this));
909 
910  // If we have an EH filter, we need to add those handlers in the
911  // right place in the landingpad, which is to say, at the end.
912  } else if (hasFilter) {
913  // Create a filter expression: a constant array indicating which filter
914  // types there are. The personality routine only lands here if the filter
915  // doesn't match.
917  llvm::ArrayType *AType =
918  llvm::ArrayType::get(!filterTypes.empty() ?
919  filterTypes[0]->getType() : Int8PtrTy,
920  filterTypes.size());
921 
922  for (unsigned i = 0, e = filterTypes.size(); i != e; ++i)
923  Filters.push_back(cast<llvm::Constant>(filterTypes[i]));
924  llvm::Constant *FilterArray = llvm::ConstantArray::get(AType, Filters);
925  LPadInst->addClause(FilterArray);
926 
927  // Also check whether we need a cleanup.
928  if (hasCleanup)
929  LPadInst->setCleanup(true);
930 
931  // Otherwise, signal that we at least have cleanups.
932  } else if (hasCleanup) {
933  LPadInst->setCleanup(true);
934  }
935 
936  assert((LPadInst->getNumClauses() > 0 || LPadInst->isCleanup()) &&
937  "landingpad instruction has no clauses!");
938 
939  // Tell the backend how to generate the landing pad.
941 
942  // Restore the old IR generation state.
943  Builder.restoreIP(savedIP);
944 
945  return lpad;
946 }
947 
948 static void emitCatchPadBlock(CodeGenFunction &CGF, EHCatchScope &CatchScope) {
949  llvm::BasicBlock *DispatchBlock = CatchScope.getCachedEHDispatchBlock();
950  assert(DispatchBlock);
951 
952  CGBuilderTy::InsertPoint SavedIP = CGF.Builder.saveIP();
953  CGF.EmitBlockAfterUses(DispatchBlock);
954 
955  llvm::Value *ParentPad = CGF.CurrentFuncletPad;
956  if (!ParentPad)
957  ParentPad = llvm::ConstantTokenNone::get(CGF.getLLVMContext());
958  llvm::BasicBlock *UnwindBB =
959  CGF.getEHDispatchBlock(CatchScope.getEnclosingEHScope());
960 
961  unsigned NumHandlers = CatchScope.getNumHandlers();
962  llvm::CatchSwitchInst *CatchSwitch =
963  CGF.Builder.CreateCatchSwitch(ParentPad, UnwindBB, NumHandlers);
964 
965  // Test against each of the exception types we claim to catch.
966  for (unsigned I = 0; I < NumHandlers; ++I) {
967  const EHCatchScope::Handler &Handler = CatchScope.getHandler(I);
968 
969  CatchTypeInfo TypeInfo = Handler.Type;
970  if (!TypeInfo.RTTI)
971  TypeInfo.RTTI = llvm::Constant::getNullValue(CGF.VoidPtrTy);
972 
973  CGF.Builder.SetInsertPoint(Handler.Block);
974 
975  if (EHPersonality::get(CGF).isMSVCXXPersonality()) {
976  CGF.Builder.CreateCatchPad(
977  CatchSwitch, {TypeInfo.RTTI, CGF.Builder.getInt32(TypeInfo.Flags),
978  llvm::Constant::getNullValue(CGF.VoidPtrTy)});
979  } else {
980  CGF.Builder.CreateCatchPad(CatchSwitch, {TypeInfo.RTTI});
981  }
982 
983  CatchSwitch->addHandler(Handler.Block);
984  }
985  CGF.Builder.restoreIP(SavedIP);
986 }
987 
988 // Wasm uses Windows-style EH instructions, but it merges all catch clauses into
989 // one big catchpad, within which we use Itanium's landingpad-style selector
990 // comparison instructions.
992  EHCatchScope &CatchScope) {
993  llvm::BasicBlock *DispatchBlock = CatchScope.getCachedEHDispatchBlock();
994  assert(DispatchBlock);
995 
996  CGBuilderTy::InsertPoint SavedIP = CGF.Builder.saveIP();
997  CGF.EmitBlockAfterUses(DispatchBlock);
998 
999  llvm::Value *ParentPad = CGF.CurrentFuncletPad;
1000  if (!ParentPad)
1001  ParentPad = llvm::ConstantTokenNone::get(CGF.getLLVMContext());
1002  llvm::BasicBlock *UnwindBB =
1003  CGF.getEHDispatchBlock(CatchScope.getEnclosingEHScope());
1004 
1005  unsigned NumHandlers = CatchScope.getNumHandlers();
1006  llvm::CatchSwitchInst *CatchSwitch =
1007  CGF.Builder.CreateCatchSwitch(ParentPad, UnwindBB, NumHandlers);
1008 
1009  // We don't use a landingpad instruction, so generate intrinsic calls to
1010  // provide exception and selector values.
1011  llvm::BasicBlock *WasmCatchStartBlock = CGF.createBasicBlock("catch.start");
1012  CatchSwitch->addHandler(WasmCatchStartBlock);
1013  CGF.EmitBlockAfterUses(WasmCatchStartBlock);
1014 
1015  // Create a catchpad instruction.
1016  SmallVector<llvm::Value *, 4> CatchTypes;
1017  for (unsigned I = 0, E = NumHandlers; I < E; ++I) {
1018  const EHCatchScope::Handler &Handler = CatchScope.getHandler(I);
1019  CatchTypeInfo TypeInfo = Handler.Type;
1020  if (!TypeInfo.RTTI)
1021  TypeInfo.RTTI = llvm::Constant::getNullValue(CGF.VoidPtrTy);
1022  CatchTypes.push_back(TypeInfo.RTTI);
1023  }
1024  auto *CPI = CGF.Builder.CreateCatchPad(CatchSwitch, CatchTypes);
1025 
1026  // Create calls to wasm.get.exception and wasm.get.ehselector intrinsics.
1027  // Before they are lowered appropriately later, they provide values for the
1028  // exception and selector.
1029  llvm::Function *GetExnFn =
1030  CGF.CGM.getIntrinsic(llvm::Intrinsic::wasm_get_exception);
1031  llvm::Function *GetSelectorFn =
1032  CGF.CGM.getIntrinsic(llvm::Intrinsic::wasm_get_ehselector);
1033  llvm::CallInst *Exn = CGF.Builder.CreateCall(GetExnFn, CPI);
1034  CGF.Builder.CreateStore(Exn, CGF.getExceptionSlot());
1035  llvm::CallInst *Selector = CGF.Builder.CreateCall(GetSelectorFn, CPI);
1036 
1037  llvm::Function *TypeIDFn = CGF.CGM.getIntrinsic(llvm::Intrinsic::eh_typeid_for);
1038 
1039  // If there's only a single catch-all, branch directly to its handler.
1040  if (CatchScope.getNumHandlers() == 1 &&
1041  CatchScope.getHandler(0).isCatchAll()) {
1042  CGF.Builder.CreateBr(CatchScope.getHandler(0).Block);
1043  CGF.Builder.restoreIP(SavedIP);
1044  return;
1045  }
1046 
1047  // Test against each of the exception types we claim to catch.
1048  for (unsigned I = 0, E = NumHandlers;; ++I) {
1049  assert(I < E && "ran off end of handlers!");
1050  const EHCatchScope::Handler &Handler = CatchScope.getHandler(I);
1051  CatchTypeInfo TypeInfo = Handler.Type;
1052  if (!TypeInfo.RTTI)
1053  TypeInfo.RTTI = llvm::Constant::getNullValue(CGF.VoidPtrTy);
1054 
1055  // Figure out the next block.
1056  llvm::BasicBlock *NextBlock;
1057 
1058  bool EmitNextBlock = false, NextIsEnd = false;
1059 
1060  // If this is the last handler, we're at the end, and the next block is a
1061  // block that contains a call to the rethrow function, so we can unwind to
1062  // the enclosing EH scope. The call itself will be generated later.
1063  if (I + 1 == E) {
1064  NextBlock = CGF.createBasicBlock("rethrow");
1065  EmitNextBlock = true;
1066  NextIsEnd = true;
1067 
1068  // If the next handler is a catch-all, we're at the end, and the
1069  // next block is that handler.
1070  } else if (CatchScope.getHandler(I + 1).isCatchAll()) {
1071  NextBlock = CatchScope.getHandler(I + 1).Block;
1072  NextIsEnd = true;
1073 
1074  // Otherwise, we're not at the end and we need a new block.
1075  } else {
1076  NextBlock = CGF.createBasicBlock("catch.fallthrough");
1077  EmitNextBlock = true;
1078  }
1079 
1080  // Figure out the catch type's index in the LSDA's type table.
1081  llvm::CallInst *TypeIndex = CGF.Builder.CreateCall(TypeIDFn, TypeInfo.RTTI);
1082  TypeIndex->setDoesNotThrow();
1083 
1084  llvm::Value *MatchesTypeIndex =
1085  CGF.Builder.CreateICmpEQ(Selector, TypeIndex, "matches");
1086  CGF.Builder.CreateCondBr(MatchesTypeIndex, Handler.Block, NextBlock);
1087 
1088  if (EmitNextBlock)
1089  CGF.EmitBlock(NextBlock);
1090  if (NextIsEnd)
1091  break;
1092  }
1093 
1094  CGF.Builder.restoreIP(SavedIP);
1095 }
1096 
1097 /// Emit the structure of the dispatch block for the given catch scope.
1098 /// It is an invariant that the dispatch block already exists.
1100  EHCatchScope &catchScope) {
1101  if (EHPersonality::get(CGF).isWasmPersonality())
1102  return emitWasmCatchPadBlock(CGF, catchScope);
1103  if (EHPersonality::get(CGF).usesFuncletPads())
1104  return emitCatchPadBlock(CGF, catchScope);
1105 
1106  llvm::BasicBlock *dispatchBlock = catchScope.getCachedEHDispatchBlock();
1107  assert(dispatchBlock);
1108 
1109  // If there's only a single catch-all, getEHDispatchBlock returned
1110  // that catch-all as the dispatch block.
1111  if (catchScope.getNumHandlers() == 1 &&
1112  catchScope.getHandler(0).isCatchAll()) {
1113  assert(dispatchBlock == catchScope.getHandler(0).Block);
1114  return;
1115  }
1116 
1117  CGBuilderTy::InsertPoint savedIP = CGF.Builder.saveIP();
1118  CGF.EmitBlockAfterUses(dispatchBlock);
1119 
1120  // Select the right handler.
1121  llvm::Function *llvm_eh_typeid_for =
1122  CGF.CGM.getIntrinsic(llvm::Intrinsic::eh_typeid_for);
1123 
1124  // Load the selector value.
1125  llvm::Value *selector = CGF.getSelectorFromSlot();
1126 
1127  // Test against each of the exception types we claim to catch.
1128  for (unsigned i = 0, e = catchScope.getNumHandlers(); ; ++i) {
1129  assert(i < e && "ran off end of handlers!");
1130  const EHCatchScope::Handler &handler = catchScope.getHandler(i);
1131 
1132  llvm::Value *typeValue = handler.Type.RTTI;
1133  assert(handler.Type.Flags == 0 &&
1134  "landingpads do not support catch handler flags");
1135  assert(typeValue && "fell into catch-all case!");
1136  typeValue = CGF.Builder.CreateBitCast(typeValue, CGF.Int8PtrTy);
1137 
1138  // Figure out the next block.
1139  bool nextIsEnd;
1140  llvm::BasicBlock *nextBlock;
1141 
1142  // If this is the last handler, we're at the end, and the next
1143  // block is the block for the enclosing EH scope.
1144  if (i + 1 == e) {
1145  nextBlock = CGF.getEHDispatchBlock(catchScope.getEnclosingEHScope());
1146  nextIsEnd = true;
1147 
1148  // If the next handler is a catch-all, we're at the end, and the
1149  // next block is that handler.
1150  } else if (catchScope.getHandler(i+1).isCatchAll()) {
1151  nextBlock = catchScope.getHandler(i+1).Block;
1152  nextIsEnd = true;
1153 
1154  // Otherwise, we're not at the end and we need a new block.
1155  } else {
1156  nextBlock = CGF.createBasicBlock("catch.fallthrough");
1157  nextIsEnd = false;
1158  }
1159 
1160  // Figure out the catch type's index in the LSDA's type table.
1161  llvm::CallInst *typeIndex =
1162  CGF.Builder.CreateCall(llvm_eh_typeid_for, typeValue);
1163  typeIndex->setDoesNotThrow();
1164 
1165  llvm::Value *matchesTypeIndex =
1166  CGF.Builder.CreateICmpEQ(selector, typeIndex, "matches");
1167  CGF.Builder.CreateCondBr(matchesTypeIndex, handler.Block, nextBlock);
1168 
1169  // If the next handler is a catch-all, we're completely done.
1170  if (nextIsEnd) {
1171  CGF.Builder.restoreIP(savedIP);
1172  return;
1173  }
1174  // Otherwise we need to emit and continue at that block.
1175  CGF.EmitBlock(nextBlock);
1176  }
1177 }
1178 
1180  EHCatchScope &catchScope = cast<EHCatchScope>(*EHStack.begin());
1181  if (catchScope.hasEHBranches())
1182  emitCatchDispatchBlock(*this, catchScope);
1183  EHStack.popCatch();
1184 }
1185 
1186 void CodeGenFunction::ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock) {
1187  unsigned NumHandlers = S.getNumHandlers();
1188  EHCatchScope &CatchScope = cast<EHCatchScope>(*EHStack.begin());
1189  assert(CatchScope.getNumHandlers() == NumHandlers);
1190  llvm::BasicBlock *DispatchBlock = CatchScope.getCachedEHDispatchBlock();
1191 
1192  // If the catch was not required, bail out now.
1193  if (!CatchScope.hasEHBranches()) {
1194  CatchScope.clearHandlerBlocks();
1195  EHStack.popCatch();
1196  return;
1197  }
1198 
1199  // Emit the structure of the EH dispatch for this catch.
1200  emitCatchDispatchBlock(*this, CatchScope);
1201 
1202  // Copy the handler blocks off before we pop the EH stack. Emitting
1203  // the handlers might scribble on this memory.
1205  CatchScope.begin(), CatchScope.begin() + NumHandlers);
1206 
1207  EHStack.popCatch();
1208 
1209  // The fall-through block.
1210  llvm::BasicBlock *ContBB = createBasicBlock("try.cont");
1211 
1212  // We just emitted the body of the try; jump to the continue block.
1213  if (HaveInsertPoint())
1214  Builder.CreateBr(ContBB);
1215 
1216  // Determine if we need an implicit rethrow for all these catch handlers;
1217  // see the comment below.
1218  bool doImplicitRethrow = false;
1219  if (IsFnTryBlock)
1220  doImplicitRethrow = isa<CXXDestructorDecl>(CurCodeDecl) ||
1221  isa<CXXConstructorDecl>(CurCodeDecl);
1222 
1223  // Wasm uses Windows-style EH instructions, but merges all catch clauses into
1224  // one big catchpad. So we save the old funclet pad here before we traverse
1225  // each catch handler.
1226  SaveAndRestore RestoreCurrentFuncletPad(CurrentFuncletPad);
1227  llvm::BasicBlock *WasmCatchStartBlock = nullptr;
1228  if (EHPersonality::get(*this).isWasmPersonality()) {
1229  auto *CatchSwitch =
1230  cast<llvm::CatchSwitchInst>(DispatchBlock->getFirstNonPHI());
1231  WasmCatchStartBlock = CatchSwitch->hasUnwindDest()
1232  ? CatchSwitch->getSuccessor(1)
1233  : CatchSwitch->getSuccessor(0);
1234  auto *CPI = cast<llvm::CatchPadInst>(WasmCatchStartBlock->getFirstNonPHI());
1235  CurrentFuncletPad = CPI;
1236  }
1237 
1238  // Perversely, we emit the handlers backwards precisely because we
1239  // want them to appear in source order. In all of these cases, the
1240  // catch block will have exactly one predecessor, which will be a
1241  // particular block in the catch dispatch. However, in the case of
1242  // a catch-all, one of the dispatch blocks will branch to two
1243  // different handlers, and EmitBlockAfterUses will cause the second
1244  // handler to be moved before the first.
1245  bool HasCatchAll = false;
1246  for (unsigned I = NumHandlers; I != 0; --I) {
1247  HasCatchAll |= Handlers[I - 1].isCatchAll();
1248  llvm::BasicBlock *CatchBlock = Handlers[I-1].Block;
1249  EmitBlockAfterUses(CatchBlock);
1250 
1251  // Catch the exception if this isn't a catch-all.
1252  const CXXCatchStmt *C = S.getHandler(I-1);
1253 
1254  // Enter a cleanup scope, including the catch variable and the
1255  // end-catch.
1256  RunCleanupsScope CatchScope(*this);
1257 
1258  // Initialize the catch variable and set up the cleanups.
1259  SaveAndRestore RestoreCurrentFuncletPad(CurrentFuncletPad);
1260  CGM.getCXXABI().emitBeginCatch(*this, C);
1261 
1262  // Emit the PGO counter increment.
1264 
1265  // Perform the body of the catch.
1266  EmitStmt(C->getHandlerBlock());
1267 
1268  // [except.handle]p11:
1269  // The currently handled exception is rethrown if control
1270  // reaches the end of a handler of the function-try-block of a
1271  // constructor or destructor.
1272 
1273  // It is important that we only do this on fallthrough and not on
1274  // return. Note that it's illegal to put a return in a
1275  // constructor function-try-block's catch handler (p14), so this
1276  // really only applies to destructors.
1277  if (doImplicitRethrow && HaveInsertPoint()) {
1278  CGM.getCXXABI().emitRethrow(*this, /*isNoReturn*/false);
1279  Builder.CreateUnreachable();
1280  Builder.ClearInsertionPoint();
1281  }
1282 
1283  // Fall out through the catch cleanups.
1284  CatchScope.ForceCleanup();
1285 
1286  // Branch out of the try.
1287  if (HaveInsertPoint())
1288  Builder.CreateBr(ContBB);
1289  }
1290 
1291  // Because in wasm we merge all catch clauses into one big catchpad, in case
1292  // none of the types in catch handlers matches after we test against each of
1293  // them, we should unwind to the next EH enclosing scope. We generate a call
1294  // to rethrow function here to do that.
1295  if (EHPersonality::get(*this).isWasmPersonality() && !HasCatchAll) {
1296  assert(WasmCatchStartBlock);
1297  // Navigate for the "rethrow" block we created in emitWasmCatchPadBlock().
1298  // Wasm uses landingpad-style conditional branches to compare selectors, so
1299  // we follow the false destination for each of the cond branches to reach
1300  // the rethrow block.
1301  llvm::BasicBlock *RethrowBlock = WasmCatchStartBlock;
1302  while (llvm::Instruction *TI = RethrowBlock->getTerminator()) {
1303  auto *BI = cast<llvm::BranchInst>(TI);
1304  assert(BI->isConditional());
1305  RethrowBlock = BI->getSuccessor(1);
1306  }
1307  assert(RethrowBlock != WasmCatchStartBlock && RethrowBlock->empty());
1308  Builder.SetInsertPoint(RethrowBlock);
1309  llvm::Function *RethrowInCatchFn =
1310  CGM.getIntrinsic(llvm::Intrinsic::wasm_rethrow);
1311  EmitNoreturnRuntimeCallOrInvoke(RethrowInCatchFn, {});
1312  }
1313 
1314  EmitBlock(ContBB);
1316 }
1317 
1318 namespace {
1319  struct CallEndCatchForFinally final : EHScopeStack::Cleanup {
1320  llvm::Value *ForEHVar;
1321  llvm::FunctionCallee EndCatchFn;
1322  CallEndCatchForFinally(llvm::Value *ForEHVar,
1323  llvm::FunctionCallee EndCatchFn)
1324  : ForEHVar(ForEHVar), EndCatchFn(EndCatchFn) {}
1325 
1326  void Emit(CodeGenFunction &CGF, Flags flags) override {
1327  llvm::BasicBlock *EndCatchBB = CGF.createBasicBlock("finally.endcatch");
1328  llvm::BasicBlock *CleanupContBB =
1329  CGF.createBasicBlock("finally.cleanup.cont");
1330 
1331  llvm::Value *ShouldEndCatch =
1332  CGF.Builder.CreateFlagLoad(ForEHVar, "finally.endcatch");
1333  CGF.Builder.CreateCondBr(ShouldEndCatch, EndCatchBB, CleanupContBB);
1334  CGF.EmitBlock(EndCatchBB);
1335  CGF.EmitRuntimeCallOrInvoke(EndCatchFn); // catch-all, so might throw
1336  CGF.EmitBlock(CleanupContBB);
1337  }
1338  };
1339 
1340  struct PerformFinally final : EHScopeStack::Cleanup {
1341  const Stmt *Body;
1342  llvm::Value *ForEHVar;
1343  llvm::FunctionCallee EndCatchFn;
1344  llvm::FunctionCallee RethrowFn;
1345  llvm::Value *SavedExnVar;
1346 
1347  PerformFinally(const Stmt *Body, llvm::Value *ForEHVar,
1348  llvm::FunctionCallee EndCatchFn,
1349  llvm::FunctionCallee RethrowFn, llvm::Value *SavedExnVar)
1350  : Body(Body), ForEHVar(ForEHVar), EndCatchFn(EndCatchFn),
1351  RethrowFn(RethrowFn), SavedExnVar(SavedExnVar) {}
1352 
1353  void Emit(CodeGenFunction &CGF, Flags flags) override {
1354  // Enter a cleanup to call the end-catch function if one was provided.
1355  if (EndCatchFn)
1356  CGF.EHStack.pushCleanup<CallEndCatchForFinally>(NormalAndEHCleanup,
1357  ForEHVar, EndCatchFn);
1358 
1359  // Save the current cleanup destination in case there are
1360  // cleanups in the finally block.
1361  llvm::Value *SavedCleanupDest =
1363  "cleanup.dest.saved");
1364 
1365  // Emit the finally block.
1366  CGF.EmitStmt(Body);
1367 
1368  // If the end of the finally is reachable, check whether this was
1369  // for EH. If so, rethrow.
1370  if (CGF.HaveInsertPoint()) {
1371  llvm::BasicBlock *RethrowBB = CGF.createBasicBlock("finally.rethrow");
1372  llvm::BasicBlock *ContBB = CGF.createBasicBlock("finally.cont");
1373 
1374  llvm::Value *ShouldRethrow =
1375  CGF.Builder.CreateFlagLoad(ForEHVar, "finally.shouldthrow");
1376  CGF.Builder.CreateCondBr(ShouldRethrow, RethrowBB, ContBB);
1377 
1378  CGF.EmitBlock(RethrowBB);
1379  if (SavedExnVar) {
1380  CGF.EmitRuntimeCallOrInvoke(RethrowFn,
1381  CGF.Builder.CreateAlignedLoad(CGF.Int8PtrTy, SavedExnVar,
1382  CGF.getPointerAlign()));
1383  } else {
1384  CGF.EmitRuntimeCallOrInvoke(RethrowFn);
1385  }
1386  CGF.Builder.CreateUnreachable();
1387 
1388  CGF.EmitBlock(ContBB);
1389 
1390  // Restore the cleanup destination.
1391  CGF.Builder.CreateStore(SavedCleanupDest,
1392  CGF.getNormalCleanupDestSlot());
1393  }
1394 
1395  // Leave the end-catch cleanup. As an optimization, pretend that
1396  // the fallthrough path was inaccessible; we've dynamically proven
1397  // that we're not in the EH case along that path.
1398  if (EndCatchFn) {
1399  CGBuilderTy::InsertPoint SavedIP = CGF.Builder.saveAndClearIP();
1400  CGF.PopCleanupBlock();
1401  CGF.Builder.restoreIP(SavedIP);
1402  }
1403 
1404  // Now make sure we actually have an insertion point or the
1405  // cleanup gods will hate us.
1406  CGF.EnsureInsertPoint();
1407  }
1408  };
1409 } // end anonymous namespace
1410 
1411 /// Enters a finally block for an implementation using zero-cost
1412 /// exceptions. This is mostly general, but hard-codes some
1413 /// language/ABI-specific behavior in the catch-all sections.
1415  llvm::FunctionCallee beginCatchFn,
1416  llvm::FunctionCallee endCatchFn,
1417  llvm::FunctionCallee rethrowFn) {
1418  assert((!!beginCatchFn) == (!!endCatchFn) &&
1419  "begin/end catch functions not paired");
1420  assert(rethrowFn && "rethrow function is required");
1421 
1422  BeginCatchFn = beginCatchFn;
1423 
1424  // The rethrow function has one of the following two types:
1425  // void (*)()
1426  // void (*)(void*)
1427  // In the latter case we need to pass it the exception object.
1428  // But we can't use the exception slot because the @finally might
1429  // have a landing pad (which would overwrite the exception slot).
1430  llvm::FunctionType *rethrowFnTy = rethrowFn.getFunctionType();
1431  SavedExnVar = nullptr;
1432  if (rethrowFnTy->getNumParams())
1433  SavedExnVar = CGF.CreateTempAlloca(CGF.Int8PtrTy, "finally.exn");
1434 
1435  // A finally block is a statement which must be executed on any edge
1436  // out of a given scope. Unlike a cleanup, the finally block may
1437  // contain arbitrary control flow leading out of itself. In
1438  // addition, finally blocks should always be executed, even if there
1439  // are no catch handlers higher on the stack. Therefore, we
1440  // surround the protected scope with a combination of a normal
1441  // cleanup (to catch attempts to break out of the block via normal
1442  // control flow) and an EH catch-all (semantically "outside" any try
1443  // statement to which the finally block might have been attached).
1444  // The finally block itself is generated in the context of a cleanup
1445  // which conditionally leaves the catch-all.
1446 
1447  // Jump destination for performing the finally block on an exception
1448  // edge. We'll never actually reach this block, so unreachable is
1449  // fine.
1450  RethrowDest = CGF.getJumpDestInCurrentScope(CGF.getUnreachableBlock());
1451 
1452  // Whether the finally block is being executed for EH purposes.
1453  ForEHVar = CGF.CreateTempAlloca(CGF.Builder.getInt1Ty(), "finally.for-eh");
1454  CGF.Builder.CreateFlagStore(false, ForEHVar);
1455 
1456  // Enter a normal cleanup which will perform the @finally block.
1457  CGF.EHStack.pushCleanup<PerformFinally>(NormalCleanup, body,
1458  ForEHVar, endCatchFn,
1459  rethrowFn, SavedExnVar);
1460 
1461  // Enter a catch-all scope.
1462  llvm::BasicBlock *catchBB = CGF.createBasicBlock("finally.catchall");
1463  EHCatchScope *catchScope = CGF.EHStack.pushCatch(1);
1464  catchScope->setCatchAllHandler(0, catchBB);
1465 }
1466 
1468  // Leave the finally catch-all.
1469  EHCatchScope &catchScope = cast<EHCatchScope>(*CGF.EHStack.begin());
1470  llvm::BasicBlock *catchBB = catchScope.getHandler(0).Block;
1471 
1472  CGF.popCatchScope();
1473 
1474  // If there are any references to the catch-all block, emit it.
1475  if (catchBB->use_empty()) {
1476  delete catchBB;
1477  } else {
1478  CGBuilderTy::InsertPoint savedIP = CGF.Builder.saveAndClearIP();
1479  CGF.EmitBlock(catchBB);
1480 
1481  llvm::Value *exn = nullptr;
1482 
1483  // If there's a begin-catch function, call it.
1484  if (BeginCatchFn) {
1485  exn = CGF.getExceptionFromSlot();
1486  CGF.EmitNounwindRuntimeCall(BeginCatchFn, exn);
1487  }
1488 
1489  // If we need to remember the exception pointer to rethrow later, do so.
1490  if (SavedExnVar) {
1491  if (!exn) exn = CGF.getExceptionFromSlot();
1492  CGF.Builder.CreateAlignedStore(exn, SavedExnVar, CGF.getPointerAlign());
1493  }
1494 
1495  // Tell the cleanups in the finally block that we're do this for EH.
1496  CGF.Builder.CreateFlagStore(true, ForEHVar);
1497 
1498  // Thread a jump through the finally cleanup.
1499  CGF.EmitBranchThroughCleanup(RethrowDest);
1500 
1501  CGF.Builder.restoreIP(savedIP);
1502  }
1503 
1504  // Finally, leave the @finally cleanup.
1505  CGF.PopCleanupBlock();
1506 }
1507 
1509  if (TerminateLandingPad)
1510  return TerminateLandingPad;
1511 
1512  CGBuilderTy::InsertPoint SavedIP = Builder.saveAndClearIP();
1513 
1514  // This will get inserted at the end of the function.
1515  TerminateLandingPad = createBasicBlock("terminate.lpad");
1516  Builder.SetInsertPoint(TerminateLandingPad);
1517 
1518  // Tell the backend that this is a landing pad.
1519  const EHPersonality &Personality = EHPersonality::get(*this);
1520 
1521  if (!CurFn->hasPersonalityFn())
1522  CurFn->setPersonalityFn(getOpaquePersonalityFn(CGM, Personality));
1523 
1524  llvm::LandingPadInst *LPadInst =
1525  Builder.CreateLandingPad(llvm::StructType::get(Int8PtrTy, Int32Ty), 0);
1526  LPadInst->addClause(getCatchAllValue(*this));
1527 
1528  llvm::Value *Exn = nullptr;
1529  if (getLangOpts().CPlusPlus)
1530  Exn = Builder.CreateExtractValue(LPadInst, 0);
1531  llvm::CallInst *terminateCall =
1533  terminateCall->setDoesNotReturn();
1534  Builder.CreateUnreachable();
1535 
1536  // Restore the saved insertion state.
1537  Builder.restoreIP(SavedIP);
1538 
1539  return TerminateLandingPad;
1540 }
1541 
1543  if (TerminateHandler)
1544  return TerminateHandler;
1545 
1546  // Set up the terminate handler. This block is inserted at the very
1547  // end of the function by FinishFunction.
1548  TerminateHandler = createBasicBlock("terminate.handler");
1549  CGBuilderTy::InsertPoint SavedIP = Builder.saveAndClearIP();
1550  Builder.SetInsertPoint(TerminateHandler);
1551 
1552  llvm::Value *Exn = nullptr;
1553  if (getLangOpts().CPlusPlus)
1554  Exn = getExceptionFromSlot();
1555  llvm::CallInst *terminateCall =
1557  terminateCall->setDoesNotReturn();
1558  Builder.CreateUnreachable();
1559 
1560  // Restore the saved insertion state.
1561  Builder.restoreIP(SavedIP);
1562 
1563  return TerminateHandler;
1564 }
1565 
1567  assert(EHPersonality::get(*this).usesFuncletPads() &&
1568  "use getTerminateLandingPad for non-funclet EH");
1569 
1570  llvm::BasicBlock *&TerminateFunclet = TerminateFunclets[CurrentFuncletPad];
1571  if (TerminateFunclet)
1572  return TerminateFunclet;
1573 
1574  CGBuilderTy::InsertPoint SavedIP = Builder.saveAndClearIP();
1575 
1576  // Set up the terminate handler. This block is inserted at the very
1577  // end of the function by FinishFunction.
1578  TerminateFunclet = createBasicBlock("terminate.handler");
1579  Builder.SetInsertPoint(TerminateFunclet);
1580 
1581  // Create the cleanuppad using the current parent pad as its token. Use 'none'
1582  // if this is a top-level terminate scope, which is the common case.
1583  SaveAndRestore RestoreCurrentFuncletPad(CurrentFuncletPad);
1584  llvm::Value *ParentPad = CurrentFuncletPad;
1585  if (!ParentPad)
1586  ParentPad = llvm::ConstantTokenNone::get(CGM.getLLVMContext());
1587  CurrentFuncletPad = Builder.CreateCleanupPad(ParentPad);
1588 
1589  // Emit the __std_terminate call.
1590  llvm::CallInst *terminateCall =
1592  terminateCall->setDoesNotReturn();
1593  Builder.CreateUnreachable();
1594 
1595  // Restore the saved insertion state.
1596  Builder.restoreIP(SavedIP);
1597 
1598  return TerminateFunclet;
1599 }
1600 
1601 llvm::BasicBlock *CodeGenFunction::getEHResumeBlock(bool isCleanup) {
1602  if (EHResumeBlock) return EHResumeBlock;
1603 
1604  CGBuilderTy::InsertPoint SavedIP = Builder.saveIP();
1605 
1606  // We emit a jump to a notional label at the outermost unwind state.
1607  EHResumeBlock = createBasicBlock("eh.resume");
1608  Builder.SetInsertPoint(EHResumeBlock);
1609 
1610  const EHPersonality &Personality = EHPersonality::get(*this);
1611 
1612  // This can always be a call because we necessarily didn't find
1613  // anything on the EH stack which needs our help.
1614  const char *RethrowName = Personality.CatchallRethrowFn;
1615  if (RethrowName != nullptr && !isCleanup) {
1617  getExceptionFromSlot())->setDoesNotReturn();
1618  Builder.CreateUnreachable();
1619  Builder.restoreIP(SavedIP);
1620  return EHResumeBlock;
1621  }
1622 
1623  // Recreate the landingpad's return value for the 'resume' instruction.
1624  llvm::Value *Exn = getExceptionFromSlot();
1625  llvm::Value *Sel = getSelectorFromSlot();
1626 
1627  llvm::Type *LPadType = llvm::StructType::get(Exn->getType(), Sel->getType());
1628  llvm::Value *LPadVal = llvm::UndefValue::get(LPadType);
1629  LPadVal = Builder.CreateInsertValue(LPadVal, Exn, 0, "lpad.val");
1630  LPadVal = Builder.CreateInsertValue(LPadVal, Sel, 1, "lpad.val");
1631 
1632  Builder.CreateResume(LPadVal);
1633  Builder.restoreIP(SavedIP);
1634  return EHResumeBlock;
1635 }
1636 
1638  EnterSEHTryStmt(S);
1639  {
1640  JumpDest TryExit = getJumpDestInCurrentScope("__try.__leave");
1641 
1642  SEHTryEpilogueStack.push_back(&TryExit);
1643 
1644  llvm::BasicBlock *TryBB = nullptr;
1645  // IsEHa: emit an invoke to _seh_try_begin() runtime for -EHa
1646  if (getLangOpts().EHAsynch) {
1648  if (SEHTryEpilogueStack.size() == 1) // outermost only
1649  TryBB = Builder.GetInsertBlock();
1650  }
1651 
1652  EmitStmt(S.getTryBlock());
1653 
1654  // Volatilize all blocks in Try, till current insert point
1655  if (TryBB) {
1657  VolatilizeTryBlocks(TryBB, Visited);
1658  }
1659 
1660  SEHTryEpilogueStack.pop_back();
1661 
1662  if (!TryExit.getBlock()->use_empty())
1663  EmitBlock(TryExit.getBlock(), /*IsFinished=*/true);
1664  else
1665  delete TryExit.getBlock();
1666  }
1667  ExitSEHTryStmt(S);
1668 }
1669 
1670 // Recursively walk through blocks in a _try
1671 // and make all memory instructions volatile
1673  llvm::BasicBlock *BB, llvm::SmallPtrSet<llvm::BasicBlock *, 10> &V) {
1674  if (BB == SEHTryEpilogueStack.back()->getBlock() /* end of Try */ ||
1675  !V.insert(BB).second /* already visited */ ||
1676  !BB->getParent() /* not emitted */ || BB->empty())
1677  return;
1678 
1679  if (!BB->isEHPad()) {
1680  for (llvm::BasicBlock::iterator J = BB->begin(), JE = BB->end(); J != JE;
1681  ++J) {
1682  if (auto LI = dyn_cast<llvm::LoadInst>(J)) {
1683  LI->setVolatile(true);
1684  } else if (auto SI = dyn_cast<llvm::StoreInst>(J)) {
1685  SI->setVolatile(true);
1686  } else if (auto* MCI = dyn_cast<llvm::MemIntrinsic>(J)) {
1687  MCI->setVolatile(llvm::ConstantInt::get(Builder.getInt1Ty(), 1));
1688  }
1689  }
1690  }
1691  const llvm::Instruction *TI = BB->getTerminator();
1692  if (TI) {
1693  unsigned N = TI->getNumSuccessors();
1694  for (unsigned I = 0; I < N; I++)
1695  VolatilizeTryBlocks(TI->getSuccessor(I), V);
1696  }
1697 }
1698 
1699 namespace {
1700 struct PerformSEHFinally final : EHScopeStack::Cleanup {
1701  llvm::Function *OutlinedFinally;
1702  PerformSEHFinally(llvm::Function *OutlinedFinally)
1703  : OutlinedFinally(OutlinedFinally) {}
1704 
1705  void Emit(CodeGenFunction &CGF, Flags F) override {
1706  ASTContext &Context = CGF.getContext();
1707  CodeGenModule &CGM = CGF.CGM;
1708 
1709  CallArgList Args;
1710 
1711  // Compute the two argument values.
1712  QualType ArgTys[2] = {Context.UnsignedCharTy, Context.VoidPtrTy};
1713  llvm::Value *FP = nullptr;
1714  // If CFG.IsOutlinedSEHHelper is true, then we are within a finally block.
1715  if (CGF.IsOutlinedSEHHelper) {
1716  FP = &CGF.CurFn->arg_begin()[1];
1717  } else {
1718  llvm::Function *LocalAddrFn =
1719  CGM.getIntrinsic(llvm::Intrinsic::localaddress);
1720  FP = CGF.Builder.CreateCall(LocalAddrFn);
1721  }
1722 
1723  llvm::Value *IsForEH =
1724  llvm::ConstantInt::get(CGF.ConvertType(ArgTys[0]), F.isForEHCleanup());
1725 
1726  // Except _leave and fall-through at the end, all other exits in a _try
1727  // (return/goto/continue/break) are considered as abnormal terminations
1728  // since _leave/fall-through is always Indexed 0,
1729  // just use NormalCleanupDestSlot (>= 1 for goto/return/..),
1730  // as 1st Arg to indicate abnormal termination
1731  if (!F.isForEHCleanup() && F.hasExitSwitch()) {
1732  Address Addr = CGF.getNormalCleanupDestSlot();
1733  llvm::Value *Load = CGF.Builder.CreateLoad(Addr, "cleanup.dest");
1734  llvm::Value *Zero = llvm::Constant::getNullValue(CGM.Int32Ty);
1735  IsForEH = CGF.Builder.CreateICmpNE(Load, Zero);
1736  }
1737 
1738  Args.add(RValue::get(IsForEH), ArgTys[0]);
1739  Args.add(RValue::get(FP), ArgTys[1]);
1740 
1741  // Arrange a two-arg function info and type.
1742  const CGFunctionInfo &FnInfo =
1743  CGM.getTypes().arrangeBuiltinFunctionCall(Context.VoidTy, Args);
1744 
1745  auto Callee = CGCallee::forDirect(OutlinedFinally);
1746  CGF.EmitCall(FnInfo, Callee, ReturnValueSlot(), Args);
1747  }
1748 };
1749 } // end anonymous namespace
1750 
1751 namespace {
1752 /// Find all local variable captures in the statement.
1753 struct CaptureFinder : ConstStmtVisitor<CaptureFinder> {
1755  const VarDecl *ParentThis;
1757  Address SEHCodeSlot = Address::invalid();
1758  CaptureFinder(CodeGenFunction &ParentCGF, const VarDecl *ParentThis)
1759  : ParentCGF(ParentCGF), ParentThis(ParentThis) {}
1760 
1761  // Return true if we need to do any capturing work.
1762  bool foundCaptures() {
1763  return !Captures.empty() || SEHCodeSlot.isValid();
1764  }
1765 
1766  void Visit(const Stmt *S) {
1767  // See if this is a capture, then recurse.
1769  for (const Stmt *Child : S->children())
1770  if (Child)
1771  Visit(Child);
1772  }
1773 
1774  void VisitDeclRefExpr(const DeclRefExpr *E) {
1775  // If this is already a capture, just make sure we capture 'this'.
1777  Captures.insert(ParentThis);
1778 
1779  const auto *D = dyn_cast<VarDecl>(E->getDecl());
1780  if (D && D->isLocalVarDeclOrParm() && D->hasLocalStorage())
1781  Captures.insert(D);
1782  }
1783 
1784  void VisitCXXThisExpr(const CXXThisExpr *E) {
1785  Captures.insert(ParentThis);
1786  }
1787 
1788  void VisitCallExpr(const CallExpr *E) {
1789  // We only need to add parent frame allocations for these builtins in x86.
1790  if (ParentCGF.getTarget().getTriple().getArch() != llvm::Triple::x86)
1791  return;
1792 
1793  unsigned ID = E->getBuiltinCallee();
1794  switch (ID) {
1795  case Builtin::BI__exception_code:
1796  case Builtin::BI_exception_code:
1797  // This is the simple case where we are the outermost finally. All we
1798  // have to do here is make sure we escape this and recover it in the
1799  // outlined handler.
1800  if (!SEHCodeSlot.isValid())
1801  SEHCodeSlot = ParentCGF.SEHCodeSlotStack.back();
1802  break;
1803  }
1804  }
1805 };
1806 } // end anonymous namespace
1807 
1809  Address ParentVar,
1810  llvm::Value *ParentFP) {
1811  llvm::CallInst *RecoverCall = nullptr;
1813  if (auto *ParentAlloca = dyn_cast<llvm::AllocaInst>(ParentVar.getPointer())) {
1814  // Mark the variable escaped if nobody else referenced it and compute the
1815  // localescape index.
1816  auto InsertPair = ParentCGF.EscapedLocals.insert(
1817  std::make_pair(ParentAlloca, ParentCGF.EscapedLocals.size()));
1818  int FrameEscapeIdx = InsertPair.first->second;
1819  // call i8* @llvm.localrecover(i8* bitcast(@parentFn), i8* %fp, i32 N)
1820  llvm::Function *FrameRecoverFn = llvm::Intrinsic::getDeclaration(
1821  &CGM.getModule(), llvm::Intrinsic::localrecover);
1822  llvm::Constant *ParentI8Fn =
1823  llvm::ConstantExpr::getBitCast(ParentCGF.CurFn, Int8PtrTy);
1824  RecoverCall = Builder.CreateCall(
1825  FrameRecoverFn, {ParentI8Fn, ParentFP,
1826  llvm::ConstantInt::get(Int32Ty, FrameEscapeIdx)});
1827 
1828  } else {
1829  // If the parent didn't have an alloca, we're doing some nested outlining.
1830  // Just clone the existing localrecover call, but tweak the FP argument to
1831  // use our FP value. All other arguments are constants.
1832  auto *ParentRecover =
1833  cast<llvm::IntrinsicInst>(ParentVar.getPointer()->stripPointerCasts());
1834  assert(ParentRecover->getIntrinsicID() == llvm::Intrinsic::localrecover &&
1835  "expected alloca or localrecover in parent LocalDeclMap");
1836  RecoverCall = cast<llvm::CallInst>(ParentRecover->clone());
1837  RecoverCall->setArgOperand(1, ParentFP);
1838  RecoverCall->insertBefore(AllocaInsertPt);
1839  }
1840 
1841  // Bitcast the variable, rename it, and insert it in the local decl map.
1842  llvm::Value *ChildVar =
1843  Builder.CreateBitCast(RecoverCall, ParentVar.getType());
1844  ChildVar->setName(ParentVar.getName());
1845  return ParentVar.withPointer(ChildVar);
1846 }
1847 
1849  const Stmt *OutlinedStmt,
1850  bool IsFilter) {
1851  // Find all captures in the Stmt.
1852  CaptureFinder Finder(ParentCGF, ParentCGF.CXXABIThisDecl);
1853  Finder.Visit(OutlinedStmt);
1854 
1855  // We can exit early on x86_64 when there are no captures. We just have to
1856  // save the exception code in filters so that __exception_code() works.
1857  if (!Finder.foundCaptures() &&
1858  CGM.getTarget().getTriple().getArch() != llvm::Triple::x86) {
1859  if (IsFilter)
1860  EmitSEHExceptionCodeSave(ParentCGF, nullptr, nullptr);
1861  return;
1862  }
1863 
1864  llvm::Value *EntryFP = nullptr;
1866  if (IsFilter && CGM.getTarget().getTriple().getArch() == llvm::Triple::x86) {
1867  // 32-bit SEH filters need to be careful about FP recovery. The end of the
1868  // EH registration is passed in as the EBP physical register. We can
1869  // recover that with llvm.frameaddress(1).
1870  EntryFP = Builder.CreateCall(
1871  CGM.getIntrinsic(llvm::Intrinsic::frameaddress, AllocaInt8PtrTy),
1872  {Builder.getInt32(1)});
1873  } else {
1874  // Otherwise, for x64 and 32-bit finally functions, the parent FP is the
1875  // second parameter.
1876  auto AI = CurFn->arg_begin();
1877  ++AI;
1878  EntryFP = &*AI;
1879  }
1880 
1881  llvm::Value *ParentFP = EntryFP;
1882  if (IsFilter) {
1883  // Given whatever FP the runtime provided us in EntryFP, recover the true
1884  // frame pointer of the parent function. We only need to do this in filters,
1885  // since finally funclets recover the parent FP for us.
1886  llvm::Function *RecoverFPIntrin =
1887  CGM.getIntrinsic(llvm::Intrinsic::eh_recoverfp);
1888  llvm::Constant *ParentI8Fn =
1889  llvm::ConstantExpr::getBitCast(ParentCGF.CurFn, Int8PtrTy);
1890  ParentFP = Builder.CreateCall(RecoverFPIntrin, {ParentI8Fn, EntryFP});
1891 
1892  // if the parent is a _finally, the passed-in ParentFP is the FP
1893  // of parent _finally, not Establisher's FP (FP of outermost function).
1894  // Establkisher FP is 2nd paramenter passed into parent _finally.
1895  // Fortunately, it's always saved in parent's frame. The following
1896  // code retrieves it, and escapes it so that spill instruction won't be
1897  // optimized away.
1898  if (ParentCGF.ParentCGF != nullptr) {
1899  // Locate and escape Parent's frame_pointer.addr alloca
1900  // Depending on target, should be 1st/2nd one in LocalDeclMap.
1901  // Let's just scan for ImplicitParamDecl with VoidPtrTy.
1902  llvm::AllocaInst *FramePtrAddrAlloca = nullptr;
1903  for (auto &I : ParentCGF.LocalDeclMap) {
1904  const VarDecl *D = cast<VarDecl>(I.first);
1905  if (isa<ImplicitParamDecl>(D) &&
1906  D->getType() == getContext().VoidPtrTy) {
1907  assert(D->getName().startswith("frame_pointer"));
1908  FramePtrAddrAlloca = cast<llvm::AllocaInst>(I.second.getPointer());
1909  break;
1910  }
1911  }
1912  assert(FramePtrAddrAlloca);
1913  auto InsertPair = ParentCGF.EscapedLocals.insert(
1914  std::make_pair(FramePtrAddrAlloca, ParentCGF.EscapedLocals.size()));
1915  int FrameEscapeIdx = InsertPair.first->second;
1916 
1917  // an example of a filter's prolog::
1918  // %0 = call i8* @llvm.eh.recoverfp(bitcast(@"?fin$0@0@main@@"),..)
1919  // %1 = call i8* @llvm.localrecover(bitcast(@"?fin$0@0@main@@"),..)
1920  // %2 = bitcast i8* %1 to i8**
1921  // %3 = load i8*, i8* *%2, align 8
1922  // ==> %3 is the frame-pointer of outermost host function
1923  llvm::Function *FrameRecoverFn = llvm::Intrinsic::getDeclaration(
1924  &CGM.getModule(), llvm::Intrinsic::localrecover);
1925  llvm::Constant *ParentI8Fn =
1926  llvm::ConstantExpr::getBitCast(ParentCGF.CurFn, Int8PtrTy);
1927  ParentFP = Builder.CreateCall(
1928  FrameRecoverFn, {ParentI8Fn, ParentFP,
1929  llvm::ConstantInt::get(Int32Ty, FrameEscapeIdx)});
1930  ParentFP = Builder.CreateBitCast(ParentFP, CGM.VoidPtrPtrTy);
1931  ParentFP = Builder.CreateLoad(
1932  Address(ParentFP, CGM.VoidPtrTy, getPointerAlign()));
1933  }
1934  }
1935 
1936  // Create llvm.localrecover calls for all captures.
1937  for (const VarDecl *VD : Finder.Captures) {
1938  if (VD->getType()->isVariablyModifiedType()) {
1939  CGM.ErrorUnsupported(VD, "VLA captured by SEH");
1940  continue;
1941  }
1942  assert((isa<ImplicitParamDecl>(VD) || VD->isLocalVarDeclOrParm()) &&
1943  "captured non-local variable");
1944 
1945  auto L = ParentCGF.LambdaCaptureFields.find(VD);
1946  if (L != ParentCGF.LambdaCaptureFields.end()) {
1947  LambdaCaptureFields[VD] = L->second;
1948  continue;
1949  }
1950 
1951  // If this decl hasn't been declared yet, it will be declared in the
1952  // OutlinedStmt.
1953  auto I = ParentCGF.LocalDeclMap.find(VD);
1954  if (I == ParentCGF.LocalDeclMap.end())
1955  continue;
1956 
1957  Address ParentVar = I->second;
1958  Address Recovered =
1959  recoverAddrOfEscapedLocal(ParentCGF, ParentVar, ParentFP);
1960  setAddrOfLocalVar(VD, Recovered);
1961 
1962  if (isa<ImplicitParamDecl>(VD)) {
1963  CXXABIThisAlignment = ParentCGF.CXXABIThisAlignment;
1964  CXXThisAlignment = ParentCGF.CXXThisAlignment;
1965  CXXABIThisValue = Builder.CreateLoad(Recovered, "this");
1968  // We are in a lambda function where "this" is captured so the
1969  // CXXThisValue need to be loaded from the lambda capture
1970  LValue ThisFieldLValue =
1973  CXXThisValue = ThisFieldLValue.getAddress(*this).getPointer();
1974  } else {
1975  CXXThisValue = EmitLoadOfLValue(ThisFieldLValue, SourceLocation())
1976  .getScalarVal();
1977  }
1978  } else {
1979  CXXThisValue = CXXABIThisValue;
1980  }
1981  }
1982  }
1983 
1984  if (Finder.SEHCodeSlot.isValid()) {
1985  SEHCodeSlotStack.push_back(
1986  recoverAddrOfEscapedLocal(ParentCGF, Finder.SEHCodeSlot, ParentFP));
1987  }
1988 
1989  if (IsFilter)
1990  EmitSEHExceptionCodeSave(ParentCGF, ParentFP, EntryFP);
1991 }
1992 
1993 /// Arrange a function prototype that can be called by Windows exception
1994 /// handling personalities. On Win64, the prototype looks like:
1995 /// RetTy func(void *EHPtrs, void *ParentFP);
1997  bool IsFilter,
1998  const Stmt *OutlinedStmt) {
1999  SourceLocation StartLoc = OutlinedStmt->getBeginLoc();
2000 
2001  // Get the mangled function name.
2002  SmallString<128> Name;
2003  {
2004  llvm::raw_svector_ostream OS(Name);
2005  GlobalDecl ParentSEHFn = ParentCGF.CurSEHParent;
2006  assert(ParentSEHFn && "No CurSEHParent!");
2008  if (IsFilter)
2009  Mangler.mangleSEHFilterExpression(ParentSEHFn, OS);
2010  else
2011  Mangler.mangleSEHFinallyBlock(ParentSEHFn, OS);
2012  }
2013 
2014  FunctionArgList Args;
2015  if (CGM.getTarget().getTriple().getArch() != llvm::Triple::x86 || !IsFilter) {
2016  // All SEH finally functions take two parameters. Win64 filters take two
2017  // parameters. Win32 filters take no parameters.
2018  if (IsFilter) {
2019  Args.push_back(ImplicitParamDecl::Create(
2020  getContext(), /*DC=*/nullptr, StartLoc,
2021  &getContext().Idents.get("exception_pointers"),
2023  } else {
2024  Args.push_back(ImplicitParamDecl::Create(
2025  getContext(), /*DC=*/nullptr, StartLoc,
2026  &getContext().Idents.get("abnormal_termination"),
2027  getContext().UnsignedCharTy, ImplicitParamDecl::Other));
2028  }
2029  Args.push_back(ImplicitParamDecl::Create(
2030  getContext(), /*DC=*/nullptr, StartLoc,
2031  &getContext().Idents.get("frame_pointer"), getContext().VoidPtrTy,
2033  }
2034 
2035  QualType RetTy = IsFilter ? getContext().LongTy : getContext().VoidTy;
2036 
2037  const CGFunctionInfo &FnInfo =
2039 
2040  llvm::FunctionType *FnTy = CGM.getTypes().GetFunctionType(FnInfo);
2041  llvm::Function *Fn = llvm::Function::Create(
2042  FnTy, llvm::GlobalValue::InternalLinkage, Name.str(), &CGM.getModule());
2043 
2044  IsOutlinedSEHHelper = true;
2045 
2046  StartFunction(GlobalDecl(), RetTy, Fn, FnInfo, Args,
2047  OutlinedStmt->getBeginLoc(), OutlinedStmt->getBeginLoc());
2049 
2051  EmitCapturedLocals(ParentCGF, OutlinedStmt, IsFilter);
2052 }
2053 
2054 /// Create a stub filter function that will ultimately hold the code of the
2055 /// filter expression. The EH preparation passes in LLVM will outline the code
2056 /// from the main function body into this stub.
2057 llvm::Function *
2059  const SEHExceptStmt &Except) {
2060  const Expr *FilterExpr = Except.getFilterExpr();
2061  startOutlinedSEHHelper(ParentCGF, true, FilterExpr);
2062 
2063  // Emit the original filter expression, convert to i32, and return.
2064  llvm::Value *R = EmitScalarExpr(FilterExpr);
2065  R = Builder.CreateIntCast(R, ConvertType(getContext().LongTy),
2066  FilterExpr->getType()->isSignedIntegerType());
2068 
2069  FinishFunction(FilterExpr->getEndLoc());
2070 
2071  return CurFn;
2072 }
2073 
2074 llvm::Function *
2076  const SEHFinallyStmt &Finally) {
2077  const Stmt *FinallyBlock = Finally.getBlock();
2078  startOutlinedSEHHelper(ParentCGF, false, FinallyBlock);
2079 
2080  // Emit the original filter expression, convert to i32, and return.
2081  EmitStmt(FinallyBlock);
2082 
2083  FinishFunction(FinallyBlock->getEndLoc());
2084 
2085  return CurFn;
2086 }
2087 
2089  llvm::Value *ParentFP,
2090  llvm::Value *EntryFP) {
2091  // Get the pointer to the EXCEPTION_POINTERS struct. This is returned by the
2092  // __exception_info intrinsic.
2093  if (CGM.getTarget().getTriple().getArch() != llvm::Triple::x86) {
2094  // On Win64, the info is passed as the first parameter to the filter.
2095  SEHInfo = &*CurFn->arg_begin();
2096  SEHCodeSlotStack.push_back(
2097  CreateMemTemp(getContext().IntTy, "__exception_code"));
2098  } else {
2099  // On Win32, the EBP on entry to the filter points to the end of an
2100  // exception registration object. It contains 6 32-bit fields, and the info
2101  // pointer is stored in the second field. So, GEP 20 bytes backwards and
2102  // load the pointer.
2103  SEHInfo = Builder.CreateConstInBoundsGEP1_32(Int8Ty, EntryFP, -20);
2104  SEHInfo = Builder.CreateBitCast(SEHInfo, Int8PtrTy->getPointerTo());
2107  ParentCGF, ParentCGF.SEHCodeSlotStack.back(), ParentFP));
2108  }
2109 
2110  // Save the exception code in the exception slot to unify exception access in
2111  // the filter function and the landing pad.
2112  // struct EXCEPTION_POINTERS {
2113  // EXCEPTION_RECORD *ExceptionRecord;
2114  // CONTEXT *ContextRecord;
2115  // };
2116  // int exceptioncode = exception_pointers->ExceptionRecord->ExceptionCode;
2117  llvm::Type *RecordTy = CGM.Int32Ty->getPointerTo();
2118  llvm::Type *PtrsTy = llvm::StructType::get(RecordTy, CGM.VoidPtrTy);
2119  llvm::Value *Ptrs = Builder.CreateBitCast(SEHInfo, PtrsTy->getPointerTo());
2120  llvm::Value *Rec = Builder.CreateStructGEP(PtrsTy, Ptrs, 0);
2121  Rec = Builder.CreateAlignedLoad(RecordTy, Rec, getPointerAlign());
2122  llvm::Value *Code = Builder.CreateAlignedLoad(Int32Ty, Rec, getIntAlign());
2123  assert(!SEHCodeSlotStack.empty() && "emitting EH code outside of __except");
2124  Builder.CreateStore(Code, SEHCodeSlotStack.back());
2125 }
2126 
2128  // Sema should diagnose calling this builtin outside of a filter context, but
2129  // don't crash if we screw up.
2130  if (!SEHInfo)
2131  return llvm::UndefValue::get(Int8PtrTy);
2132  assert(SEHInfo->getType() == Int8PtrTy);
2133  return SEHInfo;
2134 }
2135 
2137  assert(!SEHCodeSlotStack.empty() && "emitting EH code outside of __except");
2138  return Builder.CreateLoad(SEHCodeSlotStack.back());
2139 }
2140 
2142  // Abnormal termination is just the first parameter to the outlined finally
2143  // helper.
2144  auto AI = CurFn->arg_begin();
2145  return Builder.CreateZExt(&*AI, Int32Ty);
2146 }
2147 
2149  llvm::Function *FinallyFunc) {
2150  EHStack.pushCleanup<PerformSEHFinally>(Kind, FinallyFunc);
2151 }
2152 
2154  CodeGenFunction HelperCGF(CGM, /*suppressNewContext=*/true);
2155  HelperCGF.ParentCGF = this;
2156  if (const SEHFinallyStmt *Finally = S.getFinallyHandler()) {
2157  // Outline the finally block.
2158  llvm::Function *FinallyFunc =
2159  HelperCGF.GenerateSEHFinallyFunction(*this, *Finally);
2160 
2161  // Push a cleanup for __finally blocks.
2162  EHStack.pushCleanup<PerformSEHFinally>(NormalAndEHCleanup, FinallyFunc);
2163  return;
2164  }
2165 
2166  // Otherwise, we must have an __except block.
2167  const SEHExceptStmt *Except = S.getExceptHandler();
2168  assert(Except);
2169  EHCatchScope *CatchScope = EHStack.pushCatch(1);
2170  SEHCodeSlotStack.push_back(
2171  CreateMemTemp(getContext().IntTy, "__exception_code"));
2172 
2173  // If the filter is known to evaluate to 1, then we can use the clause
2174  // "catch i8* null". We can't do this on x86 because the filter has to save
2175  // the exception code.
2176  llvm::Constant *C =
2178  getContext().IntTy);
2179  if (CGM.getTarget().getTriple().getArch() != llvm::Triple::x86 && C &&
2180  C->isOneValue()) {
2181  CatchScope->setCatchAllHandler(0, createBasicBlock("__except"));
2182  return;
2183  }
2184 
2185  // In general, we have to emit an outlined filter function. Use the function
2186  // in place of the RTTI typeinfo global that C++ EH uses.
2187  llvm::Function *FilterFunc =
2188  HelperCGF.GenerateSEHFilterFunction(*this, *Except);
2189  llvm::Constant *OpaqueFunc =
2190  llvm::ConstantExpr::getBitCast(FilterFunc, Int8PtrTy);
2191  CatchScope->setHandler(0, OpaqueFunc, createBasicBlock("__except.ret"));
2192 }
2193 
2195  // Just pop the cleanup if it's a __finally block.
2196  if (S.getFinallyHandler()) {
2197  PopCleanupBlock();
2198  return;
2199  }
2200 
2201  // IsEHa: emit an invoke _seh_try_end() to mark end of FT flow
2202  if (getLangOpts().EHAsynch && Builder.GetInsertBlock()) {
2203  llvm::FunctionCallee SehTryEnd = getSehTryEndFn(CGM);
2204  EmitRuntimeCallOrInvoke(SehTryEnd);
2205  }
2206 
2207  // Otherwise, we must have an __except block.
2208  const SEHExceptStmt *Except = S.getExceptHandler();
2209  assert(Except && "__try must have __finally xor __except");
2210  EHCatchScope &CatchScope = cast<EHCatchScope>(*EHStack.begin());
2211 
2212  // Don't emit the __except block if the __try block lacked invokes.
2213  // TODO: Model unwind edges from instructions, either with iload / istore or
2214  // a try body function.
2215  if (!CatchScope.hasEHBranches()) {
2216  CatchScope.clearHandlerBlocks();
2217  EHStack.popCatch();
2218  SEHCodeSlotStack.pop_back();
2219  return;
2220  }
2221 
2222  // The fall-through block.
2223  llvm::BasicBlock *ContBB = createBasicBlock("__try.cont");
2224 
2225  // We just emitted the body of the __try; jump to the continue block.
2226  if (HaveInsertPoint())
2227  Builder.CreateBr(ContBB);
2228 
2229  // Check if our filter function returned true.
2230  emitCatchDispatchBlock(*this, CatchScope);
2231 
2232  // Grab the block before we pop the handler.
2233  llvm::BasicBlock *CatchPadBB = CatchScope.getHandler(0).Block;
2234  EHStack.popCatch();
2235 
2236  EmitBlockAfterUses(CatchPadBB);
2237 
2238  // __except blocks don't get outlined into funclets, so immediately do a
2239  // catchret.
2240  llvm::CatchPadInst *CPI =
2241  cast<llvm::CatchPadInst>(CatchPadBB->getFirstNonPHI());
2242  llvm::BasicBlock *ExceptBB = createBasicBlock("__except");
2243  Builder.CreateCatchRet(CPI, ExceptBB);
2244  EmitBlock(ExceptBB);
2245 
2246  // On Win64, the exception code is returned in EAX. Copy it into the slot.
2247  if (CGM.getTarget().getTriple().getArch() != llvm::Triple::x86) {
2248  llvm::Function *SEHCodeIntrin =
2249  CGM.getIntrinsic(llvm::Intrinsic::eh_exceptioncode);
2250  llvm::Value *Code = Builder.CreateCall(SEHCodeIntrin, {CPI});
2251  Builder.CreateStore(Code, SEHCodeSlotStack.back());
2252  }
2253 
2254  // Emit the __except body.
2255  EmitStmt(Except->getBlock());
2256 
2257  // End the lifetime of the exception code.
2258  SEHCodeSlotStack.pop_back();
2259 
2260  if (HaveInsertPoint())
2261  Builder.CreateBr(ContBB);
2262 
2263  EmitBlock(ContBB);
2264 }
2265 
2267  // If this code is reachable then emit a stop point (if generating
2268  // debug info). We have to do this ourselves because we are on the
2269  // "simple" statement path.
2270  if (HaveInsertPoint())
2271  EmitStopPoint(&S);
2272 
2273  // This must be a __leave from a __finally block, which we warn on and is UB.
2274  // Just emit unreachable.
2275  if (!isSEHTryScope()) {
2276  Builder.CreateUnreachable();
2277  Builder.ClearInsertionPoint();
2278  return;
2279  }
2280 
2282 }
clang::CodeGen::CodeGenFunction::getEHSelectorSlot
Address getEHSelectorSlot()
Definition: CGException.cpp:427
clang::CodeGen::EHPersonality::isWasmPersonality
bool isWasmPersonality() const
Definition: CGCleanup.h:628
clang::InternalLinkage
@ InternalLinkage
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
Definition: Linkage.h:31
clang::CodeGen::CatchTypeInfo::RTTI
llvm::Constant * RTTI
Definition: CGCleanup.h:37
emitCatchPadBlock
static void emitCatchPadBlock(CodeGenFunction &CGF, EHCatchScope &CatchScope)
Definition: CGException.cpp:948
clang::CodeGen::CodeGenFunction::ConvertTypeForMem
llvm::Type * ConvertTypeForMem(QualType T)
Definition: CodeGenFunction.cpp:210
getSEHPersonalityMSVC
static const EHPersonality & getSEHPersonalityMSVC(const llvm::Triple &T)
Definition: CGException.cpp:224
clang::CodeGen::EHPersonality::GNU_C_SJLJ
static const EHPersonality GNU_C_SJLJ
Definition: CGCleanup.h:600
clang::CodeGen::CodeGenFunction::EmitBlockAfterUses
void EmitBlockAfterUses(llvm::BasicBlock *BB)
EmitBlockAfterUses - Emit the given block somewhere hopefully near its uses, and leave the insertion ...
Definition: CGStmt.cpp:600
clang::LangOptions::hasSEHExceptions
bool hasSEHExceptions() const
Definition: LangOptions.h:607
clang::CodeGen::CodeGenFunction::isSEHTryScope
bool isSEHTryScope() const
Returns true inside SEH __try blocks.
Definition: CodeGenFunction.h:759
clang::CodeGen::CodeGenFunction::EmitCXXTryStmt
void EmitCXXTryStmt(const CXXTryStmt &S)
Definition: CGException.cpp:611
clang::CodeGen::CodeGenTypeCache::Int8PtrTy
llvm::PointerType * Int8PtrTy
Definition: CodeGenTypeCache.h:57
getObjCPersonality
static const EHPersonality & getObjCPersonality(const TargetInfo &Target, const LangOptions &L)
Definition: CGException.cpp:145
clang::CodeGen::EHPersonality::NeXT_ObjC
static const EHPersonality NeXT_ObjC
Definition: CGCleanup.h:607
clang::CodeGen::CodeGenFunction::EmitEndEHSpec
void EmitEndEHSpec(const Decl *D)
EmitEndEHSpec - Emit the end of the exception spec.
Definition: CGException.cpp:569
clang::CodeGen::CatchTypeInfo::Flags
unsigned Flags
Definition: CGCleanup.h:38
clang::LangOptions::ExceptionHandlingKind::None
@ None
clang::FunctionProtoType::getExceptionSpecType
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition: Type.h:4252
clang::CodeGen::CodeGenTypeCache::IntTy
llvm::IntegerType * IntTy
int
Definition: CodeGenTypeCache.h:42
clang::MangleContext::mangleSEHFinallyBlock
virtual void mangleSEHFinallyBlock(GlobalDecl EnclosingDecl, raw_ostream &Out)=0
clang::CodeGen::EHScope::Cleanup
@ Cleanup
Definition: CGCleanup.h:104
clang::CodeGen::CodeGenModule::CreateRuntimeFunction
llvm::FunctionCallee CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList(), bool Local=false, bool AssumeConvergent=false)
Create or return a runtime function declaration with the specified type and name.
Definition: CodeGenModule.cpp:4215
clang::CodeGen::EHPersonality::GNU_C
static const EHPersonality GNU_C
Definition: CGCleanup.h:599
clang::CodeGen::CodeGenFunction::getTerminateLandingPad
llvm::BasicBlock * getTerminateLandingPad()
getTerminateLandingPad - Return a landing pad that just calls terminate.
Definition: CGException.cpp:1508
clang::CodeGen::EHPersonality::GNUstep_ObjC
static const EHPersonality GNUstep_ObjC
Definition: CGCleanup.h:605
clang::CodeGen::CodeGenFunction::EmitSEHAbnormalTermination
llvm::Value * EmitSEHAbnormalTermination()
Definition: CGException.cpp:2141
clang::ObjCRuntime::GCC
@ GCC
'gcc' is the Objective-C runtime shipped with GCC, implementing a fragile Objective-C ABI
Definition: ObjCRuntime.h:53
CodeGenFunction.h
clang::CodeGen::EHPersonality::GNU_CPlusPlus_SEH
static const EHPersonality GNU_CPlusPlus_SEH
Definition: CGCleanup.h:610
clang::CodeGen::CodeGenFunction::EmitCall
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **callOrInvoke, bool IsMustTail, SourceLocation Loc)
EmitCall - Generate a call of the given function, expecting the given result type,...
Definition: CGCall.cpp:4728
clang::CodeGen::CodeGenFunction::currentFunctionUsesSEHTry
bool currentFunctionUsesSEHTry() const
Definition: CodeGenFunction.h:2024
clang::CodeGen::CGCXXABI::getAddrOfCXXCatchHandlerType
virtual CatchTypeInfo getAddrOfCXXCatchHandlerType(QualType Ty, QualType CatchHandlerType)=0
clang::CodeGen::EHScopeStack::pushFilter
class EHFilterScope * pushFilter(unsigned NumFilters)
Push an exceptions filter on the stack.
Definition: CGCleanup.cpp:242
clang::CodeGen::CodeGenFunction::CurCodeDecl
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
Definition: CodeGenFunction.h:322
clang::CodeGen::EHCatchScope::Handler::isCatchAll
bool isCatchAll() const
Definition: CGCleanup.h:161
clang::CodeGen::CodeGenFunction::EmitNounwindRuntimeCall
llvm::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
clang::CodeGen::EHCatchScope::begin
iterator begin() const
Definition: CGCleanup.h:222
clang::ASTContext::VoidTy
CanQualType VoidTy
Definition: ASTContext.h:1080
clang::ObjCRuntime::getKind
Kind getKind() const
Definition: ObjCRuntime.h:77
llvm::SmallVector
Definition: LLVM.h:38
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::CodeGen::CodeGenModule::SetInternalFunctionAttributes
void SetInternalFunctionAttributes(GlobalDecl GD, llvm::Function *F, const CGFunctionInfo &FI)
Set the attributes on the LLVM function for the given decl and function info.
Definition: CodeGenModule.cpp:2273
clang::QualType::getQualifiers
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:6662
clang::TargetCXXABI::isMicrosoft
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
Definition: TargetCXXABI.h:138
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::EHScopeStack::pushCatch
class EHCatchScope * pushCatch(unsigned NumHandlers)
Push a set of catch handlers on the stack.
Definition: CGCleanup.cpp:259
clang::CodeGen::EHCatchScope::setCatchAllHandler
void setCatchAllHandler(unsigned I, llvm::BasicBlock *Block)
Definition: CGCleanup.h:191
clang::CodeGen::EHScope::getCachedLandingPad
llvm::BasicBlock * getCachedLandingPad() const
Definition: CGCleanup.h:114
clang::MultiVersionKind::Target
@ Target
clang::CodeGen::CodeGenFunction::PopCleanupBlock
void PopCleanupBlock(bool FallThroughIsBranchThrough=false)
PopCleanupBlock - Will pop the cleanup entry on the stack and process all branch fixups.
Definition: CGCleanup.cpp:659
clang::QualType::getNonReferenceType
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
Definition: Type.h:6831
clang::CodeGen::CodeGenFunction::FinallyInfo::enter
void enter(CodeGenFunction &CGF, const Stmt *Finally, llvm::FunctionCallee beginCatchFn, llvm::FunctionCallee endCatchFn, llvm::FunctionCallee rethrowFn)
Enters a finally block for an implementation using zero-cost exceptions.
Definition: CGException.cpp:1414
clang::FunctionDecl::getExceptionSpecSourceRange
SourceRange getExceptionSpecSourceRange() const
Attempt to compute an informative source range covering the function exception specification,...
Definition: Decl.cpp:3665
clang::CodeGen::CodeGenTypeCache::getPointerAlign
CharUnits getPointerAlign() const
Definition: CodeGenTypeCache.h:117
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:737
clang::CodeGen::EHScope
A protected scope for zero-cost EH handling.
Definition: CGCleanup.h:42
clang::tooling::Filter
llvm::cl::opt< std::string > Filter
clang::CodeGen::EHCatchScope::getHandler
const Handler & getHandler(unsigned I) const
Definition: CGCleanup.h:207
clang::CodeGen::CodeGenModule::getContext
ASTContext & getContext() const
Definition: CodeGenModule.h:728
clang::CodeGen::Address::isValid
bool isValid() const
Definition: Address.h:91
clang::CodeGen::CodeGenFunction::getTerminateHandler
llvm::BasicBlock * getTerminateHandler()
getTerminateHandler - Return a handler (not a landing pad, just a catch handler) that just calls term...
Definition: CGException.cpp:1542
clang::EST_Dynamic
@ EST_Dynamic
throw(T1, T2)
Definition: ExceptionSpecificationType.h:23
clang::Qualifiers
The collection of all-type qualifiers we support.
Definition: Type.h:147
clang::TargetInfo::getCXXABI
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
Definition: TargetInfo.h:1272
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:4252
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:205
clang::CodeGen::CodeGenFunction::SEHInfo
llvm::Value * SEHInfo
Value returned by __exception_info intrinsic.
Definition: CodeGenFunction.h:676
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::CodeGen::EHPersonality::GNU_Wasm_CPlusPlus
static const EHPersonality GNU_Wasm_CPlusPlus
Definition: CGCleanup.h:614
clang::CodeGen::CGBuilderTy::CreateStore
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
Definition: CGBuilder.h:99
clang::CodeGen::EHPersonality::GNU_ObjC_SEH
static const EHPersonality GNU_ObjC_SEH
Definition: CGCleanup.h:604
clang::CodeGen::CodeGenFunction::SEHTryEpilogueStack
llvm::SmallVector< const JumpDest *, 2 > SEHTryEpilogueStack
Definition: CodeGenFunction.h:621
clang::CodeGen::CodeGenFunction::LambdaCaptureFields
llvm::DenseMap< const ValueDecl *, FieldDecl * > LambdaCaptureFields
Definition: CodeGenFunction.h:612
clang::CodeGen::EHScope::hasEHBranches
bool hasEHBranches() const
Definition: CGCleanup.h:130
CGObjCRuntime.h
TargetInfo.h
clang::CT_Cannot
@ CT_Cannot
Definition: ExceptionSpecificationType.h:55
clang::CodeGen::CodeGenTypes::arrangeBuiltinFunctionDeclaration
const CGFunctionInfo & arrangeBuiltinFunctionDeclaration(QualType resultType, const FunctionArgList &args)
A builtin function is a freestanding function using the default C conventions.
Definition: CGCall.cpp:670
clang::CodeGen::EHPersonality::CatchallRethrowFn
const char * CatchallRethrowFn
Definition: CGCleanup.h:594
clang::CodeGen::CodeGenFunction::EmitNoreturnRuntimeCallOrInvoke
void EmitNoreturnRuntimeCallOrInvoke(llvm::FunctionCallee callee, ArrayRef< llvm::Value * > args)
Emits a call or invoke to the given noreturn runtime function.
Definition: CGCall.cpp:4541
clang::CodeGen::CodeGenFunction::popCatchScope
void popCatchScope()
popCatchScope - Pops the catch scope at the top of the EHScope stack, emitting any required code (oth...
Definition: CGException.cpp:1179
clang::CodeGen::CodeGenFunction::EmitSEHExceptionCode
llvm::Value * EmitSEHExceptionCode()
Definition: CGException.cpp:2136
llvm::SmallPtrSet
Definition: ASTContext.h:55
clang::CodeGen::CodeGenModule::getLangOpts
const LangOptions & getLangOpts() const
Definition: CodeGenModule.h:729
clang::CodeGen::CodeGenFunction::HaveInsertPoint
bool HaveInsertPoint() const
HaveInsertPoint - True if an insertion point is defined.
Definition: CodeGenFunction.h:2469
clang::CodeGen::EHCleanup
@ EHCleanup
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
Definition: EHScopeStack.h:80
clang::CodeGen::CodeGenFunction::CreateTempAlloca
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
CreateTempAlloca - This creates an alloca and inserts it into the entry block if ArraySize is nullptr...
Definition: CGExpr.cpp:110
clang::ObjCRuntime::hasTerminate
bool hasTerminate() const
Does this runtime provide an objc_terminate function?
Definition: ObjCRuntime.h:348
clang::CodeGen::CGCXXABI::emitRethrow
virtual void emitRethrow(CodeGenFunction &CGF, bool isNoReturn)=0
clang::CodeGen::CodeGenFunction::EmitSEHExceptionCodeSave
void EmitSEHExceptionCodeSave(CodeGenFunction &ParentCGF, llvm::Value *ParentFP, llvm::Value *EntryEBP)
Definition: CGException.cpp:2088
clang::LangOptions::hasDWARFExceptions
bool hasDWARFExceptions() const
Definition: LangOptions.h:611
clang::CapturedDecl
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4500
clang::CodeGen::EHPersonality::PersonalityFn
const char * PersonalityFn
Definition: CGCleanup.h:589
clang::CodeGen::CodeGenTypeCache::getIntAlign
CharUnits getIntAlign() const
Definition: CodeGenTypeCache.h:87
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
ConstantEmitter.h
clang::SEHExceptStmt::getBlock
CompoundStmt * getBlock() const
Definition: Stmt.h:3392
clang::CodeGen::CodeGenFunction::JumpDest::getBlock
llvm::BasicBlock * getBlock() const
Definition: CodeGenFunction.h:246
clang::CodeGen::EHPersonality::get
static const EHPersonality & get(CodeGenModule &CGM, const FunctionDecl *FD)
Definition: CGException.cpp:230
clang::CodeGen::EHPersonality::GNU_C_SEH
static const EHPersonality GNU_C_SEH
Definition: CGCleanup.h:601
clang::CodeGen::CallArgList::add
void add(RValue rvalue, QualType type)
Definition: CGCall.h:283
clang::CodeGen::CodeGenFunction::Builder
CGBuilderTy Builder
Definition: CodeGenFunction.h:269
clang::CodeGen::EHCatchScope::Handler::Block
llvm::BasicBlock * Block
The catch handler for this type.
Definition: CGCleanup.h:159
clang::SEHTryStmt
Definition: Stmt.h:3444
clang::CodeGen::CodeGenTypeCache::VoidPtrTy
llvm::PointerType * VoidPtrTy
Definition: CodeGenTypeCache.h:56
getObjCXXPersonality
static const EHPersonality & getObjCXXPersonality(const TargetInfo &Target, const LangOptions &L)
Determines the personality function to use when both C++ and Objective-C exceptions are being caught.
Definition: CGException.cpp:193
clang::CodeGen::CodeGenFunction::CurSEHParent
GlobalDecl CurSEHParent
Definition: CodeGenFunction.h:542
clang::ObjCRuntime::getVersion
const VersionTuple & getVersion() const
Definition: ObjCRuntime.h:78
clang::CXXThrowExpr
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:1188
getUnexpectedFn
static llvm::FunctionCallee getUnexpectedFn(CodeGenModule &CGM)
Definition: CGException.cpp:54
clang::GlobalDecl
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:56
clang::CPlusPlus17
@ CPlusPlus17
Definition: LangStandard.h:56
clang::CodeGen::CodeGenTypeCache::AllocaInt8PtrTy
llvm::PointerType * AllocaInt8PtrTy
Definition: CodeGenTypeCache.h:69
clang::CodeGen::CGCXXABI::getCatchAllTypeInfo
virtual CatchTypeInfo getCatchAllTypeInfo()
Definition: CGCXXABI.cpp:333
U
clang::ObjCRuntime::FragileMacOSX
@ FragileMacOSX
'macosx-fragile' is the Apple-provided NeXT-derived runtime on Mac OS X platforms that use the fragil...
Definition: ObjCRuntime.h:40
clang::CodeGen::ReturnValueSlot
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
Definition: CGCall.h:357
getPersonalityFn
static llvm::FunctionCallee getPersonalityFn(CodeGenModule &CGM, const EHPersonality &Personality)
Definition: CGException.cpp:256
clang::CodeGen::EHPersonality::usesFuncletPads
bool usesFuncletPads() const
Does this personality use landingpads or the family of pad instructions designed to form funclets?
Definition: CGCleanup.h:619
clang::TypeInfo
Definition: ASTContext.h:152
clang::CodeGen::CGObjCRuntime::EmitThrowStmt
virtual void EmitThrowStmt(CodeGen::CodeGenFunction &CGF, const ObjCAtThrowStmt &S, bool ClearInsertionPoint=true)=0
clang::CodeGen::EHCatchScope::getNumHandlers
unsigned getNumHandlers() const
Definition: CGCleanup.h:187
V
#define V(N, I)
Definition: ASTContext.h:3208
clang::CodeGen::CodeGenFunction::RunCleanupsScope
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited.
Definition: CodeGenFunction.h:872
clang::CodeGen::EHCatchScope
A scope which attempts to handle some, possibly all, types of exceptions.
Definition: CGCleanup.h:146
clang::CodeGen::CodeGenFunction::getInvokeDestImpl
llvm::BasicBlock * getInvokeDestImpl()
Definition: CGException.cpp:757
clang::MangleContext
MangleContext - Context for tracking state which persists across multiple calls to the C++ name mangl...
Definition: Mangle.h:44
clang::CodeGen::CodeGenFunction::EmitStmt
void EmitStmt(const Stmt *S, ArrayRef< const Attr * > Attrs=std::nullopt)
EmitStmt - Emit the code for the statement.
Definition: CGStmt.cpp:53
clang::CodeGen::CodeGenFunction::EHResumeBlock
llvm::BasicBlock * EHResumeBlock
EHResumeBlock - Unified block containing a call to llvm.eh.resume.
Definition: CodeGenFunction.h:660
clang::ObjCRuntime::MacOSX
@ MacOSX
'macosx' is the Apple-provided NeXT-derived runtime on Mac OS X platforms that use the non-fragile AB...
Definition: ObjCRuntime.h:35
clang::CodeGen::EHScopeStack::Cleanup
Information for lazily generating a cleanup.
Definition: EHScopeStack.h:141
clang::CodeGen::CodeGenFunction::EmitSEHExceptionInfo
llvm::Value * EmitSEHExceptionInfo()
Definition: CGException.cpp:2127
clang::CodeGen::CodeGenFunction::SEHCodeSlotStack
SmallVector< Address, 1 > SEHCodeSlotStack
A stack of exception code slots.
Definition: CodeGenFunction.h:673
clang::LangOptions::ObjCRuntime
clang::ObjCRuntime ObjCRuntime
Definition: LangOptions.h:414
clang::CodeGen::CodeGenModule::getObjCRuntime
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
Definition: CodeGenModule.h:618
clang::CodeGen::CodeGenFunction::pushSEHCleanup
void pushSEHCleanup(CleanupKind kind, llvm::Function *FinallyFunc)
Definition: CGException.cpp:2148
clang::CodeGen::CGBuilderTy::CreateAlignedStore
llvm::StoreInst * CreateAlignedStore(llvm::Value *Val, llvm::Value *Addr, CharUnits Align, bool IsVolatile=false)
Definition: CGBuilder.h:106
clang::CodeGen::CodeGenFunction::EmitCapturedLocals
void EmitCapturedLocals(CodeGenFunction &ParentCGF, const Stmt *OutlinedStmt, bool IsFilter)
Scan the outlined statement for captures from the parent function.
Definition: CGException.cpp:1848
clang::ExceptionSpecificationType
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
Definition: ExceptionSpecificationType.h:20
clang::CodeGen::Address::getName
llvm::StringRef getName() const
Return the IR name of the pointer value.
Definition: Address.h:115
clang::ObjCAtThrowStmt
Represents Objective-C's @throw statement.
Definition: StmtObjC.h:357
clang::LangOptions::hasWasmExceptions
bool hasWasmExceptions() const
Definition: LangOptions.h:615
clang::CodeGen::EHCatchScope::Handler::Type
CatchTypeInfo Type
A type info value, or null (C++ null, not an LLVM null pointer) for a catch-all.
Definition: CGCleanup.h:156
clang::syntax::NodeRole::Callee
@ Callee
clang::CharUnits::fromQuantity
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
Definition: CharUnits.h:63
clang::CodeGen::Address::getType
llvm::PointerType * getType() const
Return the type of the pointer value.
Definition: Address.h:99
clang::CodeGen::EHPersonality::GNU_ObjCXX
static const EHPersonality GNU_ObjCXX
Definition: CGCleanup.h:606
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
clang::CPlusPlus
@ CPlusPlus
Definition: LangStandard.h:53
clang::CodeGen::CGCXXABI::emitThrow
virtual void emitThrow(CodeGenFunction &CGF, const CXXThrowExpr *E)=0
clang::CodeGen::CodeGenFunction::EmitRuntimeCall
llvm::CallInst * EmitRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
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::getExceptionSlot
Address getExceptionSlot()
Returns a pointer to the function's exception object and selector slot, which is assigned in every la...
Definition: CGException.cpp:421
clang::EST_DynamicNone
@ EST_DynamicNone
throw()
Definition: ExceptionSpecificationType.h:22
clang::CodeGen::CodeGenTypeCache::VoidTy
llvm::Type * VoidTy
void
Definition: CodeGenTypeCache.h:34
clang::CodeGen::EHScope::setCachedEHDispatchBlock
void setCachedEHDispatchBlock(llvm::BasicBlock *block)
Definition: CGCleanup.h:126
clang::CodeGen::CodeGenFunction::VolatilizeTryBlocks
void VolatilizeTryBlocks(llvm::BasicBlock *BB, llvm::SmallPtrSet< llvm::BasicBlock *, 10 > &V)
Definition: CGException.cpp:1672
clang::StmtVisitorBase< llvm::make_const_ptr, ImplClass, void, ParamTys... >::Visit
void Visit(PTR(Stmt) S, ParamTys... P)
Definition: StmtVisitor.h:43
clang::CodeGen::CodeGenModule::getModule
llvm::Module & getModule() const
Definition: CodeGenModule.h:738
clang::Stmt::getEndLoc
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:348
getSehTryEndFn
static llvm::FunctionCallee getSehTryEndFn(CodeGenModule &CGM)
Definition: CGException.cpp:48
clang::CodeGen::EHScope::getEnclosingEHScope
EHScopeStack::stable_iterator getEnclosingEHScope() const
Definition: CGCleanup.h:136
clang::DeclRefExpr::getDecl
ValueDecl * getDecl()
Definition: Expr.h:1304
clang::CodeGen::EHScopeStack::empty
bool empty() const
Determines whether the exception-scopes stack is empty.
Definition: EHScopeStack.h:350
clang::CodeGen::CodeGenFunction::EHSelectorSlot
llvm::AllocaInst * EHSelectorSlot
The selector slot.
Definition: CodeGenFunction.h:668
emitCatchDispatchBlock
static void emitCatchDispatchBlock(CodeGenFunction &CGF, EHCatchScope &catchScope)
Emit the structure of the dispatch block for the given catch scope.
Definition: CGException.cpp:1099
llvm::SmallString< 128 >
clang::CodeGen::EHScope::getKind
Kind getKind() const
Definition: CGCleanup.h:112
clang::interp::Load
bool Load(InterpState &S, CodePtr OpPC)
Definition: Interp.h:892
clang::interp::Zero
bool Zero(InterpState &S, CodePtr OpPC)
Definition: Interp.h:1122
clang::FunctionProtoType::canThrow
CanThrowResult canThrow() const
Determine whether this function type has a non-throwing exception specification.
Definition: Type.cpp:3305
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:906
getCatchAllValue
static llvm::Constant * getCatchAllValue(CodeGenFunction &CGF)
Returns the value to inject into a selector to indicate the presence of a catch-all.
Definition: CGException.cpp:374
clang::CodeGen::CodeGenFunction::ExceptionSlot
llvm::Value * ExceptionSlot
The exception slot.
Definition: CodeGenFunction.h:664
clang::ObjCRuntime::WatchOS
@ WatchOS
'watchos' is a variant of iOS for Apple's watchOS.
Definition: ObjCRuntime.h:49
clang::CodeGen::EHScope::Terminate
@ Terminate
Definition: CGCleanup.h:104
clang::CodeGen::CodeGenFunction::GenerateSEHFinallyFunction
llvm::Function * GenerateSEHFinallyFunction(CodeGenFunction &ParentCGF, const SEHFinallyStmt &Finally)
Definition: CGException.cpp:2075
clang::CodeGen::CodeGenFunction::IsOutlinedSEHHelper
bool IsOutlinedSEHHelper
True if the current function is an outlined SEH helper.
Definition: CodeGenFunction.h:546
clang::CodeGen::CodeGenModule::getTypes
CodeGenTypes & getTypes()
Definition: CodeGenModule.h:755
clang::LangOptions::hasSjLjExceptions
bool hasSjLjExceptions() const
Definition: LangOptions.h:603
clang::CodeGen::EHCatchScope::clearHandlerBlocks
void clearHandlerBlocks()
Definition: CGCleanup.h:216
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::ExitSEHTryStmt
void ExitSEHTryStmt(const SEHTryStmt &S)
Definition: CGException.cpp:2194
clang::CodeGen::CGCXXABI::emitBeginCatch
virtual void emitBeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *C)=0
clang::CodeGen::CodeGenFunction::getLLVMContext
llvm::LLVMContext & getLLVMContext()
Definition: CodeGenFunction.h:2027
clang::CodeGen::EHScopeStack::pushTerminate
void pushTerminate()
Push a terminate handler on the stack.
Definition: CGCleanup.cpp:267
clang::CodeGen::CodeGenFunction::getContext
ASTContext & getContext() const
Definition: CodeGenFunction.h:1984
clang::CodeGen::EHScopeStack::end
iterator end() const
Returns an iterator pointing to the outermost EH scope.
Definition: CGCleanup.h:555
clang::CodeGen::NormalCleanup
@ NormalCleanup
Denotes a cleanup that should run when a scope is exited using normal control flow (falling off the e...
Definition: EHScopeStack.h:84
clang::CXXTryStmt
CXXTryStmt - A C++ try block, including all handlers.
Definition: StmtCXX.h:68
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::DeactivateCleanupBlock
void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, llvm::Instruction *DominatingIP)
DeactivateCleanupBlock - Deactivates the given cleanup block.
Definition: CGCleanup.cpp:1282
clang::CodeGen::CodeGenFunction::FinishFunction
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
Definition: CodeGenFunction.cpp:327
clang::CodeGen::Address
An aligned address.
Definition: Address.h:74
getCatchallRethrowFn
static llvm::FunctionCallee getCatchallRethrowFn(CodeGenModule &CGM, StringRef Name)
Definition: CGException.cpp:89
clang::CodeGen::CGBuilderTy::CreateFlagLoad
llvm::LoadInst * CreateFlagLoad(llvm::Value *Addr, const llvm::Twine &Name="")
Emit a load from an i1 flag variable.
Definition: CGBuilder.h:121
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
PersonalityHasOnlyCXXUses
static bool PersonalityHasOnlyCXXUses(llvm::Constant *Fn)
Check whether a personality function could reasonably be swapped for a C++ personality function.
Definition: CGException.cpp:306
clang::CodeGen::EHScopeStack::requiresLandingPad
bool requiresLandingPad() const
Definition: CGCleanup.cpp:155
clang::CodeGen::CodeGenFunction::getEHDispatchBlock
llvm::BasicBlock * getEHDispatchBlock(EHScopeStack::stable_iterator scope)
Definition: CGException.cpp:655
clang::CodeGen::EHScope::Catch
@ Catch
Definition: CGCleanup.h:104
clang::FunctionProtoType::getExceptionType
QualType getExceptionType(unsigned i) const
Return the ith exception type, where 0 <= i < getNumExceptions().
Definition: Type.h:4303
StmtObjC.h
clang::CodeGen::CodeGenFunction::EmitAnyExprToMem
void EmitAnyExprToMem(const Expr *E, Address Location, Qualifiers Quals, bool IsInitializer)
EmitAnyExprToMem - Emits the code necessary to evaluate an arbitrary expression into the given memory...
Definition: CGExpr.cpp:241
clang::CodeGen::CGCallee::forDirect
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
Definition: CGCall.h:130
clang::ObjCRuntime::isNeXTFamily
bool isNeXTFamily() const
Is this runtime basically of the NeXT family of runtimes?
Definition: ObjCRuntime.h:135
clang::SEHExceptStmt
Definition: Stmt.h:3365
clang::CodeGen::CodeGenModule::getTarget
const TargetInfo & getTarget() const
Definition: CodeGenModule.h:743
clang::CodeGen::EHPersonality::GNU_CPlusPlus
static const EHPersonality GNU_CPlusPlus
Definition: CGCleanup.h:608
clang::ObjCRuntime::ObjFW
@ ObjFW
'objfw' is the Objective-C runtime included in ObjFW
Definition: ObjCRuntime.h:59
clang::QualType::getUnqualifiedType
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:6715
clang::CodeGen::CodeGenFunction::EmitSEHTryStmt
void EmitSEHTryStmt(const SEHTryStmt &S)
Definition: CGException.cpp:1637
clang::CodeGen::CodeGenTypeCache::Int32Ty
llvm::IntegerType * Int32Ty
Definition: CodeGenTypeCache.h:37
clang::Type::isObjCObjectPointerType
bool isObjCObjectPointerType() const
Definition: Type.h:7011
clang::CodeGen::EHScopeStack::popFilter
void popFilter()
Pops an exceptions filter off the stack.
Definition: CGCleanup.cpp:250
clang::CodeGen::CGCXXABI::emitTerminateForUnexpectedException
virtual llvm::CallInst * emitTerminateForUnexpectedException(CodeGenFunction &CGF, llvm::Value *Exn)
Definition: CGCXXABI.cpp:327
DiagnosticSema.h
clang::ASTContext::UnsignedCharTy
CanQualType UnsignedCharTy
Definition: ASTContext.h:1090
getCPersonality
static const EHPersonality & getCPersonality(const TargetInfo &Target, const LangOptions &L)
Definition: CGException.cpp:131
clang::CodeGen::EHCatchScope::setHandler
void setHandler(unsigned I, llvm::Constant *Type, llvm::BasicBlock *Block)
Definition: CGCleanup.h:195
clang::CodeGen::CodeGenTypes::GetFunctionType
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
Definition: CGCall.cpp:1617
clang::CodeGen::CodeGenModule::getDataLayout
const llvm::DataLayout & getDataLayout() const
Definition: CodeGenModule.h:740
getOpaquePersonalityFn
static llvm::Constant * getOpaquePersonalityFn(CodeGenModule &CGM, const EHPersonality &Personality)
Definition: CGException.cpp:263
LandingPadHasOnlyCXXUses
static bool LandingPadHasOnlyCXXUses(llvm::LandingPadInst *LPI)
Check whether a landingpad instruction only uses C++ features.
Definition: CGException.cpp:275
clang::TargetInfo::getTriple
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1197
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::LValue
LValue - This represents an lvalue references.
Definition: CGValue.h:171
clang::MangleContext::mangleSEHFilterExpression
virtual void mangleSEHFilterExpression(GlobalDecl EnclosingDecl, raw_ostream &Out)=0
clang::CodeGen::CodeGenFunction::EHStack
EHScopeStack EHStack
Definition: CodeGenFunction.h:619
clang::CodeGen::CodeGenFunction::getSelectorFromSlot
llvm::Value * getSelectorFromSlot()
Definition: CGException.cpp:437
clang::FunctionDecl::usesSEHTry
bool usesSEHTry() const
Indicates the function uses __try.
Definition: Decl.h:2387
clang::ASTContext::VoidPtrTy
CanQualType VoidPtrTy
Definition: ASTContext.h:1107
clang::Type::isPointerType
bool isPointerType() const
Definition: Type.h:6883
clang::CodeGen::CodeGenModule::getTerminateFn
llvm::FunctionCallee getTerminateFn()
Get the declaration of std::terminate for the platform.
Definition: CGException.cpp:63
clang::CodeGen::CodeGenFunction::GenerateSEHFilterFunction
llvm::Function * GenerateSEHFilterFunction(CodeGenFunction &ParentCGF, const SEHExceptStmt &Except)
Create a stub filter function that will ultimately hold the code of the filter expression.
Definition: CGException.cpp:2058
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:1083
clang::ObjCRuntime::GNUstep
@ GNUstep
'gnustep' is the modern non-fragile GNUstep runtime.
Definition: ObjCRuntime.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::SEHExceptStmt::getFilterExpr
Expr * getFilterExpr() const
Definition: Stmt.h:3388
clang::ASTContext::getUnqualifiedArrayType
QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals)
Return this type as a completely-unqualified array type, capturing the qualifiers in Quals.
Definition: ASTContext.cpp:6017
clang::VarDecl::isLocalVarDeclOrParm
bool isLocalVarDeclOrParm() const
Similar to isLocalVarDecl but also includes parameters.
Definition: Decl.h:1209
clang::CodeGen::CodeGenModule::getCXXABI
CGCXXABI & getCXXABI() const
Definition: CodeGenModule.h:748
clang::FunctionProtoType
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4016
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::CodeGen::Address::withPointer
Address withPointer(llvm::Value *NewPointer) const
Return address with different pointer, but same element type and alignment.
Definition: Address.h:127
clang::CodeGen::CodeGenModule::getIntrinsic
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=std::nullopt)
Definition: CodeGenModule.cpp:5495
clang::Language::CXX
@ CXX
clang::CodeGen::CodeGenFunction::recoverAddrOfEscapedLocal
Address recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF, Address ParentVar, llvm::Value *ParentFP)
Recovers the address of a local in a parent function.
Definition: CGException.cpp:1808
clang::CodeGen::CodeGenFunction::getExceptionFromSlot
llvm::Value * getExceptionFromSlot()
Returns the contents of the function's exception object and selector slots.
Definition: CGException.cpp:433
clang::Language::ObjCXX
@ ObjCXX
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:6824
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
clang::ASTContext::LongTy
CanQualType LongTy
Definition: ASTContext.h:1089
clang::CodeGen::ApplyDebugLocation::CreateDefaultArtificial
static ApplyDebugLocation CreateDefaultArtificial(CodeGenFunction &CGF, SourceLocation TemporaryLocation)
Apply TemporaryLocation if it is valid.
Definition: CGDebugInfo.h:836
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
getCXXPersonality
static const EHPersonality & getCXXPersonality(const TargetInfo &Target, const LangOptions &L)
Definition: CGException.cpp:173
clang::CodeGen::FunctionArgList
FunctionArgList - Type for representing both the decl and type of parameters to a function.
Definition: CGCall.h:353
StmtVisitor.h
clang::CXXThrowExpr::getSubExpr
const Expr * getSubExpr() const
Definition: ExprCXX.h:1208
clang::CodeGen::CodeGenFunction::getUnreachableBlock
llvm::BasicBlock * getUnreachableBlock()
Definition: CodeGenFunction.h:2011
clang::CodeGen::EHPersonality::MSVC_except_handler
static const EHPersonality MSVC_except_handler
Definition: CGCleanup.h:611
clang::CodeGen::CodeGenFunction::ParentCGF
CodeGenFunction * ParentCGF
Definition: CodeGenFunction.h:265
llvm::SaveAndRestore
Definition: LLVM.h:44
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::getEHResumeBlock
llvm::BasicBlock * getEHResumeBlock(bool isCleanup)
Definition: CGException.cpp:1601
TargetBuiltins.h
clang::CodeGen::NormalAndEHCleanup
@ NormalAndEHCleanup
Definition: EHScopeStack.h:86
clang::CodeGen::EHScope::getCachedEHDispatchBlock
llvm::BasicBlock * getCachedEHDispatchBlock() const
Definition: CGCleanup.h:122
clang::ConstStmtVisitor
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:193
clang::ObjCRuntime
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:28
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::CodeGen::CodeGenFunction::EmitRuntimeCallOrInvoke
llvm::CallBase * EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee, ArrayRef< llvm::Value * > args, const Twine &name="")
Emits a call or invoke instruction to the given runtime function.
Definition: CGCall.cpp:4572
clang::CodeGen::EHPersonality::MSVC_C_specific_handler
static const EHPersonality MSVC_C_specific_handler
Definition: CGCleanup.h:612
emitFilterDispatchBlock
static void emitFilterDispatchBlock(CodeGenFunction &CGF, EHFilterScope &filterScope)
Emit the dispatch block for a filter scope if necessary.
Definition: CGException.cpp:532
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::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::CodeGen::CodeGenFunction::EmitAnyExprToExn
void EmitAnyExprToExn(const Expr *E, Address Addr)
Definition: CGException.cpp:395
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::EHFilterScope
An exceptions scope which filters exceptions thrown through it.
Definition: CGCleanup.h:437
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::CXXThisExpr
Represents the this expression in C++.
Definition: ExprCXX.h:1149
clang::CodeGen::EHScopeStack::getInnermostEHScope
stable_iterator getInnermostEHScope() const
Definition: EHScopeStack.h:366
clang::CodeGen::EHScopeStack::popCatch
void popCatch()
Pops a catch scope off the stack. This is private to CGException.cpp.
Definition: CGCleanup.h:559
clang::SEHFinallyStmt
Definition: Stmt.h:3409
clang::CodeGen::EHPersonality
The exceptions personality for a function.
Definition: CGCleanup.h:588
clang::CodeGen::CodeGenFunction::CGM
CodeGenModule & CGM
Definition: CodeGenFunction.h:261
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::Builtin::ID
ID
Definition: Builtins.h:52
clang::CodeGen::CodeGenFunction::CurFn
llvm::Function * CurFn
Definition: CodeGenFunction.h:325
clang::CodeGen::CleanupKind
CleanupKind
Definition: EHScopeStack.h:77
clang
Definition: CalledOnceCheck.h:17
clang::LangOptions::MSVC2015
@ MSVC2015
Definition: LangOptions.h:145
clang::CodeGen::CGBuilderTy::CreateFlagStore
llvm::StoreInst * CreateFlagStore(bool Value, llvm::Value *Addr)
Emit a store to an i1 flag variable.
Definition: CGBuilder.h:129
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::RValue::get
static RValue get(llvm::Value *V)
Definition: CGValue.h:89
clang::Selector
Smart pointer class that efficiently represents Objective-C method names.
Definition: IdentifierTable.h:759
isNonEHScope
static bool isNonEHScope(const EHScope &S)
Check whether this is a non-EH scope, i.e.
Definition: CGException.cpp:744
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:71
clang::CodeGen::CatchTypeInfo
The MS C++ ABI needs a pointer to RTTI data plus some flags to describe the type of a catch handler,...
Definition: CGCleanup.h:36
clang::CodeGen::EHScopeStack::iterator
A non-stable pointer into the scope stack.
Definition: CGCleanup.h:491
clang::CodeGen::CodeGenFunction::RunCleanupsScope::ForceCleanup
void ForceCleanup(std::initializer_list< llvm::Value ** > ValuesToReload={})
Force the emission of cleanups now, instead of waiting until this object is destroyed.
Definition: CodeGenFunction.h:917
clang::CXXCatchStmt
CXXCatchStmt - This represents a C++ catch block.
Definition: StmtCXX.h:28
clang::Expr::getType
QualType getType() const
Definition: Expr.h:141
getSehTryBeginFn
static llvm::FunctionCallee getSehTryBeginFn(CodeGenModule &CGM)
Definition: CGException.cpp:42
clang::CodeGen::RValue::getScalarVal
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
Definition: CGValue.h:61
clang::CodeGen::CodeGenFunction::EnterCXXTryStmt
void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock=false)
Definition: CGException.cpp:617
clang::CodeGen::EHPersonality::MSVC_CxxFrameHandler3
static const EHPersonality MSVC_CxxFrameHandler3
Definition: CGCleanup.h:613
clang::CodeGen::EHCatchScope::Handler
Definition: CGCleanup.h:153
clang::CodeGen::CodeGenModule::getDiags
DiagnosticsEngine & getDiags() const
Definition: CodeGenModule.h:739
clang::Stmt::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:336
clang::CodeGen::EHScope::Filter
@ Filter
Definition: CGCleanup.h:104
clang::CodeGen::CodeGenFunction::getFuncletEHDispatchBlock
llvm::BasicBlock * getFuncletEHDispatchBlock(EHScopeStack::stable_iterator scope)
Definition: CGException.cpp:702
clang::CodeGen::CodeGenFunction::LambdaThisCaptureField
FieldDecl * LambdaThisCaptureField
Definition: CodeGenFunction.h:613
clang::CodeGen::CodeGenFunction::startOutlinedSEHHelper
void startOutlinedSEHHelper(CodeGenFunction &ParentCGF, bool IsFilter, const Stmt *OutlinedStmt)
Arrange a function prototype that can be called by Windows exception handling personalities.
Definition: CGException.cpp:1996
emitWasmCatchPadBlock
static void emitWasmCatchPadBlock(CodeGenFunction &CGF, EHCatchScope &CatchScope)
Definition: CGException.cpp:991
clang::CodeGen::EHFilterScope::getNumFilters
unsigned getNumFilters() const
Definition: CGCleanup.h:460
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::CodeGen::CodeGenFunction::CurrentFuncletPad
llvm::Instruction * CurrentFuncletPad
Definition: CodeGenFunction.h:623
getFreeExceptionFn
static llvm::FunctionCallee getFreeExceptionFn(CodeGenModule &CGM)
Definition: CGException.cpp:33
clang::CodeGen::CodeGenFunction::EnterSEHTryStmt
void EnterSEHTryStmt(const SEHTryStmt &S)
Definition: CGException.cpp:2153
clang::GlobalDecl::getDecl
const Decl * getDecl() const
Definition: GlobalDecl.h:103
clang::CodeGen::ConstantEmitter
Definition: ConstantEmitter.h:23
clang::CodeGen::CodeGenFunction::EmitStartEHSpec
void EmitStartEHSpec(const Decl *D)
EmitStartEHSpec - Emit the start of the exception spec.
Definition: CGException.cpp:462
clang::CodeGen::ConstantEmitter::tryEmitAbstract
llvm::Constant * tryEmitAbstract(const Expr *E, QualType T)
Try to emit the result of the given expression as an abstract constant.
Definition: CGExprConstant.cpp:1381
clang::ObjCRuntime::iOS
@ iOS
'ios' is the Apple-provided NeXT-derived runtime on iOS or the iOS simulator; it is always non-fragil...
Definition: ObjCRuntime.h:45
clang::CallExpr::getBuiltinCallee
unsigned getBuiltinCallee() const
getBuiltinCallee - If this is a call to a builtin, return the builtin ID of the callee.
Definition: Expr.cpp:1564
Mangle.h
clang::CodeGen::EHScopeStack::stable_end
static stable_iterator stable_end()
Create a stable reference to the bottom of the EH stack.
Definition: EHScopeStack.h:389
clang::CodeGen::EHScopeStack::begin
iterator begin() const
Returns an iterator pointing to the innermost EH scope.
Definition: CGCleanup.h:551
clang::CodeGen::CodeGenFunction::getNormalCleanupDestSlot
Address getNormalCleanupDestSlot()
Definition: CGCleanup.cpp:1312
clang::CodeGen::CodeGenFunction::getTerminateFunclet
llvm::BasicBlock * getTerminateFunclet()
getTerminateLandingPad - Return a cleanup funclet that just calls terminate.
Definition: CGException.cpp:1566
clang::CodeGen::EHPersonality::XL_CPlusPlus
static const EHPersonality XL_CPlusPlus
Definition: CGCleanup.h:615
clang::DeclRefExpr::refersToEnclosingVariableOrCapture
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Definition: Expr.h:1434
clang::CodeGen::CodeGenFunction::EmitStopPoint
void EmitStopPoint(const Stmt *S)
EmitStopPoint - Emit a debug stoppoint if we are emitting debug info.
Definition: CGStmt.cpp:43
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:712
clang::CodeGen::CodeGenFunction::CreateMemTemp
Address CreateMemTemp(QualType T, const Twine &Name="tmp", Address *Alloca=nullptr)
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen and cas...
Definition: CGExpr.cpp:135
llvm::SmallSetVector
Definition: ExternalSemaSource.h:23
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::SEHFinallyStmt::getBlock
CompoundStmt * getBlock() const
Definition: Stmt.h:3429
clang::CodeGen::CodeGenFunction::FinallyInfo::exit
void exit(CodeGenFunction &CGF)
Definition: CGException.cpp:1467
clang::CodeGen::CodeGenFunction::EmitBranchThroughCleanup
void EmitBranchThroughCleanup(JumpDest Dest)
EmitBranchThroughCleanup - Emit a branch from the current insert block through the normal cleanup han...
Definition: CGCleanup.cpp:1086
clang::CodeGen::CodeGenTypeCache::Int8Ty
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Definition: CodeGenTypeCache.h:37
clang::CodeGen::EHFilterScope::getFilter
llvm::Value * getFilter(unsigned i) const
Definition: CGCleanup.h:467
clang::transformer::name
RangeSelector name(std::string ID)
Given a node with a "name", (like NamedDecl, DeclRefExpr, CxxCtorInitializer, and TypeLoc) selects th...
Definition: RangeSelector.cpp:200
clang::CodeGen::CodeGenTypeCache::VoidPtrPtrTy
llvm::PointerType * VoidPtrPtrTy
Definition: CodeGenTypeCache.h:62
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:432
clang::CodeGen::CallArgList
CallArgList - Type for representing both the value and type of arguments in a call.
Definition: CGCall.h:259
clang::CodeGen::CGObjCRuntime::GetEHType
virtual llvm::Constant * GetEHType(QualType T)=0
Get the type constant to catch for the given ObjC pointer type.
clang::CodeGen::CodeGenTypes::arrangeBuiltinFunctionCall
const CGFunctionInfo & arrangeBuiltinFunctionCall(QualType resultType, const CallArgList &args)
Definition: CGCall.cpp:657
clang::DeclRefExpr
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1232
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1904
clang::CodeGen::EHScopeStack::popTerminate
void popTerminate()
Pops a terminate handler off the stack.
Definition: CGCleanup.h:567
clang::format::cleanup
tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>")
Clean up any erroneous/redundant code in the given Ranges in Code.
Definition: Format.cpp:3494
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::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
StmtCXX.h
clang::CodeGen::EHScopeStack::find
iterator find(stable_iterator save) const
Turn a stable reference to a scope depth into a unstable pointer to the EH stack.
Definition: CGCleanup.h:575
clang::CodeGen::EHPersonality::GNU_CPlusPlus_SJLJ
static const EHPersonality GNU_CPlusPlus_SJLJ
Definition: CGCleanup.h:609
clang::CodeGen::CodeGenModule::getLLVMContext
llvm::LLVMContext & getLLVMContext()
Definition: CodeGenModule.h:749
clang::CodeGen::EHScopeStack::stable_iterator
A saved depth on the scope stack.
Definition: EHScopeStack.h:101
clang::CodeGen::CodeGenFunction::getLangOpts
const LangOptions & getLangOpts() const
Definition: CodeGenFunction.h:1997
clang::CodeGen::CodeGenFunction::EmitSEHLeaveStmt
void EmitSEHLeaveStmt(const SEHLeaveStmt &S)
Definition: CGException.cpp:2266
clang::CodeGen::EHPersonality::GNU_ObjC_SJLJ
static const EHPersonality GNU_ObjC_SJLJ
Definition: CGCleanup.h:603
clang::CodeGen::CodeGenFunction::EmitCXXThrowExpr
void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint=true)
Definition: CGException.cpp:441
clang::DiagnosticsEngine::Report
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1537
clang::CodeGen::CodeGenFunction::EmitLandingPad
llvm::BasicBlock * EmitLandingPad()
Emits a landing pad for the current EH stack.
Definition: CGException.cpp:807
clang::CodeGen::CodeGenFunction::ExitCXXTryStmt
void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock=false)
Definition: CGException.cpp:1186
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::SEHLeaveStmt
Represents a __leave statement.
Definition: Stmt.h:3497
clang::CodeGen::EHPersonality::GNU_ObjC
static const EHPersonality GNU_ObjC
Definition: CGCleanup.h:602
clang::FunctionProtoType::getNumExceptions
unsigned getNumExceptions() const
Return the number of types in the exception specification.
Definition: Type.h:4295
clang::CodeGen::CodeGenFunction::ReturnValue
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
Definition: CodeGenFunction.h:356
clang::NamedDecl::getName
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:274