Home | History | Annotate | Download | only in CodeGenCXX
      1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
      2 
      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 
     17 struct A {
     18   union {
     19     int a;
     20     void* b;
     21   };
     22 
     23   A() : a(0) { }
     24 };
     25 
     26 A a;
     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 }
     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 }
     69 
     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 
    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) {}
    133   // CHECK: define void @_ZN5test31AC2Ev(
    134   // CHECK: [[THIS:%.*]] = load
    135   // CHECK-NEXT: [[UNION:%.*]] = getelementptr inbounds {{.*}} [[THIS]], i32 0, i32 0
    136   // CHECK-NEXT: [[STRUCT:%.*]] = bitcast {{.*}}* [[UNION]] to
    137   // CHECK-NEXT: [[CALLBACK:%.*]] = getelementptr inbounds {{.*}} [[STRUCT]], i32 0, i32 0
    138   // CHECK: store
    139   // CHECK-NEXT: [[UNION:%.*]] = getelementptr inbounds {{.*}} [[THIS]], i32 0, i32 0
    140   // CHECK-NEXT: [[STRUCT:%.*]] = bitcast {{.*}}* [[UNION]] to
    141   // CHECK-NEXT: [[CVALUE:%.*]] = getelementptr inbounds {{.*}} [[STRUCT]], i32 0, i32 1
    142   // CHECK-NEXT: store i8* null, i8** [[CVALUE]]
    143 }
    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;
    156 
    157 
    158 //PR8760
    159 template <typename T> struct Foo {
    160   Foo() : ptr(__nullptr) {}
    161   union {
    162     T *ptr;
    163   };
    164 };
    165 Foo<int> f;
    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 }
    182 
    183 namespace PR13154 {
    184   struct IndirectReferenceField {
    185       struct {
    186           float &x;
    187       };
    188       IndirectReferenceField(float &x);
    189   };
    190   IndirectReferenceField::IndirectReferenceField(float &xx) : x(xx) {}
    191 }
    192