Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s |
Anders Carlsson | 071c810 | 2010-01-26 04:02:23 +0000 | [diff] [blame] | 2 | |
| 3 | // CHECK: @_ZZ1hvE1i = internal global i32 0, align 4 |
Eli Friedman | 8b42ab7 | 2012-03-09 03:06:56 +0000 | [diff] [blame] | 4 | // CHECK: @base_req = global [4 x i8] c"foo\00", align 1 |
Richard Smith | fe58720 | 2012-04-15 02:50:59 +0000 | [diff] [blame] | 5 | // CHECK: @base_req_uchar = global [4 x i8] c"bar\00", align 1 |
Anders Carlsson | f6b89a1 | 2010-02-07 02:03:08 +0000 | [diff] [blame] | 6 | |
John McCall | 355bba7 | 2012-03-30 21:00:39 +0000 | [diff] [blame] | 7 | // CHECK: @_ZZN5test31BC1EvE1u = internal global { i8, [3 x i8] } { i8 97, [3 x i8] undef }, align 4 |
John McCall | 7895194 | 2011-03-22 06:58:49 +0000 | [diff] [blame] | 8 | // CHECK: @_ZZN5test1L6getvarEiE3var = internal constant [4 x i32] [i32 1, i32 0, i32 2, i32 4], align 16 |
John McCall | 8b24233 | 2010-05-25 04:30:21 +0000 | [diff] [blame] | 9 | // CHECK: @_ZZ2h2vE1i = linkonce_odr global i32 0 |
| 10 | // CHECK: @_ZGVZ2h2vE1i = linkonce_odr global i64 0 |
Anders Carlsson | f6b89a1 | 2010-02-07 02:03:08 +0000 | [diff] [blame] | 11 | |
Anders Carlsson | 3b2e16b | 2009-08-08 21:45:14 +0000 | [diff] [blame] | 12 | struct A { |
| 13 | A(); |
| 14 | ~A(); |
| 15 | }; |
| 16 | |
| 17 | void f() { |
Eli Friedman | eb43f4a | 2011-09-13 22:21:56 +0000 | [diff] [blame] | 18 | // CHECK: load atomic i8* bitcast (i64* @_ZGVZ1fvE1a to i8*) acquire, align 1 |
Douglas Gregor | cc6a44b | 2010-05-05 15:38:32 +0000 | [diff] [blame] | 19 | // CHECK: call i32 @__cxa_guard_acquire |
| 20 | // CHECK: call void @_ZN1AC1Ev |
John McCall | 30fa370 | 2012-04-06 18:21:06 +0000 | [diff] [blame] | 21 | // CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1AD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @_ZZ1fvE1a, i32 0, i32 0), i8* @__dso_handle) |
John McCall | 5cd91b5 | 2010-09-08 01:44:27 +0000 | [diff] [blame] | 22 | // CHECK: call void @__cxa_guard_release |
Anders Carlsson | 3b2e16b | 2009-08-08 21:45:14 +0000 | [diff] [blame] | 23 | static A a; |
| 24 | } |
| 25 | |
Anders Carlsson | c7974ca | 2009-12-10 01:05:11 +0000 | [diff] [blame] | 26 | void g() { |
Nuno Lopes | fc28448 | 2009-12-16 16:59:22 +0000 | [diff] [blame] | 27 | // CHECK: call noalias i8* @_Znwm(i64 1) |
Anders Carlsson | c7974ca | 2009-12-10 01:05:11 +0000 | [diff] [blame] | 28 | // CHECK: call void @_ZN1AC1Ev( |
| 29 | static A& a = *new A; |
| 30 | } |
Anders Carlsson | 071c810 | 2010-01-26 04:02:23 +0000 | [diff] [blame] | 31 | |
| 32 | int a(); |
| 33 | void h() { |
| 34 | static const int i = a(); |
| 35 | } |
Anders Carlsson | f6b89a1 | 2010-02-07 02:03:08 +0000 | [diff] [blame] | 36 | |
| 37 | inline void h2() { |
| 38 | static int i = a(); |
| 39 | } |
| 40 | |
| 41 | void h3() { |
| 42 | h2(); |
| 43 | } |
John McCall | e65ce96 | 2010-05-03 21:39:56 +0000 | [diff] [blame] | 44 | |
| 45 | // PR6980: this shouldn't crash |
| 46 | namespace test0 { |
| 47 | struct A { A(); }; |
| 48 | __attribute__((noreturn)) int throw_exception(); |
| 49 | |
| 50 | void test() { |
| 51 | throw_exception(); |
| 52 | static A r; |
| 53 | } |
| 54 | } |
John McCall | 8b24233 | 2010-05-25 04:30:21 +0000 | [diff] [blame] | 55 | |
| 56 | namespace test1 { |
John McCall | 7895194 | 2011-03-22 06:58:49 +0000 | [diff] [blame] | 57 | // CHECK: define internal i32 @_ZN5test1L6getvarEi( |
John McCall | 8b24233 | 2010-05-25 04:30:21 +0000 | [diff] [blame] | 58 | static inline int getvar(int index) { |
| 59 | static const int var[] = { 1, 0, 2, 4 }; |
| 60 | return var[index]; |
| 61 | } |
| 62 | |
| 63 | void test() { (void) getvar(2); } |
| 64 | } |
Eli Friedman | 8b42ab7 | 2012-03-09 03:06:56 +0000 | [diff] [blame] | 65 | |
| 66 | // Make sure we emit the initializer correctly for the following: |
| 67 | char base_req[] = { "foo" }; |
Richard Smith | fe58720 | 2012-04-15 02:50:59 +0000 | [diff] [blame] | 68 | unsigned char base_req_uchar[] = { "bar" }; |
Eli Friedman | 71cba34 | 2012-03-09 03:27:46 +0000 | [diff] [blame] | 69 | |
| 70 | namespace union_static_local { |
| 71 | // CHECK: define internal void @_ZZN18union_static_local4testEvEN1c4mainEv |
| 72 | // CHECK: call void @_ZN18union_static_local1fEPNS_1xE(%"union.union_static_local::x"* bitcast ({ [2 x i8*] }* @_ZZN18union_static_local4testEvE3foo to %"union.union_static_local::x"*)) |
| 73 | union x { long double y; const char *x[2]; }; |
| 74 | void f(union x*); |
| 75 | void test() { |
| 76 | static union x foo = { .x = { "a", "b" } }; |
| 77 | struct c { |
| 78 | static void main() { |
| 79 | f(&foo); |
| 80 | } |
| 81 | }; |
| 82 | c::main(); |
| 83 | } |
| 84 | } |
John McCall | 355bba7 | 2012-03-30 21:00:39 +0000 | [diff] [blame] | 85 | |
| 86 | // rdar://problem/11091093 |
| 87 | // Static variables should be consistent across constructor |
| 88 | // or destructor variants. |
| 89 | namespace test2 { |
| 90 | struct A { |
| 91 | A(); |
| 92 | ~A(); |
| 93 | }; |
| 94 | |
| 95 | struct B : virtual A { |
| 96 | B(); |
| 97 | ~B(); |
| 98 | }; |
| 99 | |
| 100 | // If we ever implement this as a delegate ctor call, just change |
| 101 | // this to take variadic arguments or something. |
| 102 | extern int foo(); |
| 103 | B::B() { |
| 104 | static int x = foo(); |
| 105 | } |
| 106 | // CHECK: define void @_ZN5test21BC1Ev |
| 107 | // CHECK: load atomic i8* bitcast (i64* @_ZGVZN5test21BC1EvE1x to i8*) acquire, |
| 108 | // CHECK: call i32 @__cxa_guard_acquire(i64* @_ZGVZN5test21BC1EvE1x) |
| 109 | // CHECK: [[T0:%.*]] = call i32 @_ZN5test23fooEv() |
| 110 | // CHECK: store i32 [[T0]], i32* @_ZZN5test21BC1EvE1x, |
| 111 | // CHECK: call void @__cxa_guard_release(i64* @_ZGVZN5test21BC1EvE1x) |
| 112 | |
| 113 | // CHECK: define void @_ZN5test21BC2Ev |
| 114 | // CHECK: load atomic i8* bitcast (i64* @_ZGVZN5test21BC1EvE1x to i8*) acquire, |
| 115 | // CHECK: call i32 @__cxa_guard_acquire(i64* @_ZGVZN5test21BC1EvE1x) |
| 116 | // CHECK: [[T0:%.*]] = call i32 @_ZN5test23fooEv() |
| 117 | // CHECK: store i32 [[T0]], i32* @_ZZN5test21BC1EvE1x, |
| 118 | // CHECK: call void @__cxa_guard_release(i64* @_ZGVZN5test21BC1EvE1x) |
| 119 | |
| 120 | // This is just for completeness, because we actually emit this |
| 121 | // using a delegate dtor call. |
| 122 | B::~B() { |
| 123 | static int y = foo(); |
| 124 | } |
| 125 | // CHECK: define void @_ZN5test21BD1Ev( |
| 126 | // CHECK: call void @_ZN5test21BD2Ev( |
| 127 | |
| 128 | // CHECK: define void @_ZN5test21BD2Ev( |
| 129 | // CHECK: load atomic i8* bitcast (i64* @_ZGVZN5test21BD1EvE1y to i8*) acquire, |
| 130 | // CHECK: call i32 @__cxa_guard_acquire(i64* @_ZGVZN5test21BD1EvE1y) |
| 131 | // CHECK: [[T0:%.*]] = call i32 @_ZN5test23fooEv() |
| 132 | // CHECK: store i32 [[T0]], i32* @_ZZN5test21BD1EvE1y, |
| 133 | // CHECK: call void @__cxa_guard_release(i64* @_ZGVZN5test21BD1EvE1y) |
| 134 | } |
| 135 | |
| 136 | // This shouldn't error out. |
| 137 | namespace test3 { |
| 138 | struct A { |
| 139 | A(); |
| 140 | ~A(); |
| 141 | }; |
| 142 | |
| 143 | struct B : virtual A { |
| 144 | B(); |
| 145 | ~B(); |
| 146 | }; |
| 147 | |
| 148 | B::B() { |
| 149 | union U { char x; int i; }; |
| 150 | static U u = { 'a' }; |
| 151 | } |
| 152 | // CHECK: define void @_ZN5test31BC1Ev( |
| 153 | // CHECK: define void @_ZN5test31BC2Ev( |
| 154 | } |