1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -O3 -o - | FileCheck %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc struct Empty { }; 4*f4a2713aSLionel Sambuc 5*f4a2713aSLionel Sambuc struct A { AA6*f4a2713aSLionel Sambuc explicit A(unsigned a = 0xffffffff) : a(a) { } 7*f4a2713aSLionel Sambuc 8*f4a2713aSLionel Sambuc unsigned a; 9*f4a2713aSLionel Sambuc }; 10*f4a2713aSLionel Sambuc 11*f4a2713aSLionel Sambuc struct B : A, Empty { BB12*f4a2713aSLionel Sambuc B() : A(), Empty() { } 13*f4a2713aSLionel Sambuc }; 14*f4a2713aSLionel Sambuc 15*f4a2713aSLionel Sambuc struct C : A, Empty { CC16*f4a2713aSLionel Sambuc C() : A(), Empty() { } CC17*f4a2713aSLionel Sambuc C(const C& other) : A(0x12345678), Empty(other) { } 18*f4a2713aSLionel Sambuc }; 19*f4a2713aSLionel Sambuc 20*f4a2713aSLionel Sambuc struct D : A, Empty { operator =D21*f4a2713aSLionel Sambuc D& operator=(const D& other) { 22*f4a2713aSLionel Sambuc a = 0x87654321; 23*f4a2713aSLionel Sambuc Empty::operator=(other); 24*f4a2713aSLionel Sambuc 25*f4a2713aSLionel Sambuc return *this; 26*f4a2713aSLionel Sambuc } 27*f4a2713aSLionel Sambuc }; 28*f4a2713aSLionel Sambuc 29*f4a2713aSLionel Sambuc #define CHECK(x) if (!(x)) return __LINE__ 30*f4a2713aSLionel Sambuc 31*f4a2713aSLionel Sambuc // PR7012 32*f4a2713aSLionel Sambuc // CHECK-LABEL: define i32 @_Z1fv() f()33*f4a2713aSLionel Sambucint f() { 34*f4a2713aSLionel Sambuc B b1; 35*f4a2713aSLionel Sambuc 36*f4a2713aSLionel Sambuc // Check that A::a is not overwritten by the Empty default constructor. 37*f4a2713aSLionel Sambuc CHECK(b1.a == 0xffffffff); 38*f4a2713aSLionel Sambuc 39*f4a2713aSLionel Sambuc C c1; 40*f4a2713aSLionel Sambuc C c2(c1); 41*f4a2713aSLionel Sambuc 42*f4a2713aSLionel Sambuc // Check that A::a has the value set in the C::C copy constructor. 43*f4a2713aSLionel Sambuc CHECK(c2.a == 0x12345678); 44*f4a2713aSLionel Sambuc 45*f4a2713aSLionel Sambuc D d1, d2; 46*f4a2713aSLionel Sambuc d2 = d1; 47*f4a2713aSLionel Sambuc 48*f4a2713aSLionel Sambuc // Check that A::as has the value set in the D copy assignment operator. 49*f4a2713aSLionel Sambuc CHECK(d2.a == 0x87654321); 50*f4a2713aSLionel Sambuc 51*f4a2713aSLionel Sambuc // Success! 52*f4a2713aSLionel Sambuc // CHECK: ret i32 0 53*f4a2713aSLionel Sambuc return 0; 54*f4a2713aSLionel Sambuc } 55*f4a2713aSLionel Sambuc 56*f4a2713aSLionel Sambuc namespace PR8796 { 57*f4a2713aSLionel Sambuc struct FreeCell { 58*f4a2713aSLionel Sambuc }; 59*f4a2713aSLionel Sambuc union ThingOrCell { 60*f4a2713aSLionel Sambuc FreeCell t; 61*f4a2713aSLionel Sambuc FreeCell cell; 62*f4a2713aSLionel Sambuc }; 63*f4a2713aSLionel Sambuc struct Things { 64*f4a2713aSLionel Sambuc ThingOrCell things; 65*f4a2713aSLionel Sambuc }; 66*f4a2713aSLionel Sambuc Things x; 67*f4a2713aSLionel Sambuc } 68*f4a2713aSLionel Sambuc 69*f4a2713aSLionel Sambuc #ifdef HARNESS 70*f4a2713aSLionel Sambuc extern "C" void printf(const char *, ...); 71*f4a2713aSLionel Sambuc main()72*f4a2713aSLionel Sambucint main() { 73*f4a2713aSLionel Sambuc int result = f(); 74*f4a2713aSLionel Sambuc 75*f4a2713aSLionel Sambuc if (result == 0) 76*f4a2713aSLionel Sambuc printf("success!\n"); 77*f4a2713aSLionel Sambuc else 78*f4a2713aSLionel Sambuc printf("test on line %d failed!\n", result); 79*f4a2713aSLionel Sambuc 80*f4a2713aSLionel Sambuc return result; 81*f4a2713aSLionel Sambuc } 82*f4a2713aSLionel Sambuc #endif 83