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. */ |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 15 | struct A { |
John McCall | c0bf462 | 2010-02-23 00:48:20 +0000 | [diff] [blame] | 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. |
Rafael Espindola | 0691a5c | 2011-01-25 19:10:24 +0000 | [diff] [blame] | 24 | // CHECK: define void @_ZN1AC1ER10Undeclared(%struct.A* %this, %struct.Undeclared* %ref) unnamed_addr |
John McCall | c0bf462 | 2010-02-23 00:48:20 +0000 | [diff] [blame] | 25 | // CHECK: call void @_ZN1AC2ER10Undeclared( |
| 26 | |
Rafael Espindola | 0691a5c | 2011-01-25 19:10:24 +0000 | [diff] [blame] | 27 | // CHECK: define void @_ZN1AC2ER10Undeclared(%struct.A* %this, %struct.Undeclared* %ref) unnamed_addr |
John McCall | c0bf462 | 2010-02-23 00:48:20 +0000 | [diff] [blame] | 28 | // CHECK: call void @_ZN6MemberC1Ei( |
| 29 | |
| 30 | A::A(ValueClass v) : mem(v.y - v.x) {} |
| 31 | |
Rafael Espindola | 0691a5c | 2011-01-25 19:10:24 +0000 | [diff] [blame] | 32 | // CHECK: define void @_ZN1AC1E10ValueClass(%struct.A* %this, i64 %v.coerce) unnamed_addr |
John McCall | c0bf462 | 2010-02-23 00:48:20 +0000 | [diff] [blame] | 33 | // CHECK: call void @_ZN1AC2E10ValueClass( |
| 34 | |
Rafael Espindola | 0691a5c | 2011-01-25 19:10:24 +0000 | [diff] [blame] | 35 | // CHECK: define void @_ZN1AC2E10ValueClass(%struct.A* %this, i64 %v.coerce) unnamed_addr |
John McCall | c0bf462 | 2010-02-23 00:48:20 +0000 | [diff] [blame] | 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 | |
Rafael Espindola | 0691a5c | 2011-01-25 19:10:24 +0000 | [diff] [blame] | 47 | // CHECK: define void @_ZN1BC1ER10Undeclared(%struct.B* %this, %struct.Undeclared* %ref) unnamed_addr |
John McCall | c0bf462 | 2010-02-23 00:48:20 +0000 | [diff] [blame] | 48 | // CHECK: call void @_ZN1BC2ER10Undeclared( |
| 49 | |
Rafael Espindola | 0691a5c | 2011-01-25 19:10:24 +0000 | [diff] [blame] | 50 | // CHECK: define void @_ZN1BC2ER10Undeclared(%struct.B* %this, %struct.Undeclared* %ref) unnamed_addr |
John McCall | c0bf462 | 2010-02-23 00:48:20 +0000 | [diff] [blame] | 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 | |
Rafael Espindola | 0691a5c | 2011-01-25 19:10:24 +0000 | [diff] [blame] | 67 | // CHECK: define void @_ZN1CC1Ei(%struct.C* %this, i32 %x) unnamed_addr |
John McCall | c0bf462 | 2010-02-23 00:48:20 +0000 | [diff] [blame] | 68 | // CHECK: call void @_ZN10ValueClassC1Eii( |
| 69 | // CHECK: call void @_ZN1AC2E10ValueClass( |
| 70 | // CHECK: call void @_ZN6MemberC1Ei( |
| 71 | |
Rafael Espindola | 0691a5c | 2011-01-25 19:10:24 +0000 | [diff] [blame] | 72 | // CHECK: define void @_ZN1CC2Ei(%struct.C* %this, i8** %vtt, i32 %x) unnamed_addr |
John McCall | c0bf462 | 2010-02-23 00:48:20 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 86 | // CHECK: define void @_ZN1DC1Eiz(%struct.D* %this, i32 %x, ...) unnamed_addr |
John McCall | c0bf462 | 2010-02-23 00:48:20 +0000 | [diff] [blame] | 87 | // CHECK: call void @_ZN10ValueClassC1Eii( |
| 88 | // CHECK: call void @_ZN1AC2E10ValueClass( |
| 89 | // CHECK: call void @_ZN6MemberC1Ei( |
| 90 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 91 | // CHECK: define void @_ZN1DC2Eiz(%struct.D* %this, i32 %x, ...) unnamed_addr |
John McCall | c0bf462 | 2010-02-23 00:48:20 +0000 | [diff] [blame] | 92 | // CHECK: call void @_ZN10ValueClassC1Eii( |
| 93 | // CHECK: call void @_ZN1AC2E10ValueClass( |
| 94 | // CHECK: call void @_ZN6MemberC1Ei( |
John McCall | c743571 | 2010-04-30 05:56:45 +0000 | [diff] [blame] | 95 | |
| 96 | |
| 97 | // PR6622: this shouldn't crash |
| 98 | namespace test0 { |
| 99 | struct A {}; |
| 100 | struct B : virtual A { int x; }; |
| 101 | struct C : B {}; |
| 102 | |
| 103 | void test(C &in) { |
| 104 | C tmp = in; |
| 105 | } |
| 106 | } |
John McCall | dd376ca | 2011-07-13 07:37:11 +0000 | [diff] [blame] | 107 | |
| 108 | namespace test1 { |
| 109 | struct A { A(); void *ptr; }; |
| 110 | struct B { B(); int x; A a[0]; }; |
| 111 | B::B() {} |
| 112 | // CHECK: define void @_ZN5test11BC2Ev( |
| 113 | // CHECK: [[THIS:%.*]] = load [[B:%.*]]** |
John McCall | dd376ca | 2011-07-13 07:37:11 +0000 | [diff] [blame] | 114 | // CHECK-NEXT: ret void |
| 115 | } |