anonymous-union-member-initializer.cpp revision 4955e57cd5de1e47be4e2f3e6c733beac166bbd8
1// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s 2 3// 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 17struct A { 18 union { 19 int a; 20 void* b; 21 }; 22 23 A() : a(0) { } 24}; 25 26A a; 27 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} 51 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} 69 70namespace test3 { 71 struct A { 72 union { 73 mutable char fibers[100]; 74 struct { 75 void (*callback)(void*); 76 void *callback_value; 77 }; 78 }; 79 80 A(); 81 }; 82 83 A::A() : callback(0), callback_value(0) {} 84 // CHECK: define void @_ZN5test31AC2Ev( 85 // CHECK: [[THIS:%.*]] = load 86 // CHECK-NEXT: [[UNION:%.*]] = getelementptr inbounds {{.*}} [[THIS]], i32 0, i32 0 87 // CHECK-NEXT: [[STRUCT:%.*]] = bitcast {{.*}}* [[UNION]] to 88 // CHECK-NEXT: [[CALLBACK:%.*]] = getelementptr inbounds {{.*}} [[STRUCT]], i32 0, i32 0 89 // CHECK-NEXT: store void (i8*)* null, void (i8*)** [[CALLBACK]] 90 // CHECK-NEXT: [[UNION:%.*]] = getelementptr inbounds {{.*}} [[THIS]], i32 0, i32 0 91 // CHECK-NEXT: [[STRUCT:%.*]] = bitcast {{.*}}* [[UNION]] to 92 // CHECK-NEXT: [[CVALUE:%.*]] = getelementptr inbounds {{.*}} [[STRUCT]], i32 0, i32 1 93 // CHECK-NEXT: store i8* null, i8** [[CVALUE]] 94} 95 96struct S { 97 // CHECK: store i32 42 98 // CHECK: store i32 55 99 S() : x(42), y(55) {} 100 union { 101 struct { 102 int x; 103 union { int y; }; 104 }; 105 }; 106} s; 107 108 109//PR8760 110template <typename T> struct Foo { 111 Foo() : ptr(__nullptr) {} 112 union { 113 T *ptr; 114 }; 115}; 116Foo<int> f; 117