1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -emit-llvm -o - | FileCheck %s 2 3 struct Member { int x; Member(); Member(int); Member(const Member &); }; 4 struct VBase { int x; VBase(); VBase(int); VBase(const VBase &); }; 5 6 struct ValueClass { 7 ValueClass(int x, int y) : x(x), y(y) {} 8 int x; 9 int y; 10 }; // subject to ABI trickery 11 12 13 14 /* Test basic functionality. */ 15 struct A { 16 A(struct Undeclared &); 17 A(ValueClass); 18 Member mem; 19 }; 20 21 A::A(struct Undeclared &ref) : mem(0) {} 22 23 // Check that delegation works. 24 // CHECK-LABEL: define void @_ZN1AC2ER10Undeclared(%struct.A* %this, %struct.Undeclared* nonnull %ref) unnamed_addr 25 // CHECK: call void @_ZN6MemberC1Ei( 26 27 // CHECK-LABEL: define void @_ZN1AC1ER10Undeclared(%struct.A* %this, %struct.Undeclared* nonnull %ref) unnamed_addr 28 // CHECK: call void @_ZN1AC2ER10Undeclared( 29 30 A::A(ValueClass v) : mem(v.y - v.x) {} 31 32 // CHECK-LABEL: define void @_ZN1AC2E10ValueClass(%struct.A* %this, i64 %v.coerce) unnamed_addr 33 // CHECK: call void @_ZN6MemberC1Ei( 34 35 // CHECK-LABEL: define void @_ZN1AC1E10ValueClass(%struct.A* %this, i64 %v.coerce) unnamed_addr 36 // CHECK: call void @_ZN1AC2E10ValueClass( 37 38 /* Test that things work for inheritance. */ 39 struct B : A { 40 B(struct Undeclared &); 41 Member mem; 42 }; 43 44 B::B(struct Undeclared &ref) : A(ref), mem(1) {} 45 46 // CHECK-LABEL: define void @_ZN1BC2ER10Undeclared(%struct.B* %this, %struct.Undeclared* nonnull %ref) unnamed_addr 47 // CHECK: call void @_ZN1AC2ER10Undeclared( 48 // CHECK: call void @_ZN6MemberC1Ei( 49 50 // CHECK-LABEL: define void @_ZN1BC1ER10Undeclared(%struct.B* %this, %struct.Undeclared* nonnull %ref) unnamed_addr 51 // CHECK: call void @_ZN1BC2ER10Undeclared( 52 53 54 /* Test that the delegation optimization is disabled for classes with 55 virtual bases (for now). This is necessary because a vbase 56 initializer could access one of the parameter variables by 57 reference. That's a solvable problem, but let's not solve it right 58 now. */ 59 struct C : virtual A { 60 C(int); 61 Member mem; 62 }; 63 C::C(int x) : A(ValueClass(x, x+1)), mem(x * x) {} 64 65 // CHECK-LABEL: define void @_ZN1CC2Ei(%struct.C* %this, i8** %vtt, i32 %x) unnamed_addr 66 // CHECK: call void @_ZN6MemberC1Ei( 67 68 // CHECK-LABEL: define void @_ZN1CC1Ei(%struct.C* %this, i32 %x) unnamed_addr 69 // CHECK: call void @_ZN10ValueClassC1Eii( 70 // CHECK: call void @_ZN1AC2E10ValueClass( 71 // CHECK: call void @_ZN6MemberC1Ei( 72 73 74 /* Test that the delegation optimization is disabled for varargs 75 constructors. */ 76 struct D : A { 77 D(int, ...); 78 Member mem; 79 }; 80 81 D::D(int x, ...) : A(ValueClass(x, x+1)), mem(x*x) {} 82 83 // CHECK-LABEL: define void @_ZN1DC2Eiz(%struct.D* %this, i32 %x, ...) unnamed_addr 84 // CHECK: call void @_ZN10ValueClassC1Eii( 85 // CHECK: call void @_ZN1AC2E10ValueClass( 86 // CHECK: call void @_ZN6MemberC1Ei( 87 88 // CHECK-LABEL: define void @_ZN1DC1Eiz(%struct.D* %this, i32 %x, ...) unnamed_addr 89 // CHECK: call void @_ZN10ValueClassC1Eii( 90 // CHECK: call void @_ZN1AC2E10ValueClass( 91 // CHECK: call void @_ZN6MemberC1Ei( 92 93 // PR6622: this shouldn't crash 94 namespace test0 { 95 struct A {}; 96 struct B : virtual A { int x; }; 97 struct C : B {}; 98 99 void test(C &in) { 100 C tmp = in; 101 } 102 } 103 104 namespace test1 { 105 struct A { A(); void *ptr; }; 106 struct B { B(); int x; A a[0]; }; 107 B::B() {} 108 // CHECK-LABEL: define void @_ZN5test11BC2Ev( 109 // CHECK: [[THIS:%.*]] = load [[B:%.*]]** 110 // CHECK-NEXT: ret void 111 } 112