1 // RUN: %clang_cc1 %s -emit-llvm -o %t.ll -triple=x86_64-apple-darwin10
2 // RUN: FileCheck %s < %t.ll
3 // RUN: FileCheck -check-prefix=CHECK-GLOBAL %s < %t.ll
5 struct A
{ int a
; int b
; };
11 // CHECK-GLOBAL: @_ZN8ZeroInit1aE ={{.*}} global i64 -1
14 // CHECK-GLOBAL: @_ZN8ZeroInit2aaE ={{.*}} global [2 x i64] [i64 -1, i64 -1]
17 // CHECK-GLOBAL: @_ZN8ZeroInit3aaaE ={{.*}} global [2 x [2 x i64]] {{\[}}[2 x i64] [i64 -1, i64 -1], [2 x i64] [i64 -1, i64 -1]]
20 // CHECK-GLOBAL: @_ZN8ZeroInit1bE ={{.*}} global i64 -1,
23 // CHECK-GLOBAL: @_ZN8ZeroInit2saE = internal global %struct.anon { i64 -1 }
27 void test_sa() { (void) sa
; } // force emission
29 // CHECK-GLOBAL: @_ZN8ZeroInit3ssaE = internal
30 // CHECK-GLOBAL: [2 x i64] [i64 -1, i64 -1]
34 void test_ssa() { (void) ssa
; }
36 // CHECK-GLOBAL: @_ZN8ZeroInit2ssE = internal global %struct.anon.1 { %struct.anon.2 { i64 -1 } }
42 void test_ss() { (void) ss
; }
55 struct C
: A
, B
{ int j
; };
56 // CHECK-GLOBAL: @_ZN8ZeroInit1cE ={{.*}} global {{%.*}} <{ %"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::B" { [10 x %"struct.ZeroInit::A"] [%"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::A" { i64 -1, i32 0 }, %"struct.ZeroInit::A" { i64 -1, i32 0 }], i8 0, i64 -1 }, i32 0, [4 x i8] zeroinitializer }>, align 8
62 // CHECK-GLOBAL: @_ZN6PR56742pbE ={{.*}} global i64 4
73 // CHECK: store i64 -1, ptr @_ZN5Casts2paE
76 // CHECK-NEXT: [[TMP:%.*]] = load i64, ptr @_ZN5Casts2paE, align 8
77 // CHECK-NEXT: [[ADJ:%.*]] = add nsw i64 [[TMP]], 4
78 // CHECK-NEXT: [[ISNULL:%.*]] = icmp eq i64 [[TMP]], -1
79 // CHECK-NEXT: [[RES:%.*]] = select i1 [[ISNULL]], i64 [[TMP]], i64 [[ADJ]]
80 // CHECK-NEXT: store i64 [[RES]], ptr @_ZN5Casts2pcE
83 // CHECK-NEXT: [[TMP:%.*]] = load i64, ptr @_ZN5Casts2pcE, align 8
84 // CHECK-NEXT: [[ADJ:%.*]] = sub nsw i64 [[TMP]], 4
85 // CHECK-NEXT: [[ISNULL:%.*]] = icmp eq i64 [[TMP]], -1
86 // CHECK-NEXT: [[RES:%.*]] = select i1 [[ISNULL]], i64 [[TMP]], i64 [[ADJ]]
87 // CHECK-NEXT: store i64 [[RES]], ptr @_ZN5Casts2paE
88 pa
= static_cast<int A::*>(pc
);
94 namespace Comparisons
{
98 // CHECK: icmp ne i64 {{.*}}, -1
101 // CHECK: icmp ne i64 {{.*}}, -1
104 // CHECK: icmp ne i64 -1, {{.*}}
107 // CHECK: icmp eq i64 {{.*}}, -1
110 // CHECK: icmp eq i64 -1, {{.*}}
115 namespace ValueInit
{
125 // CHECK-LABEL: define{{.*}} void @_ZN9ValueInit1AC2Ev(ptr {{[^,]*}} %this) unnamed_addr
126 // CHECK: store i64 -1, ptr
132 namespace VirtualBases
{
139 // CHECK-GLOBAL: @_ZN12VirtualBases1bE ={{.*}} global %"struct.VirtualBases::B" { ptr null, %"struct.VirtualBases::A" { i8 0, i64 -1 } }, align 8
140 struct B
: virtual A
{ };
143 // CHECK-GLOBAL: @_ZN12VirtualBases1cE ={{.*}} global %"struct.VirtualBases::C" { ptr null, i64 -1, %"struct.VirtualBases::A" { i8 0, i64 -1 } }, align 8
144 struct C
: virtual A
{ int A::*i
; };
147 // CHECK-GLOBAL: @_ZN12VirtualBases1dE ={{.*}} global %"struct.VirtualBases::D" { %"struct.VirtualBases::C.base" { ptr null, i64 -1 }, i64 -1, %"struct.VirtualBases::A" { i8 0, i64 -1 } }, align 8
148 struct D
: C
{ int A::*i
; };
155 // Don't crash when A contains a bit-field.
164 namespace BoolPtrToMember
{
169 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZN15BoolPtrToMember1fERNS_1XEMS0_b
170 bool &f(X
&x
, bool X::*member
) {
171 // CHECK: getelementptr inbounds i8, ptr
172 // CHECK-NEXT: ret ptr
180 void f(S
* p
, double S::*pm
) {
188 struct A
{ int A_i
; };
189 struct B
: virtual A
{ int A::*B_p
; };
190 struct C
: virtual B
{ int *C_p
; };
191 struct D
: C
{ int *D_p
; };
193 // CHECK-GLOBAL: @_ZN5test41dE ={{.*}} global %"struct.test4::D" { %"struct.test4::C.base" zeroinitializer, ptr null, %"struct.test4::B.base" { ptr null, i64 -1 }, %"struct.test4::A" zeroinitializer }, align 8
203 // CHECK-GLOBAL: @_ZN7PR114871xE ={{.*}} global %"union.PR11487::U" { i64 -1, [8 x i8] zeroinitializer }, align 8
208 struct X
{ int x
; X(const X
&); };
214 X
g() { return f().*&A::x
; }
215 // CHECK-LABEL: define{{.*}} void @_ZN7PR130971gEv
216 // CHECK: call void @_ZN7PR130971fEv
218 // CHECK: call void @_ZN7PR130971XC1ERKS0_
231 // CHECK-GLOBAL: @_ZN7PR210891bE ={{.*}} global %"struct.PR21089::B" { %"struct.PR21089::A.base" <{ i8 0, [7 x i8] zeroinitializer, i64 -1, i8 0 }>, [7 x i8] zeroinitializer }, align 8
240 // CHECK-GLOBAL: @_ZN7PR212821uE ={{.*}} global %"union.PR21282::U" { i64 -1, [8 x i8] zeroinitializer }, align 8
243 namespace FlexibleArrayMember
{
248 // CHECK-GLOBAL: @_ZN19FlexibleArrayMember1sE ={{.*}} global %"struct.FlexibleArrayMember::S" zeroinitializer, align 8
251 namespace IndirectPDM
{
258 // CHECK-GLOBAL: @_ZN11IndirectPDM1uE ={{.*}} global %"union.IndirectPDM::U" { %union.anon { i64 -1 } }, align 8
264 struct D
: B
{ int m
; };
265 auto x
= (int B::*)&D::m
;