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 |
Anders Carlsson | f6b89a1 | 2010-02-07 02:03:08 +0000 | [diff] [blame] | 5 | |
John McCall | 7895194 | 2011-03-22 06:58:49 +0000 | [diff] [blame] | 6 | // 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] | 7 | // CHECK: @_ZZ2h2vE1i = linkonce_odr global i32 0 |
| 8 | // CHECK: @_ZGVZ2h2vE1i = linkonce_odr global i64 0 |
Anders Carlsson | f6b89a1 | 2010-02-07 02:03:08 +0000 | [diff] [blame] | 9 | |
Anders Carlsson | 3b2e16b | 2009-08-08 21:45:14 +0000 | [diff] [blame] | 10 | struct A { |
| 11 | A(); |
| 12 | ~A(); |
| 13 | }; |
| 14 | |
| 15 | void f() { |
Eli Friedman | eb43f4a | 2011-09-13 22:21:56 +0000 | [diff] [blame] | 16 | // CHECK: load atomic i8* bitcast (i64* @_ZGVZ1fvE1a to i8*) acquire, align 1 |
Douglas Gregor | cc6a44b | 2010-05-05 15:38:32 +0000 | [diff] [blame] | 17 | // CHECK: call i32 @__cxa_guard_acquire |
| 18 | // CHECK: call void @_ZN1AC1Ev |
Anders Carlsson | c7974ca | 2009-12-10 01:05:11 +0000 | [diff] [blame] | 19 | // 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* bitcast (i8** @__dso_handle to i8*)) |
John McCall | 5cd91b5 | 2010-09-08 01:44:27 +0000 | [diff] [blame] | 20 | // CHECK: call void @__cxa_guard_release |
Anders Carlsson | 3b2e16b | 2009-08-08 21:45:14 +0000 | [diff] [blame] | 21 | static A a; |
| 22 | } |
| 23 | |
Anders Carlsson | c7974ca | 2009-12-10 01:05:11 +0000 | [diff] [blame] | 24 | void g() { |
Nuno Lopes | fc28448 | 2009-12-16 16:59:22 +0000 | [diff] [blame] | 25 | // CHECK: call noalias i8* @_Znwm(i64 1) |
Anders Carlsson | c7974ca | 2009-12-10 01:05:11 +0000 | [diff] [blame] | 26 | // CHECK: call void @_ZN1AC1Ev( |
| 27 | static A& a = *new A; |
| 28 | } |
Anders Carlsson | 071c810 | 2010-01-26 04:02:23 +0000 | [diff] [blame] | 29 | |
| 30 | int a(); |
| 31 | void h() { |
| 32 | static const int i = a(); |
| 33 | } |
Anders Carlsson | f6b89a1 | 2010-02-07 02:03:08 +0000 | [diff] [blame] | 34 | |
| 35 | inline void h2() { |
| 36 | static int i = a(); |
| 37 | } |
| 38 | |
| 39 | void h3() { |
| 40 | h2(); |
| 41 | } |
John McCall | e65ce96 | 2010-05-03 21:39:56 +0000 | [diff] [blame] | 42 | |
| 43 | // PR6980: this shouldn't crash |
| 44 | namespace test0 { |
| 45 | struct A { A(); }; |
| 46 | __attribute__((noreturn)) int throw_exception(); |
| 47 | |
| 48 | void test() { |
| 49 | throw_exception(); |
| 50 | static A r; |
| 51 | } |
| 52 | } |
John McCall | 8b24233 | 2010-05-25 04:30:21 +0000 | [diff] [blame] | 53 | |
| 54 | namespace test1 { |
John McCall | 7895194 | 2011-03-22 06:58:49 +0000 | [diff] [blame] | 55 | // CHECK: define internal i32 @_ZN5test1L6getvarEi( |
John McCall | 8b24233 | 2010-05-25 04:30:21 +0000 | [diff] [blame] | 56 | static inline int getvar(int index) { |
| 57 | static const int var[] = { 1, 0, 2, 4 }; |
| 58 | return var[index]; |
| 59 | } |
| 60 | |
| 61 | void test() { (void) getvar(2); } |
| 62 | } |
Eli Friedman | 8b42ab7 | 2012-03-09 03:06:56 +0000 | [diff] [blame] | 63 | |
| 64 | // Make sure we emit the initializer correctly for the following: |
| 65 | char base_req[] = { "foo" }; |
Eli Friedman | 71cba34 | 2012-03-09 03:27:46 +0000 | [diff] [blame] | 66 | |
| 67 | namespace union_static_local { |
| 68 | // CHECK: define internal void @_ZZN18union_static_local4testEvEN1c4mainEv |
| 69 | // 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"*)) |
| 70 | union x { long double y; const char *x[2]; }; |
| 71 | void f(union x*); |
| 72 | void test() { |
| 73 | static union x foo = { .x = { "a", "b" } }; |
| 74 | struct c { |
| 75 | static void main() { |
| 76 | f(&foo); |
| 77 | } |
| 78 | }; |
| 79 | c::main(); |
| 80 | } |
| 81 | } |