John McCall | 044cc54 | 2010-07-06 04:38:10 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm -fexceptions %s -o - |FileCheck %s |
| 2 | // RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm %s -o - |FileCheck -check-prefix NOEXC %s |
Anders Carlsson | 89ed31d | 2009-08-08 23:24:23 +0000 | [diff] [blame] | 3 | |
| 4 | struct A { |
| 5 | A(); |
| 6 | ~A(); |
| 7 | }; |
| 8 | |
Anders Carlsson | 74d644a | 2009-10-08 17:28:59 +0000 | [diff] [blame] | 9 | struct B { B(); ~B(); }; |
| 10 | |
John McCall | fb8b69a | 2010-02-02 08:02:49 +0000 | [diff] [blame] | 11 | struct C { void *field; }; |
| 12 | |
Anders Carlsson | 2ca4f63 | 2010-02-05 18:38:45 +0000 | [diff] [blame] | 13 | struct D { ~D(); }; |
| 14 | |
John McCall | fb8b69a | 2010-02-02 08:02:49 +0000 | [diff] [blame] | 15 | // CHECK: @c = global %struct.C zeroinitializer, align 8 |
| 16 | |
Anders Carlsson | 74d644a | 2009-10-08 17:28:59 +0000 | [diff] [blame] | 17 | // CHECK: call void @_ZN1AC1Ev(%struct.A* @a) |
Anders Carlsson | a3f36ab | 2009-10-08 17:22:47 +0000 | [diff] [blame] | 18 | // CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1AD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @a, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*)) |
Anders Carlsson | 89ed31d | 2009-08-08 23:24:23 +0000 | [diff] [blame] | 19 | A a; |
Anders Carlsson | 74d644a | 2009-10-08 17:28:59 +0000 | [diff] [blame] | 20 | |
| 21 | // CHECK: call void @_ZN1BC1Ev(%struct.A* @b) |
| 22 | // CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1BD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @b, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*)) |
| 23 | B b; |
John McCall | fb8b69a | 2010-02-02 08:02:49 +0000 | [diff] [blame] | 24 | |
| 25 | // PR6205: this should not require a global initializer |
| 26 | // CHECK-NOT: call void @_ZN1CC1Ev(%struct.C* @c) |
| 27 | C c; |
| 28 | |
Anders Carlsson | 2ca4f63 | 2010-02-05 18:38:45 +0000 | [diff] [blame] | 29 | // CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1DD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @d, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*)) |
| 30 | D d; |
| 31 | |
John McCall | bf40cb5 | 2010-07-15 23:40:35 +0000 | [diff] [blame] | 32 | // <rdar://problem/7458115> |
| 33 | namespace test1 { |
| 34 | int f(); |
| 35 | const int x = f(); // This has side-effects and gets emitted immediately. |
| 36 | const int y = x - 1; // This gets deferred. |
| 37 | const int z = ~y; // This also gets deferred, but gets "undeferred" before y. |
| 38 | int test() { return z; } |
| 39 | // CHECK: define i32 @_ZN5test14testEv() { |
John McCall | 85aca0f | 2010-07-30 04:56:58 +0000 | [diff] [blame^] | 40 | |
| 41 | // All of these initializers end up delayed, so we check them later. |
| 42 | } |
| 43 | |
| 44 | // <rdar://problem/8246444> |
| 45 | namespace test2 { |
| 46 | struct allocator { allocator(); ~allocator(); }; |
| 47 | struct A { A(const allocator &a = allocator()); ~A(); }; |
| 48 | |
| 49 | A a; |
| 50 | // CHECK: call void @_ZN5test29allocatorC1Ev( |
| 51 | // CHECK: invoke void @_ZN5test21AC1ERKNS_9allocatorE( |
| 52 | // CHECK: call void @_ZN5test29allocatorD1Ev( |
| 53 | // CHECK: call i32 @__cxa_atexit({{.*}} @_ZN5test21AD1Ev {{.*}} @_ZN5test21aE |
| 54 | } |
| 55 | |
John McCall | bf40cb5 | 2010-07-15 23:40:35 +0000 | [diff] [blame] | 56 | // CHECK: define internal void [[TEST1_Z_INIT:@.*]]() |
| 57 | // CHECK: load i32* @_ZN5test1L1yE |
| 58 | // CHECK-NEXT: xor |
| 59 | // CHECK-NEXT: store i32 {{.*}}, i32* @_ZN5test1L1zE |
| 60 | // CHECK: define internal void [[TEST1_Y_INIT:@.*]]() |
| 61 | // CHECK: load i32* @_ZN5test1L1xE |
| 62 | // CHECK-NEXT: sub |
| 63 | // CHECK-NEXT: store i32 {{.*}}, i32* @_ZN5test1L1yE |
| 64 | |
John McCall | 85aca0f | 2010-07-30 04:56:58 +0000 | [diff] [blame^] | 65 | // At the end of the file, we check that y is initialized before z. |
John McCall | bf40cb5 | 2010-07-15 23:40:35 +0000 | [diff] [blame] | 66 | |
Anders Carlsson | 9df792c | 2010-06-09 01:42:52 +0000 | [diff] [blame] | 67 | // CHECK: define internal void @_GLOBAL__I_a() section "__TEXT,__StaticInit,regular,pure_instructions" { |
John McCall | bf40cb5 | 2010-07-15 23:40:35 +0000 | [diff] [blame] | 68 | // CHECK: call void [[TEST1_Y_INIT]] |
| 69 | // CHECK: call void [[TEST1_Z_INIT]] |
Anders Carlsson | 9df792c | 2010-06-09 01:42:52 +0000 | [diff] [blame] | 70 | |
John McCall | 044cc54 | 2010-07-06 04:38:10 +0000 | [diff] [blame] | 71 | // rdar://problem/8090834: this should be nounwind |
| 72 | // CHECK-NOEXC: define internal void @_GLOBAL__I_a() nounwind section "__TEXT,__StaticInit,regular,pure_instructions" { |