eh.cpp revision 53b4810bad9385fbc65f045711585517f99fd31b
1// RUN: %clang_cc1 -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() nounwind {
13// CHECK:       %{{exception.ptr|1}} = alloca i8*
14// CHECK-NEXT:  %{{exception|2}} = call i8* @__cxa_allocate_exception(i64 8)
15// CHECK-NEXT:  store i8* %{{exception|2}}, i8** %{{exception.ptr|1}}
16// CHECK-NEXT:  %{{0|3}} = bitcast i8* %{{exception|2}} to %struct.test1_D*
17// CHECK-NEXT:  %{{tmp|4}} = bitcast %struct.test1_D* %{{0|3}} to i8*
18// CHECK-NEXT:  call void @llvm.memcpy.i64(i8* %{{tmp|4}}, i8* bitcast (%struct.test1_D* @d1 to i8*), i64 8, i32 8)
19// CHECK-NEXT:  call void @__cxa_throw(i8* %{{exception|2}}, i8* bitcast (%0* @_ZTI7test1_D to i8*), i8* null) noreturn
20// CHECK-NEXT:  unreachable
21
22
23struct test2_D {
24  test2_D(const test2_D&o);
25  test2_D();
26  virtual void bar() { }
27  int i; int j;
28} d2;
29
30void test2() {
31  throw d2;
32}
33
34// CHECK:     define void @_Z5test2v() nounwind {
35// CHECK:       %{{exception.ptr|1}} = alloca i8*
36// CHECK-NEXT:  %{{exception|2}} = call i8* @__cxa_allocate_exception(i64 16)
37// CHECK-NEXT:  store i8* %{{exception|2}}, i8** %{{\1}}
38// CHECK-NEXT:  %{{0|3}} = bitcast i8* %{{exception|2}} to %struct.test2_D*
39// CHECK:       invoke void @_ZN7test2_DC1ERKS_(%struct.test2_D* %{{0|3}}, %struct.test2_D* @d2)
40// CHECK-NEXT:     to label %{{invoke.cont|8}} unwind label %{{terminate.handler|4}}
41// CHECK:  call void @__cxa_throw(i8* %{{exception|2}}, i8* bitcast (%{{0|3}}* @_ZTI7test2_D to i8*), i8* null) noreturn
42// CHECK-NEXT:  unreachable
43
44
45struct test3_D {
46  test3_D() { }
47  test3_D(volatile test3_D&o);
48  virtual void bar();
49};
50
51void test3() {
52  throw (volatile test3_D *)0;
53}
54
55// CHECK:     define void @_Z5test3v() nounwind {
56// CHECK:        %{{exception.ptr|1}} = alloca i8*
57// CHECK-NEXT:   %{{exception|2}} = call i8* @__cxa_allocate_exception(i64 8)
58// CHECK-NEXT:   store i8* %{{exception|2}}, i8** %{{exception.ptr|1}}
59// CHECK-NEXT:   %{{0|3}} = bitcast i8* %{{exception|2}} to %struct.test3_D**
60// CHECK-NEXT:   store %struct.test3_D* null, %struct.test3_D**
61// CHECK-NEXT:   call void @__cxa_throw(i8* %{{exception|2}}, i8* bitcast (%1* @_ZTIPV7test3_D to i8*), i8* null) noreturn
62// CHECK-NEXT:   unreachable
63
64
65void test4() {
66  throw;
67}
68
69// CHECK:     define void @_Z5test4v() nounwind {
70// CHECK:        call void @__cxa_rethrow() noreturn
71// CHECK-NEXT:   unreachable
72