Argyrios Kyrtzidis | d4d3ce6 | 2011-01-31 07:04:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s |
Anders Carlsson | c186b8f | 2009-09-02 21:14:47 +0000 | [diff] [blame] | 2 | |
Argyrios Kyrtzidis | 0413db4 | 2011-01-31 07:04:29 +0000 | [diff] [blame] | 3 | // rdar://8818236 |
| 4 | namespace rdar8818236 { |
| 5 | struct S { |
| 6 | char c2; |
| 7 | union { |
| 8 | char c; |
| 9 | int i; |
| 10 | }; |
| 11 | }; |
| 12 | |
| 13 | // CHECK: @_ZN11rdar88182363fooE = global i64 4 |
| 14 | char S::*foo = &S::c; |
| 15 | } |
| 16 | |
Anders Carlsson | c186b8f | 2009-09-02 21:14:47 +0000 | [diff] [blame] | 17 | struct A { |
| 18 | union { |
| 19 | int a; |
| 20 | void* b; |
| 21 | }; |
| 22 | |
| 23 | A() : a(0) { } |
| 24 | }; |
| 25 | |
| 26 | A a; |
Douglas Gregor | fe60f84 | 2010-05-03 15:18:25 +0000 | [diff] [blame] | 27 | |
| 28 | namespace PR7021 { |
| 29 | struct X |
| 30 | { |
| 31 | union { long l; }; |
| 32 | }; |
| 33 | |
| 34 | // CHECK: define void @_ZN6PR70211fENS_1XES0_ |
| 35 | void f(X x, X z) { |
| 36 | X x1; |
| 37 | |
| 38 | // CHECK: store i64 1, i64 |
| 39 | x1.l = 1; |
| 40 | |
| 41 | // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 |
| 42 | X x2(x1); |
| 43 | |
| 44 | X x3; |
| 45 | // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 |
| 46 | x3 = x1; |
| 47 | |
| 48 | // CHECK: ret void |
| 49 | } |
| 50 | } |
John McCall | f1860e5 | 2010-05-20 23:23:51 +0000 | [diff] [blame] | 51 | |
| 52 | namespace test2 { |
| 53 | struct A { |
| 54 | struct { |
| 55 | union { |
| 56 | int b; |
| 57 | }; |
| 58 | }; |
| 59 | |
| 60 | A(); |
| 61 | }; |
| 62 | |
| 63 | A::A() : b(10) { } |
| 64 | // CHECK: define void @_ZN5test21AC2Ev( |
| 65 | // CHECK-NOT: } |
| 66 | // CHECK: store i32 10 |
| 67 | // CHECK: } |
| 68 | } |
John McCall | a9976d3 | 2010-05-21 01:18:57 +0000 | [diff] [blame] | 69 | |
Douglas Gregor | 4dc41c9 | 2011-08-10 15:22:55 +0000 | [diff] [blame] | 70 | namespace PR10512 { |
| 71 | struct A { |
| 72 | A(); |
| 73 | A(int); |
| 74 | A(long); |
| 75 | |
| 76 | struct { |
| 77 | struct {int x;}; |
| 78 | struct {int y;}; |
| 79 | }; |
| 80 | }; |
| 81 | |
| 82 | // CHECK: define void @_ZN7PR105121AC2Ev |
| 83 | // CHECK: [[THISADDR:%[a-zA-z0-9.]+]] = alloca [[A:%"struct[A-Za-z0-9:.]+"]] |
| 84 | // CHECK-NEXT: store [[A]]* [[THIS:%[a-zA-z0-9.]+]], [[A]]** [[THISADDR]] |
| 85 | // CHECK-NEXT: [[THIS1:%[a-zA-z0-9.]+]] = load [[A]]** [[THISADDR]] |
| 86 | // CHECK-NEXT: ret void |
| 87 | A::A() {} |
| 88 | |
| 89 | // CHECK: define void @_ZN7PR105121AC2Ei |
| 90 | // CHECK: [[THISADDR:%[a-zA-z0-9.]+]] = alloca [[A:%"struct[A-Za-z0-9:.]+"]] |
| 91 | // CHECK-NEXT: [[XADDR:%[a-zA-z0-9.]+]] = alloca i32 |
| 92 | // CHECK-NEXT: store [[A]]* [[THIS:%[a-zA-z0-9.]+]], [[A]]** [[THISADDR]] |
| 93 | // CHECK-NEXT: store i32 [[X:%[a-zA-z0-9.]+]], i32* [[XADDR]] |
| 94 | // CHECK-NEXT: [[THIS1:%[a-zA-z0-9.]+]] = load [[A]]** [[THISADDR]] |
| 95 | // CHECK-NEXT: {{getelementptr inbounds.*i32 0, i32 0}} |
| 96 | // CHECK-NEXT: {{getelementptr inbounds.*i32 0, i32 0}} |
| 97 | // CHECK-NEXT: {{getelementptr inbounds.*i32 0, i32 0}} |
| 98 | // CHECK-NEXT: [[TMP:%[a-zA-z0-9.]+]] = load i32* [[XADDR]] |
| 99 | // CHECK-NEXT: store i32 [[TMP]] |
| 100 | // CHECK-NEXT: ret void |
| 101 | A::A(int x) : x(x) { } |
| 102 | |
| 103 | // CHECK: define void @_ZN7PR105121AC2El |
| 104 | // CHECK: [[THISADDR:%[a-zA-z0-9.]+]] = alloca [[A:%"struct[A-Za-z0-9:.]+"]] |
| 105 | // CHECK-NEXT: [[XADDR:%[a-zA-z0-9.]+]] = alloca i64 |
| 106 | // CHECK-NEXT: store [[A]]* [[THIS:%[a-zA-z0-9.]+]], [[A]]** [[THISADDR]] |
| 107 | // CHECK-NEXT: store i64 [[X:%[a-zA-z0-9.]+]], i64* [[XADDR]] |
| 108 | // CHECK-NEXT: [[THIS1:%[a-zA-z0-9.]+]] = load [[A]]** [[THISADDR]] |
| 109 | // CHECK-NEXT: {{getelementptr inbounds.*i32 0, i32 0}} |
| 110 | // CHECK-NEXT: {{getelementptr inbounds.*i32 0, i32 1}} |
| 111 | // CHECK-NEXT: {{getelementptr inbounds.*i32 0, i32 0}} |
| 112 | // CHECK-NEXT: [[TMP:%[a-zA-z0-9.]+]] = load i64* [[XADDR]] |
| 113 | // CHECK-NEXT: [[CONV:%[a-zA-z0-9.]+]] = trunc i64 [[TMP]] to i32 |
| 114 | // CHECK-NEXT: store i32 [[CONV]] |
| 115 | // CHECK-NEXT: ret void |
| 116 | A::A(long y) : y(y) { } |
| 117 | } |
| 118 | |
John McCall | a9976d3 | 2010-05-21 01:18:57 +0000 | [diff] [blame] | 119 | namespace test3 { |
| 120 | struct A { |
| 121 | union { |
| 122 | mutable char fibers[100]; |
| 123 | struct { |
| 124 | void (*callback)(void*); |
| 125 | void *callback_value; |
| 126 | }; |
| 127 | }; |
| 128 | |
| 129 | A(); |
| 130 | }; |
| 131 | |
| 132 | A::A() : callback(0), callback_value(0) {} |
Argyrios Kyrtzidis | d4d3ce6 | 2011-01-31 07:04:24 +0000 | [diff] [blame] | 133 | // CHECK: define void @_ZN5test31AC2Ev( |
John McCall | a9976d3 | 2010-05-21 01:18:57 +0000 | [diff] [blame] | 134 | // CHECK: [[THIS:%.*]] = load |
| 135 | // CHECK-NEXT: [[UNION:%.*]] = getelementptr inbounds {{.*}} [[THIS]], i32 0, i32 0 |
John McCall | bc7fbf0 | 2011-02-26 08:07:02 +0000 | [diff] [blame] | 136 | // CHECK-NEXT: [[STRUCT:%.*]] = bitcast {{.*}}* [[UNION]] to |
John McCall | a9976d3 | 2010-05-21 01:18:57 +0000 | [diff] [blame] | 137 | // CHECK-NEXT: [[CALLBACK:%.*]] = getelementptr inbounds {{.*}} [[STRUCT]], i32 0, i32 0 |
Chris Lattner | 04af8aa | 2011-07-10 14:52:52 +0000 | [diff] [blame] | 138 | // CHECK: store |
John McCall | a9976d3 | 2010-05-21 01:18:57 +0000 | [diff] [blame] | 139 | // CHECK-NEXT: [[UNION:%.*]] = getelementptr inbounds {{.*}} [[THIS]], i32 0, i32 0 |
John McCall | bc7fbf0 | 2011-02-26 08:07:02 +0000 | [diff] [blame] | 140 | // CHECK-NEXT: [[STRUCT:%.*]] = bitcast {{.*}}* [[UNION]] to |
Argyrios Kyrtzidis | d4d3ce6 | 2011-01-31 07:04:24 +0000 | [diff] [blame] | 141 | // CHECK-NEXT: [[CVALUE:%.*]] = getelementptr inbounds {{.*}} [[STRUCT]], i32 0, i32 1 |
| 142 | // CHECK-NEXT: store i8* null, i8** [[CVALUE]] |
John McCall | a9976d3 | 2010-05-21 01:18:57 +0000 | [diff] [blame] | 143 | } |
Argyrios Kyrtzidis | 881b36c | 2010-08-16 17:27:13 +0000 | [diff] [blame] | 144 | |
| 145 | struct S { |
| 146 | // CHECK: store i32 42 |
| 147 | // CHECK: store i32 55 |
| 148 | S() : x(42), y(55) {} |
| 149 | union { |
| 150 | struct { |
| 151 | int x; |
| 152 | union { int y; }; |
| 153 | }; |
| 154 | }; |
| 155 | } s; |
Francois Pichet | 40e1775 | 2010-12-09 10:07:54 +0000 | [diff] [blame] | 156 | |
| 157 | |
John McCall | 4955e57 | 2011-04-12 00:59:32 +0000 | [diff] [blame] | 158 | //PR8760 |
| 159 | template <typename T> struct Foo { |
| 160 | Foo() : ptr(__nullptr) {} |
| 161 | union { |
| 162 | T *ptr; |
| 163 | }; |
| 164 | }; |
| 165 | Foo<int> f; |
Douglas Gregor | e7003b7 | 2011-07-13 02:14:02 +0000 | [diff] [blame] | 166 | |
| 167 | namespace PR9683 { |
| 168 | struct QueueEntry { |
| 169 | union { |
| 170 | struct { |
| 171 | void* mPtr; |
| 172 | union { |
| 173 | unsigned mSubmissionTag; |
| 174 | }; |
| 175 | }; |
| 176 | unsigned mValue; |
| 177 | }; |
| 178 | QueueEntry() {} |
| 179 | }; |
| 180 | QueueEntry QE; |
| 181 | } |