aboutsummaryrefslogtreecommitdiff
path: root/test/CodeGenCXX/constructors.cpp
blob: 2c95c91e11140dab32dd337cf843678e69a13d2f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -emit-llvm -o - | FileCheck %s

struct Member { int x; Member(); Member(int); Member(const Member &); };
struct VBase { int x; VBase(); VBase(int); VBase(const VBase &); };

struct ValueClass {
  ValueClass(int x, int y) : x(x), y(y) {}
  int x;
  int y;
}; // subject to ABI trickery



/* Test basic functionality. */
class A {
  A(struct Undeclared &);
  A(ValueClass);
  Member mem;
};

A::A(struct Undeclared &ref) : mem(0) {}

// Check that delegation works.
// CHECK: define void @_ZN1AC1ER10Undeclared(
// CHECK: call void @_ZN1AC2ER10Undeclared(

// CHECK: define void @_ZN1AC2ER10Undeclared(
// CHECK: call void @_ZN6MemberC1Ei(

A::A(ValueClass v) : mem(v.y - v.x) {}

// CHECK: define void @_ZN1AC1E10ValueClass(
// CHECK: call void @_ZN1AC2E10ValueClass(

// CHECK: define void @_ZN1AC2E10ValueClass(
// CHECK: call void @_ZN6MemberC1Ei(


/* Test that things work for inheritance. */
struct B : A {
  B(struct Undeclared &);
  Member mem;
};

B::B(struct Undeclared &ref) : A(ref), mem(1) {}

// CHECK: define void @_ZN1BC1ER10Undeclared(
// CHECK: call void @_ZN1BC2ER10Undeclared(

// CHECK: define void @_ZN1BC2ER10Undeclared(
// CHECK: call void @_ZN1AC2ER10Undeclared(
// CHECK: call void @_ZN6MemberC1Ei(



/* Test that the delegation optimization is disabled for classes with
   virtual bases (for now).  This is necessary because a vbase
   initializer could access one of the parameter variables by
   reference.  That's a solvable problem, but let's not solve it right
   now. */
struct C : virtual A {
  C(int);
  Member mem;
};
C::C(int x) : A(ValueClass(x, x+1)), mem(x * x) {}

// CHECK: define void @_ZN1CC1Ei(
// CHECK: call void @_ZN10ValueClassC1Eii(
// CHECK: call void @_ZN1AC2E10ValueClass(
// CHECK: call void @_ZN6MemberC1Ei(

// CHECK: define void @_ZN1CC2Ei(
// CHECK: call void @_ZN6MemberC1Ei(



/* Test that the delegation optimization is disabled for varargs
   constructors. */
struct D : A {
  D(int, ...);
  Member mem;
};

D::D(int x, ...) : A(ValueClass(x, x+1)), mem(x*x) {}

// CHECK: define void @_ZN1DC1Eiz(
// CHECK: call void @_ZN10ValueClassC1Eii(
// CHECK: call void @_ZN1AC2E10ValueClass(
// CHECK: call void @_ZN6MemberC1Ei(

// CHECK: define void @_ZN1DC2Eiz(
// CHECK: call void @_ZN10ValueClassC1Eii(
// CHECK: call void @_ZN1AC2E10ValueClass(
// CHECK: call void @_ZN6MemberC1Ei(