blob: a12ae53f395f7f94f7b6dde406872d3f3136711c [file] [log] [blame]
Argyrios Kyrtzidisd4d3ce62011-01-31 07:04:24 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
Anders Carlssonc186b8f2009-09-02 21:14:47 +00002
Argyrios Kyrtzidis0413db42011-01-31 07:04:29 +00003// rdar://8818236
4namespace rdar8818236 {
5struct S {
6 char c2;
7 union {
8 char c;
9 int i;
10 };
11};
12
13// CHECK: @_ZN11rdar88182363fooE = global i64 4
14char S::*foo = &S::c;
15}
16
Anders Carlssonc186b8f2009-09-02 21:14:47 +000017struct A {
18 union {
19 int a;
20 void* b;
21 };
22
23 A() : a(0) { }
24};
25
26A a;
Douglas Gregorfe60f842010-05-03 15:18:25 +000027
28namespace 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 McCallf1860e52010-05-20 23:23:51 +000051
52namespace 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 McCalla9976d32010-05-21 01:18:57 +000069
Douglas Gregor4dc41c92011-08-10 15:22:55 +000070namespace 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 McCalla9976d32010-05-21 01:18:57 +0000119namespace 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 Kyrtzidisd4d3ce62011-01-31 07:04:24 +0000133 // CHECK: define void @_ZN5test31AC2Ev(
John McCalla9976d32010-05-21 01:18:57 +0000134 // CHECK: [[THIS:%.*]] = load
135 // CHECK-NEXT: [[UNION:%.*]] = getelementptr inbounds {{.*}} [[THIS]], i32 0, i32 0
John McCallbc7fbf02011-02-26 08:07:02 +0000136 // CHECK-NEXT: [[STRUCT:%.*]] = bitcast {{.*}}* [[UNION]] to
John McCalla9976d32010-05-21 01:18:57 +0000137 // CHECK-NEXT: [[CALLBACK:%.*]] = getelementptr inbounds {{.*}} [[STRUCT]], i32 0, i32 0
Chris Lattner04af8aa2011-07-10 14:52:52 +0000138 // CHECK: store
John McCalla9976d32010-05-21 01:18:57 +0000139 // CHECK-NEXT: [[UNION:%.*]] = getelementptr inbounds {{.*}} [[THIS]], i32 0, i32 0
John McCallbc7fbf02011-02-26 08:07:02 +0000140 // CHECK-NEXT: [[STRUCT:%.*]] = bitcast {{.*}}* [[UNION]] to
Argyrios Kyrtzidisd4d3ce62011-01-31 07:04:24 +0000141 // CHECK-NEXT: [[CVALUE:%.*]] = getelementptr inbounds {{.*}} [[STRUCT]], i32 0, i32 1
142 // CHECK-NEXT: store i8* null, i8** [[CVALUE]]
John McCalla9976d32010-05-21 01:18:57 +0000143}
Argyrios Kyrtzidis881b36c2010-08-16 17:27:13 +0000144
145struct 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 Pichet40e17752010-12-09 10:07:54 +0000156
157
John McCall4955e572011-04-12 00:59:32 +0000158//PR8760
159template <typename T> struct Foo {
160 Foo() : ptr(__nullptr) {}
161 union {
162 T *ptr;
163 };
164};
165Foo<int> f;
Douglas Gregore7003b72011-07-13 02:14:02 +0000166
167namespace 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}