pointers-to-data-members.cpp revision 3cb18bcefe39756f3b079fa1a62b4c9cbf6a592f
1// RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-apple-darwin10 | FileCheck %s
2
3struct A { int a; int b; };
4struct B { int b; };
5struct C : B, A { };
6
7// Zero init.
8namespace ZeroInit {
9  // CHECK: @_ZN8ZeroInit1aE = global i64 -1
10  int A::* a;
11
12  // CHECK: @_ZN8ZeroInit2aaE = global [2 x i64] [i64 -1, i64 -1]
13  int A::* aa[2];
14
15  // CHECK: @_ZN8ZeroInit3aaaE = global [2 x [2 x i64]] {{\[}}[2 x i64] [i64 -1, i64 -1], [2 x i64] [i64 -1, i64 -1]]
16  int A::* aaa[2][2];
17
18  // CHECK: @_ZN8ZeroInit1bE = global i64 -1,
19  int A::* b = 0;
20
21  // CHECK: @_ZN8ZeroInit2saE = global %struct.anon { i64 -1 }
22  struct {
23    int A::*a;
24  } sa;
25
26  // CHECK: @_ZN8ZeroInit3ssaE =
27  // CHECK: [2 x i64] [i64 -1, i64 -1]
28  struct {
29    int A::*aa[2];
30  } ssa[2];
31
32  // CHECK: @_ZN8ZeroInit2ssE = global %1 { %struct.anon { i64 -1 } }
33  struct {
34    struct {
35      int A::*pa;
36    } s;
37  } ss;
38}
39
40// PR5674
41namespace PR5674 {
42  // CHECK: @_ZN6PR56742pbE = global i64 4
43  int A::*pb = &A::b;
44}
45
46// Casts.
47namespace Casts {
48
49int A::*pa;
50int C::*pc;
51
52void f() {
53  // CHECK: store i64 -1, i64* @_ZN5Casts2paE
54  pa = 0;
55
56  // CHECK: [[ADJ:%[a-zA-Z0-9\.]+]] = add i64 {{.*}}, 4
57  // CHECK: store i64 [[ADJ]], i64* @_ZN5Casts2pcE
58  pc = pa;
59
60  // CHECK: [[ADJ:%[a-zA-Z0-9\.]+]] = sub i64 {{.*}}, 4
61  // CHECK: store i64 [[ADJ]], i64* @_ZN5Casts2paE
62  pa = static_cast<int A::*>(pc);
63}
64
65}
66
67// Comparisons
68namespace Comparisons {
69  void f() {
70    int A::*a;
71
72    // CHECK: icmp ne i64 {{.*}}, -1
73    if (a) { }
74
75    // CHECK: icmp ne i64 {{.*}}, -1
76    if (a != 0) { }
77
78    // CHECK: icmp ne i64 -1, {{.*}}
79    if (0 != a) { }
80
81    // CHECK: icmp eq i64 {{.*}}, -1
82    if (a == 0) { }
83
84    // CHECK: icmp eq i64 -1, {{.*}}
85    if (0 == a) { }
86  }
87}
88
89namespace ValueInit {
90
91struct A {
92  int A::*a;
93
94  char c;
95
96  A();
97};
98
99// CHECK: define void @_ZN9ValueInit1AC2Ev
100// CHECK: store i64 -1, i64*
101// CHECK: ret void
102A::A() : a() {}
103
104}
105