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