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 |
Eli Friedman | 9b37274 | 2009-11-27 04:56:40 +0000 | [diff] [blame] | 2 | |
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 | |
| 21 | // CHECK: @_ZN8ZeroInit2saE = global %struct.anon { i64 -1 } |
| 22 | struct { |
| 23 | int A::*a; |
| 24 | } sa; |
| 25 | |
Anders Carlsson | 7e673c4 | 2010-02-05 06:58:06 +0000 | [diff] [blame] | 26 | // CHECK: @_ZN8ZeroInit3ssaE = |
| 27 | // CHECK: [2 x i64] [i64 -1, i64 -1] |
Anders Carlsson | 2c12d03 | 2010-02-02 05:17:25 +0000 | [diff] [blame] | 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; |
Anders Carlsson | a83fb4b | 2010-05-18 16:51:41 +0000 | [diff] [blame^] | 38 | |
| 39 | struct A { |
| 40 | int A::*a; |
| 41 | int b; |
| 42 | }; |
| 43 | |
| 44 | struct B { |
| 45 | A a[10]; |
| 46 | char c; |
| 47 | int B::*b; |
| 48 | }; |
| 49 | |
| 50 | struct C : A, B { int j; }; |
| 51 | // 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 } |
| 52 | C c; |
Anders Carlsson | 45147d0 | 2010-02-02 03:37:46 +0000 | [diff] [blame] | 53 | } |
Anders Carlsson | 63b071f | 2010-02-02 03:32:35 +0000 | [diff] [blame] | 54 | |
Anders Carlsson | 45147d0 | 2010-02-02 03:37:46 +0000 | [diff] [blame] | 55 | // PR5674 |
| 56 | namespace PR5674 { |
| 57 | // CHECK: @_ZN6PR56742pbE = global i64 4 |
| 58 | int A::*pb = &A::b; |
Anders Carlsson | 63b071f | 2010-02-02 03:32:35 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Anders Carlsson | fe40456 | 2010-02-02 03:23:38 +0000 | [diff] [blame] | 61 | // Casts. |
| 62 | namespace Casts { |
| 63 | |
Eli Friedman | 9b37274 | 2009-11-27 04:56:40 +0000 | [diff] [blame] | 64 | int A::*pa; |
| 65 | int C::*pc; |
| 66 | |
| 67 | void f() { |
Anders Carlsson | fe40456 | 2010-02-02 03:23:38 +0000 | [diff] [blame] | 68 | // CHECK: store i64 -1, i64* @_ZN5Casts2paE |
Eli Friedman | 9b37274 | 2009-11-27 04:56:40 +0000 | [diff] [blame] | 69 | pa = 0; |
| 70 | |
| 71 | // CHECK: [[ADJ:%[a-zA-Z0-9\.]+]] = add i64 {{.*}}, 4 |
Anders Carlsson | fe40456 | 2010-02-02 03:23:38 +0000 | [diff] [blame] | 72 | // CHECK: store i64 [[ADJ]], i64* @_ZN5Casts2pcE |
Eli Friedman | 9b37274 | 2009-11-27 04:56:40 +0000 | [diff] [blame] | 73 | pc = pa; |
| 74 | |
| 75 | // CHECK: [[ADJ:%[a-zA-Z0-9\.]+]] = sub i64 {{.*}}, 4 |
Anders Carlsson | fe40456 | 2010-02-02 03:23:38 +0000 | [diff] [blame] | 76 | // CHECK: store i64 [[ADJ]], i64* @_ZN5Casts2paE |
Eli Friedman | 9b37274 | 2009-11-27 04:56:40 +0000 | [diff] [blame] | 77 | pa = static_cast<int A::*>(pc); |
| 78 | } |
Anders Carlsson | fe40456 | 2010-02-02 03:23:38 +0000 | [diff] [blame] | 79 | |
| 80 | } |
Anders Carlsson | 45147d0 | 2010-02-02 03:37:46 +0000 | [diff] [blame] | 81 | |
| 82 | // Comparisons |
| 83 | namespace Comparisons { |
| 84 | void f() { |
| 85 | int A::*a; |
| 86 | |
| 87 | // CHECK: icmp ne i64 {{.*}}, -1 |
| 88 | if (a) { } |
| 89 | |
| 90 | // CHECK: icmp ne i64 {{.*}}, -1 |
| 91 | if (a != 0) { } |
| 92 | |
| 93 | // CHECK: icmp ne i64 -1, {{.*}} |
| 94 | if (0 != a) { } |
| 95 | |
| 96 | // CHECK: icmp eq i64 {{.*}}, -1 |
| 97 | if (a == 0) { } |
| 98 | |
| 99 | // CHECK: icmp eq i64 -1, {{.*}} |
| 100 | if (0 == a) { } |
| 101 | } |
| 102 | } |
Anders Carlsson | 3cb18bc | 2010-05-14 15:05:19 +0000 | [diff] [blame] | 103 | |
| 104 | namespace ValueInit { |
| 105 | |
| 106 | struct A { |
| 107 | int A::*a; |
| 108 | |
| 109 | char c; |
| 110 | |
| 111 | A(); |
| 112 | }; |
| 113 | |
| 114 | // CHECK: define void @_ZN9ValueInit1AC2Ev |
| 115 | // CHECK: store i64 -1, i64* |
| 116 | // CHECK: ret void |
| 117 | A::A() : a() {} |
| 118 | |
| 119 | } |
Anders Carlsson | a83fb4b | 2010-05-18 16:51:41 +0000 | [diff] [blame^] | 120 | |