[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGenCXX / pointers-to-data-members.cpp
blob29f1c3f48e3ac04308fa8ef13d6c6cd483f84257
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; };
6 struct B { int b; };
7 struct C : B, A { };
9 // Zero init.
10 namespace ZeroInit {
11 // CHECK-GLOBAL: @_ZN8ZeroInit1aE ={{.*}} global i64 -1
12 int A::* a;
14 // CHECK-GLOBAL: @_ZN8ZeroInit2aaE ={{.*}} global [2 x i64] [i64 -1, i64 -1]
15 int A::* aa[2];
17 // CHECK-GLOBAL: @_ZN8ZeroInit3aaaE ={{.*}} global [2 x [2 x i64]] {{\[}}[2 x i64] [i64 -1, i64 -1], [2 x i64] [i64 -1, i64 -1]]
18 int A::* aaa[2][2];
20 // CHECK-GLOBAL: @_ZN8ZeroInit1bE ={{.*}} global i64 -1,
21 int A::* b = 0;
23 // CHECK-GLOBAL: @_ZN8ZeroInit2saE = internal global %struct.anon { i64 -1 }
24 struct {
25 int A::*a;
26 } sa;
27 void test_sa() { (void) sa; } // force emission
29 // CHECK-GLOBAL: @_ZN8ZeroInit3ssaE = internal
30 // CHECK-GLOBAL: [2 x i64] [i64 -1, i64 -1]
31 struct {
32 int A::*aa[2];
33 } ssa[2];
34 void test_ssa() { (void) ssa; }
36 // CHECK-GLOBAL: @_ZN8ZeroInit2ssE = internal global %struct.anon.1 { %struct.anon.2 { i64 -1 } }
37 struct {
38 struct {
39 int A::*pa;
40 } s;
41 } ss;
42 void test_ss() { (void) ss; }
44 struct A {
45 int A::*a;
46 int b;
49 struct B {
50 A a[10];
51 char c;
52 int B::*b;
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
57 C c;
60 // PR5674
61 namespace PR5674 {
62 // CHECK-GLOBAL: @_ZN6PR56742pbE ={{.*}} global i64 4
63 int A::*pb = &A::b;
66 // Casts.
67 namespace Casts {
69 int A::*pa;
70 int C::*pc;
72 void f() {
73 // CHECK: store i64 -1, ptr @_ZN5Casts2paE
74 pa = 0;
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
81 pc = pa;
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);
93 // Comparisons
94 namespace Comparisons {
95 void f() {
96 int A::*a;
98 // CHECK: icmp ne i64 {{.*}}, -1
99 if (a) { }
101 // CHECK: icmp ne i64 {{.*}}, -1
102 if (a != 0) { }
104 // CHECK: icmp ne i64 -1, {{.*}}
105 if (0 != a) { }
107 // CHECK: icmp eq i64 {{.*}}, -1
108 if (a == 0) { }
110 // CHECK: icmp eq i64 -1, {{.*}}
111 if (0 == a) { }
115 namespace ValueInit {
117 struct A {
118 int A::*a;
120 char c;
122 A();
125 // CHECK-LABEL: define{{.*}} void @_ZN9ValueInit1AC2Ev(ptr {{[^,]*}} %this) unnamed_addr
126 // CHECK: store i64 -1, ptr
127 // CHECK: ret void
128 A::A() : a() {}
132 namespace VirtualBases {
134 struct A {
135 char c;
136 int A::*i;
139 // CHECK-GLOBAL: @_ZN12VirtualBases1bE ={{.*}} global %"struct.VirtualBases::B" { ptr null, %"struct.VirtualBases::A" { i8 0, i64 -1 } }, align 8
140 struct B : virtual A { };
141 B b;
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; };
145 C c;
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; };
149 D d;
153 namespace Test1 {
155 // Don't crash when A contains a bit-field.
156 struct A {
157 int A::* a;
158 int b : 10;
160 A a;
164 namespace BoolPtrToMember {
165 struct X {
166 bool member;
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
173 return x.*member;
177 namespace PR8507 {
179 struct S;
180 void f(S* p, double S::*pm) {
181 if (0 < p->*pm) {
187 namespace test4 {
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
194 D d;
197 namespace PR11487 {
198 union U
200 int U::* mptr;
201 char x[16];
202 } x;
203 // CHECK-GLOBAL: @_ZN7PR114871xE ={{.*}} global %"union.PR11487::U" { i64 -1, [8 x i8] zeroinitializer }, align 8
207 namespace PR13097 {
208 struct X { int x; X(const X&); };
209 struct A {
210 int qq;
211 X x;
213 A f();
214 X g() { return f().*&A::x; }
215 // CHECK-LABEL: define{{.*}} void @_ZN7PR130971gEv
216 // CHECK: call void @_ZN7PR130971fEv
217 // CHECK-NOT: memcpy
218 // CHECK: call void @_ZN7PR130971XC1ERKS0_
221 namespace PR21089 {
222 struct A {
223 bool : 1;
224 int A::*x;
225 bool y;
226 A();
228 struct B : A {
230 B b;
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
234 namespace PR21282 {
235 union U {
236 int U::*x;
237 long y[2];
239 U u;
240 // CHECK-GLOBAL: @_ZN7PR212821uE ={{.*}} global %"union.PR21282::U" { i64 -1, [8 x i8] zeroinitializer }, align 8
243 namespace FlexibleArrayMember {
244 struct S {
245 int S::*x[];
247 S s;
248 // CHECK-GLOBAL: @_ZN19FlexibleArrayMember1sE ={{.*}} global %"struct.FlexibleArrayMember::S" zeroinitializer, align 8
251 namespace IndirectPDM {
252 union U {
253 union {
254 int U::*m;
257 U u;
258 // CHECK-GLOBAL: @_ZN11IndirectPDM1uE ={{.*}} global %"union.IndirectPDM::U" { %union.anon { i64 -1 } }, align 8
261 namespace PR47864 {
262 struct B;
263 struct B {};
264 struct D : B { int m; };
265 auto x = (int B::*)&D::m;