1*67e74705SXin Li // RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -O3 -o - | FileCheck %s
2*67e74705SXin Li
3*67e74705SXin Li // CHECK: %"struct.rdar20621065::B" = type { float, float }
4*67e74705SXin Li
5*67e74705SXin Li struct Empty { };
6*67e74705SXin Li
7*67e74705SXin Li struct A {
AA8*67e74705SXin Li explicit A(unsigned a = 0xffffffff) : a(a) { }
9*67e74705SXin Li
10*67e74705SXin Li unsigned a;
11*67e74705SXin Li };
12*67e74705SXin Li
13*67e74705SXin Li struct B : A, Empty {
BB14*67e74705SXin Li B() : A(), Empty() { }
15*67e74705SXin Li };
16*67e74705SXin Li
17*67e74705SXin Li struct C : A, Empty {
CC18*67e74705SXin Li C() : A(), Empty() { }
CC19*67e74705SXin Li C(const C& other) : A(0x12345678), Empty(other) { }
20*67e74705SXin Li };
21*67e74705SXin Li
22*67e74705SXin Li struct D : A, Empty {
operator =D23*67e74705SXin Li D& operator=(const D& other) {
24*67e74705SXin Li a = 0x87654321;
25*67e74705SXin Li Empty::operator=(other);
26*67e74705SXin Li
27*67e74705SXin Li return *this;
28*67e74705SXin Li }
29*67e74705SXin Li };
30*67e74705SXin Li
31*67e74705SXin Li #define CHECK(x) if (!(x)) return __LINE__
32*67e74705SXin Li
33*67e74705SXin Li // PR7012
34*67e74705SXin Li // CHECK-LABEL: define i32 @_Z1fv()
f()35*67e74705SXin Li int f() {
36*67e74705SXin Li B b1;
37*67e74705SXin Li
38*67e74705SXin Li // Check that A::a is not overwritten by the Empty default constructor.
39*67e74705SXin Li CHECK(b1.a == 0xffffffff);
40*67e74705SXin Li
41*67e74705SXin Li C c1;
42*67e74705SXin Li C c2(c1);
43*67e74705SXin Li
44*67e74705SXin Li // Check that A::a has the value set in the C::C copy constructor.
45*67e74705SXin Li CHECK(c2.a == 0x12345678);
46*67e74705SXin Li
47*67e74705SXin Li D d1, d2;
48*67e74705SXin Li d2 = d1;
49*67e74705SXin Li
50*67e74705SXin Li // Check that A::as has the value set in the D copy assignment operator.
51*67e74705SXin Li CHECK(d2.a == 0x87654321);
52*67e74705SXin Li
53*67e74705SXin Li // Success!
54*67e74705SXin Li // CHECK: ret i32 0
55*67e74705SXin Li return 0;
56*67e74705SXin Li }
57*67e74705SXin Li
58*67e74705SXin Li namespace PR8796 {
59*67e74705SXin Li struct FreeCell {
60*67e74705SXin Li };
61*67e74705SXin Li union ThingOrCell {
62*67e74705SXin Li FreeCell t;
63*67e74705SXin Li FreeCell cell;
64*67e74705SXin Li };
65*67e74705SXin Li struct Things {
66*67e74705SXin Li ThingOrCell things;
67*67e74705SXin Li };
68*67e74705SXin Li Things x;
69*67e74705SXin Li }
70*67e74705SXin Li
71*67e74705SXin Li #ifdef HARNESS
72*67e74705SXin Li extern "C" void printf(const char *, ...);
73*67e74705SXin Li
main()74*67e74705SXin Li int main() {
75*67e74705SXin Li int result = f();
76*67e74705SXin Li
77*67e74705SXin Li if (result == 0)
78*67e74705SXin Li printf("success!\n");
79*67e74705SXin Li else
80*67e74705SXin Li printf("test on line %d failed!\n", result);
81*67e74705SXin Li
82*67e74705SXin Li return result;
83*67e74705SXin Li }
84*67e74705SXin Li #endif
85*67e74705SXin Li
86*67e74705SXin Li namespace rdar20621065 {
87*67e74705SXin Li struct A {
88*67e74705SXin Li float array[0];
89*67e74705SXin Li };
90*67e74705SXin Li
91*67e74705SXin Li struct B : A {
92*67e74705SXin Li float left;
93*67e74705SXin Li float right;
94*67e74705SXin Li };
95*67e74705SXin Li
96*67e74705SXin Li // Type checked at the top of the file.
97*67e74705SXin Li B b;
98*67e74705SXin Li };
99