xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/noexcept.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - -fcxx-exceptions -fexceptions -std=c++11 | FileCheck %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // rdar://11904428
4*f4a2713aSLionel Sambuc //   Ensure that we call __cxa_begin_catch before calling
5*f4a2713aSLionel Sambuc //   std::terminate in a noexcept function.
6*f4a2713aSLionel Sambuc namespace test0 {
7*f4a2713aSLionel Sambuc   void foo();
8*f4a2713aSLionel Sambuc 
9*f4a2713aSLionel Sambuc   struct A {
10*f4a2713aSLionel Sambuc     A();
11*f4a2713aSLionel Sambuc     ~A();
12*f4a2713aSLionel Sambuc   };
13*f4a2713aSLionel Sambuc 
test()14*f4a2713aSLionel Sambuc   void test() noexcept {
15*f4a2713aSLionel Sambuc     A a;
16*f4a2713aSLionel Sambuc     foo();
17*f4a2713aSLionel Sambuc   }
18*f4a2713aSLionel Sambuc }
19*f4a2713aSLionel Sambuc // CHECK-LABEL:    define void @_ZN5test04testEv()
20*f4a2713aSLionel Sambuc // CHECK:      [[EXN:%.*]] = alloca i8*
21*f4a2713aSLionel Sambuc //   This goes to the terminate lpad.
22*f4a2713aSLionel Sambuc // CHECK:      invoke void @_ZN5test01AC1Ev(
23*f4a2713aSLionel Sambuc //   This goes to the cleanup-and-then-terminate lpad.
24*f4a2713aSLionel Sambuc // CHECK:      invoke void @_ZN5test03fooEv()
25*f4a2713aSLionel Sambuc //   Destructors don't throw by default in C++11.
26*f4a2713aSLionel Sambuc // CHECK:      call void @_ZN5test01AD1Ev(
27*f4a2713aSLionel Sambuc //   Cleanup lpad.
28*f4a2713aSLionel Sambuc // CHECK:      [[T0:%.*]] = landingpad
29*f4a2713aSLionel Sambuc // CHECK-NEXT:   catch i8* null
30*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = extractvalue { i8*, i32 } [[T0]], 0
31*f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T1]], i8** [[EXN]]
32*f4a2713aSLionel Sambuc //   (Calling this destructor is not technically required.)
33*f4a2713aSLionel Sambuc // CHECK:      call void @_ZN5test01AD1Ev(
34*f4a2713aSLionel Sambuc // CHECK-NEXT: br label
35*f4a2713aSLionel Sambuc //   The terminate landing pad jumps in here for some reason.
36*f4a2713aSLionel Sambuc // CHECK:      [[T0:%.*]] = landingpad
37*f4a2713aSLionel Sambuc // CHECK-NEXT:   catch i8* null
38*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = extractvalue { i8*, i32 } [[T0]], 0
39*f4a2713aSLionel Sambuc // CHECK-NEXT: call void @__clang_call_terminate(i8* [[T1]])
40*f4a2713aSLionel Sambuc // CHECK-NEXT: unreachable
41*f4a2713aSLionel Sambuc //   The terminate handler chained to by the cleanup lpad.
42*f4a2713aSLionel Sambuc // CHECK:      [[T0:%.*]] = load i8** [[EXN]]
43*f4a2713aSLionel Sambuc // CHECK-NEXT: call void @__clang_call_terminate(i8* [[T0]])
44*f4a2713aSLionel Sambuc // CHECK-NEXT: unreachable
45*f4a2713aSLionel Sambuc 
46*f4a2713aSLionel Sambuc // CHECK-LABEL:  define linkonce_odr hidden void @__clang_call_terminate(
47*f4a2713aSLionel Sambuc // CHECK:      call i8* @__cxa_begin_catch(
48*f4a2713aSLionel Sambuc // CHECK-NEXT: call void @_ZSt9terminatev()
49*f4a2713aSLionel Sambuc // CHECK-NEXT: unreachable
50