1 // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
2 
3 // CHECK: @_ZZ1hvE1i = internal global i32 0, align 4
4 // CHECK: @base_req = global [4 x i8] c"foo\00", align 1
5 
6 // CHECK: @_ZZN5test1L6getvarEiE3var = internal constant [4 x i32] [i32 1, i32 0, i32 2, i32 4], align 16
7 // CHECK: @_ZZ2h2vE1i = linkonce_odr global i32 0
8 // CHECK: @_ZGVZ2h2vE1i = linkonce_odr global i64 0
9 
10 struct A {
11   A();
12   ~A();
13 };
14 
15 void f() {
16   // CHECK: load atomic i8* bitcast (i64* @_ZGVZ1fvE1a to i8*) acquire, align 1
17   // CHECK: call i32 @__cxa_guard_acquire
18   // CHECK: call void @_ZN1AC1Ev
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*))
20   // CHECK: call void @__cxa_guard_release
21   static A a;
22 }
23 
24 void g() {
25   // CHECK: call noalias i8* @_Znwm(i64 1)
26   // CHECK: call void @_ZN1AC1Ev(
27   static A& a = *new A;
28 }
29 
30 int a();
31 void h() {
32   static const int i = a();
33 }
34 
35 inline void h2() {
36   static int i = a();
37 }
38 
39 void h3() {
40   h2();
41 }
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 }
53 
54 namespace test1 {
55   // CHECK: define internal i32 @_ZN5test1L6getvarEi(
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 }
63 
64 // Make sure we emit the initializer correctly for the following:
65 char base_req[] = { "foo" };
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 }
82