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