1 // RUN: %clang_cc1 %s -triple=x86_64-pc-linuxs -emit-llvm -std=c++98 -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK98 %s
2 // RUN: %clang_cc1 %s -triple=x86_64-pc-linuxs -emit-llvm -std=c++11 -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK11 %s
4 // CHECK: @_ZZ1hvE1i = internal global i32 0, align 4
5 // CHECK: @base_req ={{.*}} global [4 x i8] c"foo\00", align 1
6 // CHECK: @base_req_uchar ={{.*}} global [4 x i8] c"bar\00", align 1
8 // CHECK: @_ZZN5test31BC1EvE1u = internal global { i8, [3 x i8] } { i8 97, [3 x i8] undef }, align 4
10 // CHECK: @_ZZ2h2vE1i = linkonce_odr global i32 0, comdat, align 4
11 // CHECK: @_ZGVZ2h2vE1i = linkonce_odr global i64 0, comdat, align 8{{$}}
12 // CHECK: @_ZZN5test1L6getvarEiE3var = internal constant [4 x i32] [i32 1, i32 0, i32 2, i32 4], align 16
13 // CHECK98: @_ZZN5test414useStaticLocalEvE3obj = linkonce_odr global %"struct.test4::HasVTable" zeroinitializer, comdat, align 8
14 // CHECK11: @_ZZN5test414useStaticLocalEvE3obj = linkonce_odr global %"struct.test4::HasVTable" { ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTVN5test49HasVTableE, i32 0, inrange i32 0, i32 2) }, comdat, align 8
22 // CHECK: load atomic i8, ptr @_ZGVZ1fvE1a acquire, align 8
23 // CHECK: call i32 @__cxa_guard_acquire
24 // CHECK: call void @_ZN1AC1Ev
25 // CHECK: call i32 @__cxa_atexit(ptr @_ZN1AD1Ev, ptr @_ZZ1fvE1a, ptr @__dso_handle)
26 // CHECK: call void @__cxa_guard_release
31 // CHECK: call noalias noundef nonnull ptr @_Znwm(i64 noundef 1)
32 // CHECK: call void @_ZN1AC1Ev(
38 static const int i
= a();
41 // CHECK: define linkonce_odr void @_Z2h2v() {{.*}} comdat {
50 // PR6980: this shouldn't crash
53 __attribute__((noreturn
)) int throw_exception();
62 // CHECK-LABEL: define internal noundef i32 @_ZN5test1L6getvarEi(
63 static inline int getvar(int index
) {
64 static const int var
[] = { 1, 0, 2, 4 };
68 void test() { (void) getvar(2); }
71 // Make sure we emit the initializer correctly for the following:
72 char base_req
[] = { "foo" };
73 unsigned char base_req_uchar
[] = { "bar" };
75 namespace union_static_local
{
76 // CHECK-LABEL: define internal void @_ZZN18union_static_local4testEvEN1c4mainEv
77 // CHECK: call void @_ZN18union_static_local1fEPNS_1xE(ptr noundef @_ZZN18union_static_local4testEvE3foo)
78 union x
{ long double y
; const char *x
[2]; };
81 static union x foo
= { .x
= { "a", "b" } };
91 // rdar://problem/11091093
92 // Static variables should be consistent across constructor
93 // or destructor variants.
100 struct B
: virtual A
{
105 // If we ever implement this as a delegate ctor call, just change
106 // this to take variadic arguments or something.
109 static int x
= foo();
111 // CHECK-LABEL: define{{.*}} void @_ZN5test21BC2Ev
112 // CHECK: load atomic i8, ptr @_ZGVZN5test21BC1EvE1x acquire, align 8
113 // CHECK: call i32 @__cxa_guard_acquire(ptr @_ZGVZN5test21BC1EvE1x)
114 // CHECK: [[T0:%.*]] = call noundef i32 @_ZN5test23fooEv()
115 // CHECK: store i32 [[T0]], ptr @_ZZN5test21BC1EvE1x,
116 // CHECK: call void @__cxa_guard_release(ptr @_ZGVZN5test21BC1EvE1x)
118 // CHECK-LABEL: define{{.*}} void @_ZN5test21BC1Ev
119 // CHECK: load atomic i8, ptr @_ZGVZN5test21BC1EvE1x acquire, align 8
120 // CHECK: call i32 @__cxa_guard_acquire(ptr @_ZGVZN5test21BC1EvE1x)
121 // CHECK: [[T0:%.*]] = call noundef i32 @_ZN5test23fooEv()
122 // CHECK: store i32 [[T0]], ptr @_ZZN5test21BC1EvE1x,
123 // CHECK: call void @__cxa_guard_release(ptr @_ZGVZN5test21BC1EvE1x)
125 // This is just for completeness, because we actually emit this
126 // using a delegate dtor call.
128 static int y
= foo();
130 // CHECK-LABEL: define{{.*}} void @_ZN5test21BD2Ev(
131 // CHECK: load atomic i8, ptr @_ZGVZN5test21BD1EvE1y acquire, align 8
132 // CHECK: call i32 @__cxa_guard_acquire(ptr @_ZGVZN5test21BD1EvE1y)
133 // CHECK: [[T0:%.*]] = call noundef i32 @_ZN5test23fooEv()
134 // CHECK: store i32 [[T0]], ptr @_ZZN5test21BD1EvE1y,
135 // CHECK: call void @__cxa_guard_release(ptr @_ZGVZN5test21BD1EvE1y)
137 // CHECK-LABEL: define{{.*}} void @_ZN5test21BD1Ev(
138 // CHECK: call void @_ZN5test21BD2Ev(
141 // This shouldn't error out.
148 struct B
: virtual A
{
154 union U
{ char x
; int i
; };
155 static U u
= { 'a' };
157 // CHECK-LABEL: define{{.*}} void @_ZN5test31BC2Ev(
158 // CHECK-LABEL: define{{.*}} void @_ZN5test31BC1Ev(
161 // We forgot to set the comdat when replacing the global with a different type.
166 inline HasVTable
&useStaticLocal() {
167 static HasVTable obj
;
173 // CHECK: define linkonce_odr noundef nonnull align 8 dereferenceable(8) ptr @_ZN5test414useStaticLocalEv()
174 // CHECK: ret ptr{{.*}} @_ZZN5test414useStaticLocalEvE3obj