Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / anonymous-union-member-initializer.cpp
blob827b51bb23cbc834f0b90f4784dc09c1e1d89845
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
3 namespace rdar8818236 {
4 struct S {
5 char c2;
6 union {
7 char c;
8 int i;
9 };
12 // CHECK: @_ZN11rdar88182363fooE ={{.*}} global i64 4
13 char S::*foo = &S::c;
16 struct A {
17 union {
18 int a;
19 void* b;
22 A() : a(0) { }
25 A a;
27 namespace PR7021 {
28 struct X
30 union { long l; };
33 // CHECK-LABEL: define{{.*}} void @_ZN6PR70211fENS_1XES0_
34 void f(X x, X z) {
35 X x1;
37 // CHECK: store i64 1, ptr
38 x1.l = 1;
40 // CHECK: call void @llvm.memcpy.p0.p0.i64
41 X x2(x1);
43 X x3;
44 // CHECK: call void @llvm.memcpy.p0.p0.i64
45 x3 = x1;
47 // CHECK: ret void
51 namespace test2 {
52 struct A {
53 struct {
54 union {
55 int b;
59 A();
62 A::A() : b(10) { }
63 // CHECK-LABEL: define{{.*}} void @_ZN5test21AC2Ev(
64 // CHECK-NOT: }
65 // CHECK: store i32 10
66 // CHECK: }
69 namespace PR10512 {
70 struct A {
71 A();
72 A(int);
73 A(long);
75 struct {
76 struct {int x;};
77 struct {int y;};
81 // CHECK-LABEL: define{{.*}} void @_ZN7PR105121AC2Ev
82 // CHECK: [[THISADDR:%[a-zA-Z0-9.]+]] = alloca ptr
83 // CHECK-NEXT: store ptr [[THIS:%[a-zA-Z0-9.]+]], ptr [[THISADDR]]
84 // CHECK-NEXT: [[THIS1:%[a-zA-Z0-9.]+]] = load ptr, ptr [[THISADDR]]
85 // CHECK-NEXT: ret void
86 A::A() {}
88 // CHECK-LABEL: define{{.*}} void @_ZN7PR105121AC2Ei
89 // CHECK: [[THISADDR:%[a-zA-Z0-9.]+]] = alloca ptr
90 // CHECK-NEXT: [[XADDR:%[a-zA-Z0-9.]+]] = alloca i32
91 // CHECK-NEXT: store ptr [[THIS:%[a-zA-Z0-9.]+]], ptr [[THISADDR]]
92 // CHECK-NEXT: store i32 [[X:%[a-zA-Z0-9.]+]], ptr [[XADDR]]
93 // CHECK-NEXT: [[THIS1:%[a-zA-Z0-9.]+]] = load ptr, ptr [[THISADDR]]
94 // CHECK-NEXT: {{getelementptr inbounds.*i32 0, i32 0}}
95 // CHECK-NEXT: {{getelementptr inbounds.*i32 0, i32 0}}
96 // CHECK-NEXT: {{getelementptr inbounds.*i32 0, i32 0}}
97 // CHECK-NEXT: [[TMP:%[a-zA-Z0-9.]+]] = load i32, ptr [[XADDR]]
98 // CHECK-NEXT: store i32 [[TMP]]
99 // CHECK-NEXT: ret void
100 A::A(int x) : x(x) { }
102 // CHECK-LABEL: define{{.*}} void @_ZN7PR105121AC2El
103 // CHECK: [[THISADDR:%[a-zA-Z0-9.]+]] = alloca ptr
104 // CHECK-NEXT: [[XADDR:%[a-zA-Z0-9.]+]] = alloca i64
105 // CHECK-NEXT: store ptr [[THIS:%[a-zA-Z0-9.]+]], ptr [[THISADDR]]
106 // CHECK-NEXT: store i64 [[X:%[a-zA-Z0-9.]+]], ptr [[XADDR]]
107 // CHECK-NEXT: [[THIS1:%[a-zA-Z0-9.]+]] = load ptr, ptr [[THISADDR]]
108 // CHECK-NEXT: {{getelementptr inbounds.*i32 0, i32 0}}
109 // CHECK-NEXT: {{getelementptr inbounds.*i32 0, i32 1}}
110 // CHECK-NEXT: {{getelementptr inbounds.*i32 0, i32 0}}
111 // CHECK-NEXT: [[TMP:%[a-zA-Z0-9.]+]] = load i64, ptr [[XADDR]]
112 // CHECK-NEXT: [[CONV:%[a-zA-Z0-9.]+]] = trunc i64 [[TMP]] to i32
113 // CHECK-NEXT: store i32 [[CONV]]
114 // CHECK-NEXT: ret void
115 A::A(long y) : y(y) { }
118 namespace test3 {
119 struct A {
120 union {
121 mutable char fibers[100];
122 struct {
123 void (*callback)(void*);
124 void *callback_value;
128 A();
131 A::A() : callback(0), callback_value(0) {}
132 // CHECK-LABEL: define{{.*}} void @_ZN5test31AC2Ev(
133 // CHECK: [[THIS:%.*]] = load
134 // CHECK-NEXT: [[UNION:%.*]] = getelementptr inbounds {{.*}} [[THIS]], i32 0, i32 0
135 // CHECK-NEXT: [[CALLBACK:%.*]] = getelementptr inbounds {{.*}} [[UNION]], i32 0, i32 0
136 // CHECK: store
137 // CHECK-NEXT: [[UNION:%.*]] = getelementptr inbounds {{.*}} [[THIS]], i32 0, i32 0
138 // CHECK-NEXT: [[CVALUE:%.*]] = getelementptr inbounds {{.*}} [[UNION]], i32 0, i32 1
139 // CHECK-NEXT: store ptr null, ptr [[CVALUE]]
142 struct S {
143 // CHECK: store i32 42
144 // CHECK: store i32 55
145 S() : x(42), y(55) {}
146 union {
147 struct {
148 int x;
149 union { int y; };
152 } s;
155 //PR8760
156 template <typename T> struct Foo {
157 Foo() : ptr(__nullptr) {}
158 union {
159 T *ptr;
162 Foo<int> f;
164 namespace PR9683 {
165 struct QueueEntry {
166 union {
167 struct {
168 void* mPtr;
169 union {
170 unsigned mSubmissionTag;
173 unsigned mValue;
175 QueueEntry() {}
177 QueueEntry QE;
180 namespace PR13154 {
181 struct IndirectReferenceField {
182 struct {
183 float &x;
185 IndirectReferenceField(float &x);
187 IndirectReferenceField::IndirectReferenceField(float &xx) : x(xx) {}