blob: 9e2da31f046aff0b90d560a225556bcfc092e4f7 [file] [log] [blame]
John McCallc0bf4622010-02-23 00:48:20 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -emit-llvm -o - | FileCheck %s
2
3struct Member { int x; Member(); Member(int); Member(const Member &); };
4struct VBase { int x; VBase(); VBase(int); VBase(const VBase &); };
5
6struct 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 McCall7002f4c2010-04-09 19:03:51 +000015struct A {
John McCallc0bf4622010-02-23 00:48:20 +000016 A(struct Undeclared &);
17 A(ValueClass);
18 Member mem;
19};
20
21A::A(struct Undeclared &ref) : mem(0) {}
22
23// Check that delegation works.
Rafael Espindola0691a5c2011-01-25 19:10:24 +000024// CHECK: define void @_ZN1AC1ER10Undeclared(%struct.A* %this, %struct.Undeclared* %ref) unnamed_addr
John McCallc0bf4622010-02-23 00:48:20 +000025// CHECK: call void @_ZN1AC2ER10Undeclared(
26
Rafael Espindola0691a5c2011-01-25 19:10:24 +000027// CHECK: define void @_ZN1AC2ER10Undeclared(%struct.A* %this, %struct.Undeclared* %ref) unnamed_addr
John McCallc0bf4622010-02-23 00:48:20 +000028// CHECK: call void @_ZN6MemberC1Ei(
29
30A::A(ValueClass v) : mem(v.y - v.x) {}
31
Rafael Espindola0691a5c2011-01-25 19:10:24 +000032// CHECK: define void @_ZN1AC1E10ValueClass(%struct.A* %this, i64 %v.coerce) unnamed_addr
John McCallc0bf4622010-02-23 00:48:20 +000033// CHECK: call void @_ZN1AC2E10ValueClass(
34
Rafael Espindola0691a5c2011-01-25 19:10:24 +000035// CHECK: define void @_ZN1AC2E10ValueClass(%struct.A* %this, i64 %v.coerce) unnamed_addr
John McCallc0bf4622010-02-23 00:48:20 +000036// CHECK: call void @_ZN6MemberC1Ei(
37
38
39/* Test that things work for inheritance. */
40struct B : A {
41 B(struct Undeclared &);
42 Member mem;
43};
44
45B::B(struct Undeclared &ref) : A(ref), mem(1) {}
46
Rafael Espindola0691a5c2011-01-25 19:10:24 +000047// CHECK: define void @_ZN1BC1ER10Undeclared(%struct.B* %this, %struct.Undeclared* %ref) unnamed_addr
John McCallc0bf4622010-02-23 00:48:20 +000048// CHECK: call void @_ZN1BC2ER10Undeclared(
49
Rafael Espindola0691a5c2011-01-25 19:10:24 +000050// CHECK: define void @_ZN1BC2ER10Undeclared(%struct.B* %this, %struct.Undeclared* %ref) unnamed_addr
John McCallc0bf4622010-02-23 00:48:20 +000051// 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. */
61struct C : virtual A {
62 C(int);
63 Member mem;
64};
65C::C(int x) : A(ValueClass(x, x+1)), mem(x * x) {}
66
Rafael Espindola0691a5c2011-01-25 19:10:24 +000067// CHECK: define void @_ZN1CC1Ei(%struct.C* %this, i32 %x) unnamed_addr
John McCallc0bf4622010-02-23 00:48:20 +000068// CHECK: call void @_ZN10ValueClassC1Eii(
69// CHECK: call void @_ZN1AC2E10ValueClass(
70// CHECK: call void @_ZN6MemberC1Ei(
71
Rafael Espindola0691a5c2011-01-25 19:10:24 +000072// CHECK: define void @_ZN1CC2Ei(%struct.C* %this, i8** %vtt, i32 %x) unnamed_addr
John McCallc0bf4622010-02-23 00:48:20 +000073// CHECK: call void @_ZN6MemberC1Ei(
74
75
76
77/* Test that the delegation optimization is disabled for varargs
78 constructors. */
79struct D : A {
80 D(int, ...);
81 Member mem;
82};
83
84D::D(int x, ...) : A(ValueClass(x, x+1)), mem(x*x) {}
85
Chris Lattner9cbe4f02011-07-09 17:41:47 +000086// CHECK: define void @_ZN1DC1Eiz(%struct.D* %this, i32 %x, ...) unnamed_addr
John McCallc0bf4622010-02-23 00:48:20 +000087// CHECK: call void @_ZN10ValueClassC1Eii(
88// CHECK: call void @_ZN1AC2E10ValueClass(
89// CHECK: call void @_ZN6MemberC1Ei(
90
Chris Lattner9cbe4f02011-07-09 17:41:47 +000091// CHECK: define void @_ZN1DC2Eiz(%struct.D* %this, i32 %x, ...) unnamed_addr
John McCallc0bf4622010-02-23 00:48:20 +000092// CHECK: call void @_ZN10ValueClassC1Eii(
93// CHECK: call void @_ZN1AC2E10ValueClass(
94// CHECK: call void @_ZN6MemberC1Ei(
John McCallc7435712010-04-30 05:56:45 +000095
96
97// PR6622: this shouldn't crash
98namespace 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 McCalldd376ca2011-07-13 07:37:11 +0000107
108namespace 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 McCalldd376ca2011-07-13 07:37:11 +0000114 // CHECK-NEXT: ret void
115}