blob: 8a8eedf5a66fd41b325fcd500abe6ea9483aeb2b [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 Espindolac5f657f2011-01-11 00:26:26 +000024// CHECK: define unnamed_addr void @_ZN1AC1ER10Undeclared(
John McCallc0bf4622010-02-23 00:48:20 +000025// CHECK: call void @_ZN1AC2ER10Undeclared(
26
Rafael Espindolac5f657f2011-01-11 00:26:26 +000027// CHECK: define unnamed_addr void @_ZN1AC2ER10Undeclared(
John McCallc0bf4622010-02-23 00:48:20 +000028// CHECK: call void @_ZN6MemberC1Ei(
29
30A::A(ValueClass v) : mem(v.y - v.x) {}
31
Rafael Espindolac5f657f2011-01-11 00:26:26 +000032// CHECK: define unnamed_addr void @_ZN1AC1E10ValueClass(
John McCallc0bf4622010-02-23 00:48:20 +000033// CHECK: call void @_ZN1AC2E10ValueClass(
34
Rafael Espindolac5f657f2011-01-11 00:26:26 +000035// CHECK: define unnamed_addr void @_ZN1AC2E10ValueClass(
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 Espindolac5f657f2011-01-11 00:26:26 +000047// CHECK: define unnamed_addr void @_ZN1BC1ER10Undeclared(
John McCallc0bf4622010-02-23 00:48:20 +000048// CHECK: call void @_ZN1BC2ER10Undeclared(
49
Rafael Espindolac5f657f2011-01-11 00:26:26 +000050// CHECK: define unnamed_addr void @_ZN1BC2ER10Undeclared(
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 Espindolac5f657f2011-01-11 00:26:26 +000067// CHECK: define unnamed_addr void @_ZN1CC1Ei(
John McCallc0bf4622010-02-23 00:48:20 +000068// CHECK: call void @_ZN10ValueClassC1Eii(
69// CHECK: call void @_ZN1AC2E10ValueClass(
70// CHECK: call void @_ZN6MemberC1Ei(
71
Rafael Espindolac5f657f2011-01-11 00:26:26 +000072// CHECK: define unnamed_addr void @_ZN1CC2Ei(
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
Rafael Espindolac5f657f2011-01-11 00:26:26 +000086// CHECK: define unnamed_addr void @_ZN1DC1Eiz(
John McCallc0bf4622010-02-23 00:48:20 +000087// CHECK: call void @_ZN10ValueClassC1Eii(
88// CHECK: call void @_ZN1AC2E10ValueClass(
89// CHECK: call void @_ZN6MemberC1Ei(
90
Rafael Espindolac5f657f2011-01-11 00:26:26 +000091// CHECK: define unnamed_addr void @_ZN1DC2Eiz(
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}