eh.cpp revision ac418162692a951ca3796d6830496a85a2d12493
1// RUN: %clang_cc1 -fexceptions -triple x86_64-apple-darwin -std=c++0x -emit-llvm %s -o %t.ll
2// RUN: FileCheck --input-file=%t.ll %s
3
4struct test1_D {
5  double d;
6} d1;
7
8void test1() {
9  throw d1;
10}
11
12// CHECK:     define void @_Z5test1v()
13// CHECK:       [[FREEVAR:%.*]] = alloca i1
14// CHECK-NEXT:  [[EXNOBJVAR:%.*]] = alloca i8*
15// CHECK-NEXT:  store i1 false, i1* [[FREEVAR]]
16// CHECK-NEXT:  [[EXNOBJ:%.*]] = call i8* @__cxa_allocate_exception(i64 8)
17// CHECK-NEXT:  store i8* [[EXNOBJ]], i8** [[EXNOBJVAR]]
18// CHECK-NEXT:  store i1 true, i1* [[FREEVAR]]
19// CHECK-NEXT:  [[EXN:%.*]] = bitcast i8* [[EXNOBJ]] to [[DSTAR:%[^*]*\*]]
20// CHECK-NEXT:  [[EXN2:%.*]] = bitcast [[DSTAR]] [[EXN]] to i8*
21// CHECK-NEXT:  call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[EXN2]], i8* bitcast ([[DSTAR]] @d1 to i8*), i64 8, i32 8, i1 false)
22// CHECK-NEXT:  store i1 false, i1* [[FREEVAR]]
23// CHECK-NEXT:  call void @__cxa_throw(i8* [[EXNOBJ]], i8* bitcast (%0* @_ZTI7test1_D to i8*), i8* null) noreturn
24// CHECK-NEXT:  unreachable
25
26
27struct test2_D {
28  test2_D(const test2_D&o);
29  test2_D();
30  virtual void bar() { }
31  int i; int j;
32} d2;
33
34void test2() {
35  throw d2;
36}
37
38// CHECK:     define void @_Z5test2v()
39// CHECK:       [[FREEVAR:%.*]] = alloca i1
40// CHECK-NEXT:  [[EXNOBJVAR:%.*]] = alloca i8*
41// CHECK-NEXT:  store i1 false, i1* [[FREEVAR]]
42// CHECK-NEXT:  [[EXNOBJ:%.*]] = call i8* @__cxa_allocate_exception(i64 16)
43// CHECK-NEXT:  store i8* [[EXNOBJ]], i8** [[EXNOBJVAR]]
44// CHECK-NEXT:  store i1 true, i1* [[FREEVAR]]
45// CHECK-NEXT:  [[EXN:%.*]] = bitcast i8* [[EXNOBJ]] to [[DSTAR:%[^*]*\*]]
46// CHECK-NEXT:  invoke void @_ZN7test2_DC1ERKS_([[DSTAR]] [[EXN]], [[DSTAR]] @d2)
47// CHECK-NEXT:     to label %[[CONT:.*]] unwind label %{{.*}}
48// CHECK:     [[CONT]]:
49// CHECK-NEXT:  store i1 false, i1* [[FREEVAR]]
50// CHECK-NEXT:  call void @__cxa_throw(i8* [[EXNOBJ]], i8* bitcast (%{{.*}}* @_ZTI7test2_D to i8*), i8* null) noreturn
51// CHECK-NEXT:  unreachable
52
53
54struct test3_D {
55  test3_D() { }
56  test3_D(volatile test3_D&o);
57  virtual void bar();
58};
59
60void test3() {
61  throw (volatile test3_D *)0;
62}
63
64// CHECK:     define void @_Z5test3v()
65// CHECK:       [[FREEVAR:%.*]] = alloca i1
66// CHECK-NEXT:  [[EXNOBJVAR:%.*]] = alloca i8*
67// CHECK-NEXT:  store i1 false, i1* [[FREEVAR]]
68// CHECK-NEXT:  [[EXNOBJ:%.*]] = call i8* @__cxa_allocate_exception(i64 8)
69// CHECK-NEXT:  store i8* [[EXNOBJ]], i8** [[EXNOBJVAR]]
70// CHECK-NEXT:  store i1 true, i1* [[FREEVAR]]
71// CHECK-NEXT:  [[EXN:%.*]] = bitcast i8* [[EXNOBJ]] to [[DSS:%[^*]*\*]]*
72// CHECK-NEXT:  store [[DSS]] null, [[DSS]]* [[EXN]]
73// CHECK-NEXT:  store i1 false, i1* [[FREEVAR]]
74// CHECK-NEXT:  call void @__cxa_throw(i8* [[EXNOBJ]], i8* bitcast (%1* @_ZTIPV7test3_D to i8*), i8* null) noreturn
75// CHECK-NEXT:  unreachable
76
77
78void test4() {
79  throw;
80}
81
82// CHECK:     define void @_Z5test4v()
83// CHECK:        call void @__cxa_rethrow() noreturn
84// CHECK-NEXT:   unreachable
85
86
87// rdar://problem/7696549
88namespace test5 {
89  struct A {
90    A();
91    A(const A&);
92    ~A();
93  };
94
95  void test() {
96    try { throw A(); } catch (A &x) {}
97  }
98// CHECK:      define void @_ZN5test54testEv()
99// CHECK:      [[EXNOBJ:%.*]] = call i8* @__cxa_allocate_exception(i64 1)
100// CHECK:      [[EXNCAST:%.*]] = bitcast i8* [[EXNOBJ]] to [[A:%[^*]*]]*
101// CHECK-NEXT: invoke void @_ZN5test51AC1Ev([[A]]* [[EXNCAST]])
102// CHECK:      invoke void @__cxa_throw(i8* [[EXNOBJ]], i8* bitcast ({{%.*}}* @_ZTIN5test51AE to i8*), i8* bitcast (void ([[A]]*)* @_ZN5test51AD1Ev to i8*)) noreturn
103// CHECK-NEXT:   to label {{%.*}} unwind label %[[HANDLER:[^ ]*]]
104// CHECK:    [[HANDLER]]:
105// CHECK:      {{%.*}} = call i32 @llvm.eh.typeid.for(i8* bitcast ({{%.*}}* @_ZTIN5test51AE to i8*))
106}
107