1 // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
3 // CHECK: @_ZZ1hvE1i = internal global i32 0, align 4
4 // CHECK: @base_req = global [4 x i8] c"foo\00", align 1
5 // CHECK: @base_req_uchar = global [4 x i8] c"bar\00", align 1
7 // CHECK: @_ZZN5test31BC1EvE1u = internal global { i8, [3 x i8] } { i8 97, [3 x i8] undef }, align 4
8 // CHECK: @_ZZN5test1L6getvarEiE3var = internal constant [4 x i32] [i32 1, i32 0, i32 2, i32 4], align 16
9 // CHECK: @_ZZ2h2vE1i = linkonce_odr global i32 0
10 // CHECK: @_ZGVZ2h2vE1i = linkonce_odr global i64 0
18 // CHECK: load atomic i8* bitcast (i64* @_ZGVZ1fvE1a to i8*) acquire, align 1
19 // CHECK: call i32 @__cxa_guard_acquire
20 // CHECK: call void @_ZN1AC1Ev
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)
22 // CHECK: call void @__cxa_guard_release
27 // CHECK: call noalias i8* @_Znwm(i64 1)
28 // CHECK: call void @_ZN1AC1Ev(
34 static const int i = a();
45 // PR6980: this shouldn't crash
48 __attribute__((noreturn)) int throw_exception();
57 // CHECK-LABEL: define internal i32 @_ZN5test1L6getvarEi(
58 static inline int getvar(int index) {
59 static const int var[] = { 1, 0, 2, 4 };
63 void test() { (void) getvar(2); }
66 // Make sure we emit the initializer correctly for the following:
67 char base_req[] = { "foo" };
68 unsigned char base_req_uchar[] = { "bar" };
70 namespace union_static_local {
71 // CHECK-LABEL: 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]; };
76 static union x foo = { .x = { "a", "b" } };
86 // rdar://problem/11091093
87 // Static variables should be consistent across constructor
88 // or destructor variants.
95 struct B : virtual A {
100 // If we ever implement this as a delegate ctor call, just change
101 // this to take variadic arguments or something.
104 static int x = foo();
106 // CHECK-LABEL: 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)
113 // CHECK-LABEL: 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)
120 // This is just for completeness, because we actually emit this
121 // using a delegate dtor call.
123 static int y = foo();
125 // CHECK-LABEL: define void @_ZN5test21BD1Ev(
126 // CHECK: call void @_ZN5test21BD2Ev(
128 // CHECK-LABEL: 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)
136 // This shouldn't error out.
143 struct B : virtual A {
149 union U { char x; int i; };
150 static U u = { 'a' };
152 // CHECK-LABEL: define void @_ZN5test31BC1Ev(
153 // CHECK-LABEL: define void @_ZN5test31BC2Ev(