Anders Carlsson | fe40456 | 2010-02-02 03:23:38 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-apple-darwin10 | FileCheck %s |
Anders Carlsson | 1884eb0 | 2010-05-22 17:35:42 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-apple-darwin10 -O3 | FileCheck --check-prefix=CHECK-O3 %s |
Anders Carlsson | 45147d0 | 2010-02-02 03:37:46 +0000 | [diff] [blame] | 3 | struct A { int a; int b; }; |
Eli Friedman | 9b37274 | 2009-11-27 04:56:40 +0000 | [diff] [blame] | 4 | struct B { int b; }; |
| 5 | struct C : B, A { }; |
| 6 | |
Anders Carlsson | 63b071f | 2010-02-02 03:32:35 +0000 | [diff] [blame] | 7 | // Zero init. |
| 8 | namespace 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; |
Anders Carlsson | 2c12d03 | 2010-02-02 05:17:25 +0000 | [diff] [blame] | 20 | |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 21 | // CHECK: @_ZN8ZeroInit2saE = internal global %struct.anon { i64 -1 } |
Anders Carlsson | 2c12d03 | 2010-02-02 05:17:25 +0000 | [diff] [blame] | 22 | struct { |
| 23 | int A::*a; |
| 24 | } sa; |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 25 | void test_sa() { (void) sa; } // force emission |
Anders Carlsson | 2c12d03 | 2010-02-02 05:17:25 +0000 | [diff] [blame] | 26 | |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 27 | // CHECK: @_ZN8ZeroInit3ssaE = internal |
Anders Carlsson | 7e673c4 | 2010-02-05 06:58:06 +0000 | [diff] [blame] | 28 | // CHECK: [2 x i64] [i64 -1, i64 -1] |
Anders Carlsson | 2c12d03 | 2010-02-02 05:17:25 +0000 | [diff] [blame] | 29 | struct { |
| 30 | int A::*aa[2]; |
| 31 | } ssa[2]; |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 32 | void test_ssa() { (void) ssa; } |
Anders Carlsson | 2c12d03 | 2010-02-02 05:17:25 +0000 | [diff] [blame] | 33 | |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 34 | // CHECK: @_ZN8ZeroInit2ssE = internal global %1 { %struct.anon { i64 -1 } } |
Anders Carlsson | 2c12d03 | 2010-02-02 05:17:25 +0000 | [diff] [blame] | 35 | struct { |
| 36 | struct { |
| 37 | int A::*pa; |
| 38 | } s; |
| 39 | } ss; |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 40 | void test_ss() { (void) ss; } |
Anders Carlsson | a83fb4b | 2010-05-18 16:51:41 +0000 | [diff] [blame] | 41 | |
| 42 | struct A { |
| 43 | int A::*a; |
| 44 | int b; |
| 45 | }; |
| 46 | |
| 47 | struct B { |
| 48 | A a[10]; |
| 49 | char c; |
| 50 | int B::*b; |
| 51 | }; |
| 52 | |
| 53 | struct C : A, B { int j; }; |
| 54 | // CHECK: @_ZN8ZeroInit1cE = global %"struct.ZeroInit::C" { [16 x i8] c"\FF\FF\FF\FF\FF\FF\FF\FF\00\00\00\00\00\00\00\00", [176 x i8] c"\FF\FF\FF\FF\FF\FF\FF\FF\00\00\00\00\00\00\00\00\FF\FF\FF\FF\FF\FF\FF\FF\00\00\00\00\00\00\00\00\FF\FF\FF\FF\FF\FF\FF\FF\00\00\00\00\00\00\00\00\FF\FF\FF\FF\FF\FF\FF\FF\00\00\00\00\00\00\00\00\FF\FF\FF\FF\FF\FF\FF\FF\00\00\00\00\00\00\00\00\FF\FF\FF\FF\FF\FF\FF\FF\00\00\00\00\00\00\00\00\FF\FF\FF\FF\FF\FF\FF\FF\00\00\00\00\00\00\00\00\FF\FF\FF\FF\FF\FF\FF\FF\00\00\00\00\00\00\00\00\FF\FF\FF\FF\FF\FF\FF\FF\00\00\00\00\00\00\00\00\FF\FF\FF\FF\FF\FF\FF\FF\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\FF\FF\FF\FF\FF\FF\FF\FF", i32 0, [4 x i8] zeroinitializer } |
| 55 | C c; |
Anders Carlsson | 45147d0 | 2010-02-02 03:37:46 +0000 | [diff] [blame] | 56 | } |
Anders Carlsson | 63b071f | 2010-02-02 03:32:35 +0000 | [diff] [blame] | 57 | |
Anders Carlsson | 45147d0 | 2010-02-02 03:37:46 +0000 | [diff] [blame] | 58 | // PR5674 |
| 59 | namespace PR5674 { |
| 60 | // CHECK: @_ZN6PR56742pbE = global i64 4 |
| 61 | int A::*pb = &A::b; |
Anders Carlsson | 63b071f | 2010-02-02 03:32:35 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Anders Carlsson | fe40456 | 2010-02-02 03:23:38 +0000 | [diff] [blame] | 64 | // Casts. |
| 65 | namespace Casts { |
| 66 | |
Eli Friedman | 9b37274 | 2009-11-27 04:56:40 +0000 | [diff] [blame] | 67 | int A::*pa; |
| 68 | int C::*pc; |
| 69 | |
| 70 | void f() { |
John McCall | 0bab0cd | 2010-08-23 01:21:21 +0000 | [diff] [blame] | 71 | // CHECK: store i64 -1, i64* @_ZN5Casts2paE |
Eli Friedman | 9b37274 | 2009-11-27 04:56:40 +0000 | [diff] [blame] | 72 | pa = 0; |
| 73 | |
John McCall | 0bab0cd | 2010-08-23 01:21:21 +0000 | [diff] [blame] | 74 | // CHECK-NEXT: [[TMP:%.*]] = load i64* @_ZN5Casts2paE, align 8 |
| 75 | // CHECK-NEXT: [[ADJ:%.*]] = add nsw i64 [[TMP]], 4 |
| 76 | // CHECK-NEXT: [[ISNULL:%.*]] = icmp eq i64 [[TMP]], -1 |
| 77 | // CHECK-NEXT: [[RES:%.*]] = select i1 [[ISNULL]], i64 [[TMP]], i64 [[ADJ]] |
| 78 | // CHECK-NEXT: store i64 [[RES]], i64* @_ZN5Casts2pcE |
Eli Friedman | 9b37274 | 2009-11-27 04:56:40 +0000 | [diff] [blame] | 79 | pc = pa; |
| 80 | |
John McCall | 0bab0cd | 2010-08-23 01:21:21 +0000 | [diff] [blame] | 81 | // CHECK-NEXT: [[TMP:%.*]] = load i64* @_ZN5Casts2pcE, align 8 |
| 82 | // CHECK-NEXT: [[ADJ:%.*]] = sub nsw i64 [[TMP]], 4 |
| 83 | // CHECK-NEXT: [[ISNULL:%.*]] = icmp eq i64 [[TMP]], -1 |
| 84 | // CHECK-NEXT: [[RES:%.*]] = select i1 [[ISNULL]], i64 [[TMP]], i64 [[ADJ]] |
| 85 | // CHECK-NEXT: store i64 [[RES]], i64* @_ZN5Casts2paE |
Eli Friedman | 9b37274 | 2009-11-27 04:56:40 +0000 | [diff] [blame] | 86 | pa = static_cast<int A::*>(pc); |
| 87 | } |
Anders Carlsson | fe40456 | 2010-02-02 03:23:38 +0000 | [diff] [blame] | 88 | |
| 89 | } |
Anders Carlsson | 45147d0 | 2010-02-02 03:37:46 +0000 | [diff] [blame] | 90 | |
| 91 | // Comparisons |
| 92 | namespace Comparisons { |
| 93 | void f() { |
| 94 | int A::*a; |
| 95 | |
| 96 | // CHECK: icmp ne i64 {{.*}}, -1 |
| 97 | if (a) { } |
| 98 | |
| 99 | // CHECK: icmp ne i64 {{.*}}, -1 |
| 100 | if (a != 0) { } |
| 101 | |
| 102 | // CHECK: icmp ne i64 -1, {{.*}} |
| 103 | if (0 != a) { } |
| 104 | |
| 105 | // CHECK: icmp eq i64 {{.*}}, -1 |
| 106 | if (a == 0) { } |
| 107 | |
| 108 | // CHECK: icmp eq i64 -1, {{.*}} |
| 109 | if (0 == a) { } |
| 110 | } |
| 111 | } |
Anders Carlsson | 3cb18bc | 2010-05-14 15:05:19 +0000 | [diff] [blame] | 112 | |
| 113 | namespace ValueInit { |
| 114 | |
| 115 | struct A { |
| 116 | int A::*a; |
| 117 | |
| 118 | char c; |
| 119 | |
| 120 | A(); |
| 121 | }; |
| 122 | |
Rafael Espindola | c5f657f | 2011-01-11 00:26:26 +0000 | [diff] [blame] | 123 | // CHECK: define unnamed_addr void @_ZN9ValueInit1AC2Ev |
Anders Carlsson | 3cb18bc | 2010-05-14 15:05:19 +0000 | [diff] [blame] | 124 | // CHECK: store i64 -1, i64* |
| 125 | // CHECK: ret void |
| 126 | A::A() : a() {} |
| 127 | |
| 128 | } |
Anders Carlsson | a83fb4b | 2010-05-18 16:51:41 +0000 | [diff] [blame] | 129 | |
Anders Carlsson | 1884eb0 | 2010-05-22 17:35:42 +0000 | [diff] [blame] | 130 | namespace PR7139 { |
| 131 | |
| 132 | struct pair { |
| 133 | int first; |
| 134 | int second; |
| 135 | }; |
| 136 | |
| 137 | typedef int pair::*ptr_to_member_type; |
| 138 | |
| 139 | struct ptr_to_member_struct { |
| 140 | ptr_to_member_type data; |
| 141 | int i; |
| 142 | }; |
| 143 | |
| 144 | struct A { |
| 145 | ptr_to_member_struct a; |
| 146 | |
| 147 | A() : a() {} |
| 148 | }; |
| 149 | |
| 150 | // CHECK-O3: define zeroext i1 @_ZN6PR71395checkEv() nounwind readnone |
| 151 | bool check() { |
| 152 | // CHECK-O3: ret i1 true |
| 153 | return A().a.data == 0; |
| 154 | } |
| 155 | |
Anders Carlsson | a40a9f3 | 2010-05-22 17:45:10 +0000 | [diff] [blame] | 156 | // CHECK-O3: define zeroext i1 @_ZN6PR71396check2Ev() nounwind readnone |
| 157 | bool check2() { |
| 158 | // CHECK-O3: ret i1 true |
| 159 | return ptr_to_member_type() == 0; |
| 160 | } |
| 161 | |
Anders Carlsson | 1884eb0 | 2010-05-22 17:35:42 +0000 | [diff] [blame] | 162 | } |
Anders Carlsson | 0a87b37 | 2010-05-27 18:51:01 +0000 | [diff] [blame] | 163 | |
| 164 | namespace VirtualBases { |
| 165 | |
| 166 | struct A { |
| 167 | char c; |
| 168 | int A::*i; |
| 169 | }; |
| 170 | |
| 171 | // FIXME: A::i should be initialized to -1 here. |
| 172 | struct B : virtual A { }; |
| 173 | B b; |
| 174 | |
| 175 | // FIXME: A::i should be initialized to -1 here. |
| 176 | struct C : virtual A { int A::*i; }; |
| 177 | C c; |
| 178 | |
| 179 | // FIXME: C::A::i should be initialized to -1 here. |
| 180 | struct D : C { int A::*i; }; |
| 181 | D d; |
| 182 | |
| 183 | } |
Anders Carlsson | e9a05b7 | 2010-06-03 15:36:07 +0000 | [diff] [blame] | 184 | |
| 185 | namespace Test1 { |
| 186 | |
| 187 | // Don't crash when A contains a bit-field. |
| 188 | struct A { |
| 189 | int A::* a; |
| 190 | int b : 10; |
| 191 | }; |
| 192 | A a; |
| 193 | |
| 194 | } |
Douglas Gregor | b61e2a3 | 2010-09-02 15:00:29 +0000 | [diff] [blame] | 195 | |
| 196 | namespace BoolPtrToMember { |
| 197 | struct X { |
| 198 | bool member; |
| 199 | }; |
| 200 | |
| 201 | // CHECK: define i8* @_ZN15BoolPtrToMember1fERNS_1XEMS0_b |
| 202 | bool &f(X &x, bool X::*member) { |
| 203 | // CHECK: {{bitcast.* to i8\*}} |
| 204 | // CHECK-NEXT: getelementptr inbounds i8* |
| 205 | // CHECK-NEXT: ret i8* |
| 206 | return x.*member; |
| 207 | } |
| 208 | } |
Anders Carlsson | 96e9366 | 2010-10-31 01:21:47 +0000 | [diff] [blame] | 209 | |
| 210 | namespace PR8507 { |
| 211 | |
| 212 | struct S; |
| 213 | void f(S* p, double S::*pm) { |
| 214 | if (0 < p->*pm) { |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | } |
| 219 | |