blob: d610fd5ad8664c37b2ffafd7ad65cd6222d268da [file] [log] [blame]
Douglas Gregor7abfbdb2009-12-19 03:01:41 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -emit-llvm -o - | FileCheck %s
Fariborz Jahanian742cd1b2009-07-25 21:12:28 +00002
3extern "C" int printf(...);
4
5struct M {
6 M() { printf("M()\n"); }
7 M(int i) { iM = i; printf("M(%d)\n", i); }
8 int iM;
9 void MPR() {printf("iM = %d\n", iM); };
10};
11
12struct P {
13 P() { printf("P()\n"); }
14 P(int i) { iP = i; printf("P(%d)\n", i); }
15 int iP;
16 void PPR() {printf("iP = %d\n", iP); };
17};
18
19struct Q {
20 Q() { printf("Q()\n"); }
21 Q(int i) { iQ = i; printf("Q(%d)\n", i); }
22 int iQ;
23 void QPR() {printf("iQ = %d\n", iQ); };
24};
25
26struct N : M , P, Q {
27 N() : f1(1.314), P(2000), ld(00.1234+f1), M(1000), Q(3000),
28 d1(3.4567), i1(1234), m1(100) { printf("N()\n"); }
29 M m1;
30 M m2;
31 float f1;
32 int i1;
33 float d1;
Mike Stump1eb44332009-09-09 15:08:12 +000034 void PR() {
35 printf("f1 = %f d1 = %f i1 = %d ld = %f \n", f1,d1,i1, ld);
36 MPR();
37 PPR();
38 QPR();
39 printf("iQ = %d\n", iQ);
40 printf("iP = %d\n", iP);
41 printf("iM = %d\n", iM);
42 // FIXME. We don't yet support this syntax.
43 // printf("iQ = %d\n", (*this).iQ);
44 printf("iQ = %d\n", this->iQ);
45 printf("iP = %d\n", this->iP);
46 printf("iM = %d\n", this->iM);
47 }
Fariborz Jahanian742cd1b2009-07-25 21:12:28 +000048 float ld;
49 float ff;
Fariborz Jahanian64a54ad2009-08-21 17:09:38 +000050 M arr_m[3];
51 P arr_p[1][3];
52 Q arr_q[2][3][4];
Fariborz Jahanian742cd1b2009-07-25 21:12:28 +000053};
54
55int main() {
56 M m1;
57
58 N n1;
59 n1.PR();
60}
61
Douglas Gregor7abfbdb2009-12-19 03:01:41 +000062// PR5826
63template <class T> struct A {
64 A() {}
65 A(int) {}
66 A(const A&) {}
67 ~A() {}
68 operator int() {return 0;}
69};
70
71// CHECK: define void @_Z1fv()
72void f() {
73 // CHECK: call void @_ZN1AIsEC1Ei
74 A<short> a4 = 97;
75
76 // CHECK-NEXT: store i32 17
77 int i = 17;
78
79 // CHECK-NEXT: call void @_ZN1AIsED1Ev
80 // CHECK-NOT: call void @_ZN1AIsED1Ev
81 // CHECK: ret void
82}
Douglas Gregord6068482010-03-26 22:43:07 +000083
John McCall7e1dff72010-09-17 02:31:44 +000084// Make sure we initialize the vtable pointer if it's required by a
85// base initializer.
86namespace InitVTable {
87 struct A { A(int); };
88 struct B : A {
89 virtual int foo();
90 B();
91 B(int);
92 };
93
94 // CHECK: define void @_ZN10InitVTable1BC2Ev(
95 // CHECK: [[T0:%.*]] = bitcast [[B:%.*]]* [[THIS:%.*]] to i8***
96 // CHECK-NEXT: store i8** getelementptr inbounds ([3 x i8*]* @_ZTVN10InitVTable1BE, i64 0, i64 2), i8*** [[T0]]
97 // CHECK: [[VTBL:%.*]] = load i32 ([[B]]*)*** {{%.*}}
98 // CHECK-NEXT: [[FNP:%.*]] = getelementptr inbounds i32 ([[B]]*)** [[VTBL]], i64 0
99 // CHECK-NEXT: [[FN:%.*]] = load i32 ([[B]]*)** [[FNP]]
100 // CHECK-NEXT: [[ARG:%.*]] = call i32 [[FN]]([[B]]* [[THIS]])
101 // CHECK-NEXT: call void @_ZN10InitVTable1AC2Ei({{.*}}* %1, i32 [[ARG]])
102 // CHECK-NEXT: [[T0:%.*]] = bitcast [[B]]* [[THIS]] to i8***
103 // CHECK-NEXT: store i8** getelementptr inbounds ([3 x i8*]* @_ZTVN10InitVTable1BE, i64 0, i64 2), i8*** [[T0]]
104 // CHECK-NEXT: ret void
105 B::B() : A(foo()) {}
106
107 // CHECK: define void @_ZN10InitVTable1BC2Ei(
108 // CHECK: [[ARG:%.*]] = add nsw i32 {{%.*}}, 5
109 // CHECK-NEXT: call void @_ZN10InitVTable1AC2Ei({{.*}}* {{%.*}}, i32 [[ARG]])
110 // CHECK-NEXT: [[T0:%.*]] = bitcast [[B]]* {{%.*}} to i8***
111 // CHECK-NEXT: store i8** getelementptr inbounds ([3 x i8*]* @_ZTVN10InitVTable1BE, i64 0, i64 2), i8*** [[T0]]
112 // CHECK-NEXT: ret void
113 B::B(int x) : A(x + 5) {}
114}
115
Douglas Gregord6068482010-03-26 22:43:07 +0000116template<typename T>
117struct X {
118 X(const X &);
119
120 T *start;
121 T *end;
122};
123
124template<typename T> struct X;
125
126// Make sure that the instantiated constructor initializes start and
127// end properly.
128// CHECK: define linkonce_odr void @_ZN1XIiEC2ERKS0_
129// CHECK: {{store.*null}}
130// CHECK: {{store.*null}}
131// CHECK: ret
132template<typename T>
133X<T>::X(const X &other) : start(0), end(0) { }
134
135X<int> get_X(X<int> x) { return x; }