John McCall | c0bf462 | 2010-02-23 00:48:20 +0000 | [diff] [blame^] | 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 | class 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: define void @_ZN1AC1ER10Undeclared( |
| 25 | // CHECK: call void @_ZN1AC2ER10Undeclared( |
| 26 | |
| 27 | // CHECK: define void @_ZN1AC2ER10Undeclared( |
| 28 | // CHECK: call void @_ZN6MemberC1Ei( |
| 29 | |
| 30 | A::A(ValueClass v) : mem(v.y - v.x) {} |
| 31 | |
| 32 | // CHECK: define void @_ZN1AC1E10ValueClass( |
| 33 | // CHECK: call void @_ZN1AC2E10ValueClass( |
| 34 | |
| 35 | // CHECK: define void @_ZN1AC2E10ValueClass( |
| 36 | // CHECK: call void @_ZN6MemberC1Ei( |
| 37 | |
| 38 | |
| 39 | /* Test that things work for inheritance. */ |
| 40 | struct B : A { |
| 41 | B(struct Undeclared &); |
| 42 | Member mem; |
| 43 | }; |
| 44 | |
| 45 | B::B(struct Undeclared &ref) : A(ref), mem(1) {} |
| 46 | |
| 47 | // CHECK: define void @_ZN1BC1ER10Undeclared( |
| 48 | // CHECK: call void @_ZN1BC2ER10Undeclared( |
| 49 | |
| 50 | // CHECK: define void @_ZN1BC2ER10Undeclared( |
| 51 | // CHECK: call void @_ZN1AC2ER10Undeclared( |
| 52 | // CHECK: call void @_ZN6MemberC1Ei( |
| 53 | |
| 54 | |
| 55 | |
| 56 | /* Test that the delegation optimization is disabled for classes with |
| 57 | virtual bases (for now). This is necessary because a vbase |
| 58 | initializer could access one of the parameter variables by |
| 59 | reference. That's a solvable problem, but let's not solve it right |
| 60 | now. */ |
| 61 | struct C : virtual A { |
| 62 | C(int); |
| 63 | Member mem; |
| 64 | }; |
| 65 | C::C(int x) : A(ValueClass(x, x+1)), mem(x * x) {} |
| 66 | |
| 67 | // CHECK: define void @_ZN1CC1Ei( |
| 68 | // CHECK: call void @_ZN10ValueClassC1Eii( |
| 69 | // CHECK: call void @_ZN1AC2E10ValueClass( |
| 70 | // CHECK: call void @_ZN6MemberC1Ei( |
| 71 | |
| 72 | // CHECK: define void @_ZN1CC2Ei( |
| 73 | // CHECK: call void @_ZN6MemberC1Ei( |
| 74 | |
| 75 | |
| 76 | |
| 77 | /* Test that the delegation optimization is disabled for varargs |
| 78 | constructors. */ |
| 79 | struct D : A { |
| 80 | D(int, ...); |
| 81 | Member mem; |
| 82 | }; |
| 83 | |
| 84 | D::D(int x, ...) : A(ValueClass(x, x+1)), mem(x*x) {} |
| 85 | |
| 86 | // CHECK: define void @_ZN1DC1Eiz( |
| 87 | // CHECK: call void @_ZN10ValueClassC1Eii( |
| 88 | // CHECK: call void @_ZN1AC2E10ValueClass( |
| 89 | // CHECK: call void @_ZN6MemberC1Ei( |
| 90 | |
| 91 | // CHECK: define void @_ZN1DC2Eiz( |
| 92 | // CHECK: call void @_ZN10ValueClassC1Eii( |
| 93 | // CHECK: call void @_ZN1AC2E10ValueClass( |
| 94 | // CHECK: call void @_ZN6MemberC1Ei( |