Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s |
| 2 | |
| 3 | struct A { |
| 4 | virtual ~A(); |
| 5 | }; |
| 6 | |
| 7 | struct B : A { }; |
| 8 | |
| 9 | struct C { |
| 10 | int i; |
| 11 | B b; |
| 12 | }; |
| 13 | |
| 14 | // CHECK: _Z15test_value_initv |
| 15 | void test_value_init() { |
| 16 | // This value initialization requires zero initialization of the 'B' |
| 17 | // subobject followed by a call to its constructor. |
| 18 | // PR5800 |
| 19 | |
| 20 | // CHECK: store i32 17 |
Mon P Wang | 3ecd785 | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 21 | // CHECK: call void @llvm.memset.p0i8.i64 |
Douglas Gregor | 7dd4490 | 2009-12-16 19:18:40 +0000 | [diff] [blame] | 22 | // CHECK: call void @_ZN1BC1Ev |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 23 | C c = { 17 } ; |
Douglas Gregor | 7dd4490 | 2009-12-16 19:18:40 +0000 | [diff] [blame] | 24 | // CHECK: call void @_ZN1CD1Ev |
Douglas Gregor | 16006c9 | 2009-12-16 18:50:27 +0000 | [diff] [blame] | 25 | } |
Douglas Gregor | 1c63b9c | 2010-04-27 20:36:09 +0000 | [diff] [blame] | 26 | |
| 27 | enum enum_type { negative_number = -1, magic_number = 42 }; |
| 28 | |
| 29 | class enum_holder |
| 30 | { |
| 31 | enum_type m_enum; |
| 32 | |
| 33 | public: |
| 34 | enum_holder() : m_enum(magic_number) { } |
| 35 | }; |
| 36 | |
| 37 | struct enum_holder_and_int |
| 38 | { |
| 39 | enum_holder e; |
| 40 | int i; |
| 41 | }; |
| 42 | |
| 43 | // CHECK: _Z24test_enum_holder_and_intv() |
| 44 | void test_enum_holder_and_int() { |
| 45 | // CHECK: alloca |
| 46 | // CHECK-NEXT: bitcast |
| 47 | // CHECK-NEXT: call void @llvm.memset |
| 48 | // CHECK-NEXT: call void @_ZN19enum_holder_and_intC1Ev |
| 49 | enum_holder_and_int(); |
| 50 | // CHECK-NEXT: ret void |
| 51 | } |
John McCall | 9021718 | 2010-08-07 08:21:30 +0000 | [diff] [blame] | 52 | |
| 53 | // PR7834: don't crash. |
| 54 | namespace test1 { |
| 55 | struct A { |
| 56 | int A::*f; |
| 57 | A(); |
| 58 | A(const A&); |
| 59 | A &operator=(const A &); |
| 60 | }; |
| 61 | |
| 62 | struct B { |
| 63 | A base; |
| 64 | }; |
| 65 | |
| 66 | void foo() { |
| 67 | B(); |
| 68 | } |
| 69 | } |
Douglas Gregor | 452b7f2 | 2010-08-20 16:57:37 +0000 | [diff] [blame] | 70 | |
| 71 | namespace ptrmem { |
| 72 | struct S { |
| 73 | int mem1; |
| 74 | int S::*mem2; |
| 75 | }; |
| 76 | |
| 77 | // CHECK: define i32 @_ZN6ptrmem4testEPNS_1SE |
| 78 | int test(S *s) { |
| 79 | // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 |
| 80 | // CHECK: getelementptr |
| 81 | // CHECK: ret |
| 82 | return s->*S().mem2; |
| 83 | } |
| 84 | } |
| 85 | |
Argyrios Kyrtzidis | 3b4d490 | 2011-04-28 18:53:58 +0000 | [diff] [blame] | 86 | namespace PR9801 { |
| 87 | |
| 88 | struct Test { |
| 89 | Test() : i(10) {} |
| 90 | Test(int i) : i(i) {} |
| 91 | int i; |
| 92 | private: |
| 93 | int j; |
| 94 | }; |
| 95 | |
| 96 | struct Test2 { |
| 97 | Test t; |
| 98 | }; |
| 99 | |
| 100 | struct Test3 : public Test { }; |
| 101 | |
| 102 | // CHECK: define void @_ZN6PR98011fEv |
| 103 | void f() { |
Argyrios Kyrtzidis | 657baf1 | 2011-04-28 22:57:55 +0000 | [diff] [blame] | 104 | // CHECK-NOT: call void @llvm.memset.p0i8.i64 |
Argyrios Kyrtzidis | 3b4d490 | 2011-04-28 18:53:58 +0000 | [diff] [blame] | 105 | // CHECK: call void @_ZN6PR98014TestC1Ei |
Argyrios Kyrtzidis | 657baf1 | 2011-04-28 22:57:55 +0000 | [diff] [blame] | 106 | // CHECK-NOT: call void @llvm.memset.p0i8.i64 |
Argyrios Kyrtzidis | 3b4d490 | 2011-04-28 18:53:58 +0000 | [diff] [blame] | 107 | // CHECK: call void @_ZN6PR98014TestC1Ev |
Argyrios Kyrtzidis | 3b4d490 | 2011-04-28 18:53:58 +0000 | [diff] [blame] | 108 | Test partial[3] = { 1 }; |
| 109 | |
Argyrios Kyrtzidis | 657baf1 | 2011-04-28 22:57:55 +0000 | [diff] [blame] | 110 | // CHECK-NOT: call void @llvm.memset.p0i8.i64 |
Argyrios Kyrtzidis | 3b4d490 | 2011-04-28 18:53:58 +0000 | [diff] [blame] | 111 | // CHECK: call void @_ZN6PR98014TestC1Ev |
John McCall | bdc4d80 | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 112 | // CHECK-NOT: call void @_ZN6PR98014TestC1Ev |
Argyrios Kyrtzidis | 3b4d490 | 2011-04-28 18:53:58 +0000 | [diff] [blame] | 113 | Test empty[3] = {}; |
| 114 | |
Argyrios Kyrtzidis | 657baf1 | 2011-04-28 22:57:55 +0000 | [diff] [blame] | 115 | // CHECK: call void @llvm.memset.p0i8.i64 |
| 116 | // CHECK-NOT: call void @llvm.memset.p0i8.i64 |
Argyrios Kyrtzidis | 3b4d490 | 2011-04-28 18:53:58 +0000 | [diff] [blame] | 117 | // CHECK: call void @_ZN6PR98015Test2C1Ev |
John McCall | bdc4d80 | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 118 | // CHECK-NOT: call void @_ZN6PR98015Test2C1Ev |
Argyrios Kyrtzidis | 3b4d490 | 2011-04-28 18:53:58 +0000 | [diff] [blame] | 119 | Test2 empty2[3] = {}; |
| 120 | |
Argyrios Kyrtzidis | 657baf1 | 2011-04-28 22:57:55 +0000 | [diff] [blame] | 121 | // CHECK: call void @llvm.memset.p0i8.i64 |
| 122 | // CHECK-NOT: call void @llvm.memset.p0i8.i64 |
Argyrios Kyrtzidis | 3b4d490 | 2011-04-28 18:53:58 +0000 | [diff] [blame] | 123 | // CHECK: call void @_ZN6PR98015Test3C1Ev |
Argyrios Kyrtzidis | 657baf1 | 2011-04-28 22:57:55 +0000 | [diff] [blame] | 124 | // CHECK-NOT: call void @llvm.memset.p0i8.i64 |
John McCall | bdc4d80 | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 125 | // CHECK-NOT: call void @_ZN6PR98015Test3C1Ev |
Argyrios Kyrtzidis | 3b4d490 | 2011-04-28 18:53:58 +0000 | [diff] [blame] | 126 | Test3 empty3[3] = {}; |
| 127 | } |
| 128 | |
| 129 | } |
| 130 | |
Douglas Gregor | 452b7f2 | 2010-08-20 16:57:37 +0000 | [diff] [blame] | 131 | namespace zeroinit { |
| 132 | struct S { int i; }; |
| 133 | |
| 134 | // CHECK: define i32 @_ZN8zeroinit4testEv() |
| 135 | int test() { |
| 136 | // CHECK: call void @llvm.memset.p0i8.i64 |
Richard Smith | 5120188 | 2011-12-30 21:15:51 +0000 | [diff] [blame] | 137 | // CHECK: ret i32 0 |
Douglas Gregor | 452b7f2 | 2010-08-20 16:57:37 +0000 | [diff] [blame] | 138 | return S().i; |
| 139 | } |
Douglas Gregor | 759e41b | 2010-08-22 16:15:35 +0000 | [diff] [blame] | 140 | |
| 141 | struct X0 { |
| 142 | X0() { } |
| 143 | int x; |
| 144 | }; |
| 145 | |
| 146 | struct X1 : X0 { |
| 147 | int x1; |
| 148 | void f(); |
| 149 | }; |
| 150 | |
| 151 | // CHECK: define void @_ZN8zeroinit9testX0_X1Ev |
| 152 | void testX0_X1() { |
| 153 | // CHECK: call void @llvm.memset.p0i8.i64 |
| 154 | // CHECK-NEXT: call void @_ZN8zeroinit2X1C1Ev |
| 155 | // CHECK-NEXT: call void @_ZN8zeroinit2X11fEv |
| 156 | X1().f(); |
| 157 | } |
Douglas Gregor | 8c3e554 | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 158 | |
| 159 | template<typename> |
| 160 | struct X2 : X0 { |
| 161 | int x2; |
| 162 | void f(); |
| 163 | }; |
| 164 | |
| 165 | template<typename> |
| 166 | struct X3 : X2<int> { |
| 167 | X3() : X2<int>() { } |
Anders Carlsson | 1741d7b | 2011-04-17 21:49:47 +0000 | [diff] [blame] | 168 | int i; |
Douglas Gregor | 8c3e554 | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | |
| 172 | // CHECK: define void @_ZN8zeroinit9testX0_X3Ev |
| 173 | void testX0_X3() { |
| 174 | // CHECK-NOT: call void @llvm.memset |
| 175 | // CHECK: call void @_ZN8zeroinit2X3IiEC1Ev |
| 176 | // CHECK: call void @_ZN8zeroinit2X2IiE1fEv |
| 177 | // CHECK-NEXT: ret void |
| 178 | X3<int>().f(); |
| 179 | } |
| 180 | |
John McCall | bdc4d80 | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 181 | // More checks at EOF |
Douglas Gregor | 452b7f2 | 2010-08-20 16:57:37 +0000 | [diff] [blame] | 182 | } |
Chris Lattner | d1d56df | 2010-12-02 18:29:00 +0000 | [diff] [blame] | 183 | |
| 184 | namespace PR8726 { |
| 185 | class C; |
| 186 | struct S { |
| 187 | const C &c1; |
| 188 | int i; |
| 189 | const C &c2; |
| 190 | }; |
| 191 | void f(const C& c) { |
| 192 | S s = {c, 42, c}; |
| 193 | } |
| 194 | |
Chris Lattner | 124b3de | 2010-12-21 02:36:58 +0000 | [diff] [blame] | 195 | } |
John McCall | bdc4d80 | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 196 | |
| 197 | // rdar://problem/9355931 |
| 198 | namespace test6 { |
| 199 | struct A { A(); A(int); }; |
| 200 | |
| 201 | void test() { |
| 202 | A arr[10][20] = { 5 }; |
| 203 | }; |
| 204 | // CHECK: define void @_ZN5test64testEv() |
| 205 | // CHECK: [[ARR:%.*]] = alloca [10 x [20 x [[A:%.*]]]], |
John McCall | bdc4d80 | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 206 | |
| 207 | // CHECK-NEXT: [[INNER:%.*]] = getelementptr inbounds [10 x [20 x [[A]]]]* [[ARR]], i64 0, i64 0 |
| 208 | // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [20 x [[A]]]* [[INNER]], i64 0, i64 0 |
| 209 | // CHECK-NEXT: call void @_ZN5test61AC1Ei([[A]]* [[T0]], i32 5) |
| 210 | // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [[A]]* [[T0]], i64 1 |
| 211 | // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [[A]]* [[T0]], i64 20 |
| 212 | // CHECK-NEXT: br label |
| 213 | // CHECK: [[CUR:%.*]] = phi [[A]]* [ [[BEGIN]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ] |
| 214 | // CHECK-NEXT: call void @_ZN5test61AC1Ev([[A]]* [[CUR]]) |
| 215 | // CHECK-NEXT: [[NEXT]] = getelementptr inbounds [[A]]* [[CUR]], i64 1 |
| 216 | // CHECK-NEXT: [[T0:%.*]] = icmp eq [[A]]* [[NEXT]], [[END]] |
| 217 | // CHECK-NEXT: br i1 |
| 218 | |
| 219 | // CHECK: [[BEGIN:%.*]] = getelementptr inbounds [20 x [[A]]]* [[INNER]], i64 1 |
| 220 | // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [20 x [[A]]]* [[INNER]], i64 10 |
| 221 | // CHECK-NEXT: br label |
| 222 | // CHECK: [[CUR:%.*]] = phi [20 x [[A]]]* [ [[BEGIN]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ] |
John McCall | bdc4d80 | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 223 | |
John McCall | c3c0766 | 2011-07-13 06:10:41 +0000 | [diff] [blame] | 224 | // Inner loop. |
| 225 | // CHECK-NEXT: [[IBEGIN:%.*]] = getelementptr inbounds [20 x [[A]]]* [[CUR]], i32 0, i32 0 |
| 226 | // CHECK-NEXT: [[IEND:%.*]] = getelementptr inbounds [[A]]* [[IBEGIN]], i64 20 |
John McCall | bdc4d80 | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 227 | // CHECK-NEXT: br label |
John McCall | c3c0766 | 2011-07-13 06:10:41 +0000 | [diff] [blame] | 228 | // CHECK: [[ICUR:%.*]] = phi [[A]]* [ [[IBEGIN]], {{%.*}} ], [ [[INEXT:%.*]], {{%.*}} ] |
| 229 | // CHECK-NEXT: call void @_ZN5test61AC1Ev([[A]]* [[ICUR]]) |
| 230 | // CHECK-NEXT: [[INEXT:%.*]] = getelementptr inbounds [[A]]* [[ICUR]], i64 1 |
| 231 | // CHECK-NEXT: [[T0:%.*]] = icmp eq [[A]]* [[INEXT]], [[IEND]] |
| 232 | // CHECK-NEXT: br i1 [[T0]], |
| 233 | |
John McCall | bdc4d80 | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 234 | // CHECK: [[NEXT]] = getelementptr inbounds [20 x [[A]]]* [[CUR]], i64 1 |
| 235 | // CHECK-NEXT: [[T0:%.*]] = icmp eq [20 x [[A]]]* [[NEXT]], [[END]] |
| 236 | // CHECK-NEXT: br i1 [[T0]] |
| 237 | // CHECK: ret void |
| 238 | } |
| 239 | |
Eli Friedman | 2ed7cb6 | 2011-10-14 02:27:24 +0000 | [diff] [blame] | 240 | namespace PR11124 { |
| 241 | // Make sure C::C doesn't overwrite parts of A while it is zero-initializing B |
| 242 | struct A { int a; A(); A(int); }; |
| 243 | struct B : virtual A { int b; }; |
| 244 | struct C : B { C(); }; |
| 245 | C::C() : A(3), B() {} |
| 246 | // CHECK: define void @_ZN7PR111241CC1Ev |
| 247 | // CHECK: call void @llvm.memset.p0i8.i64(i8* {{.*}}, i8 0, i64 12, i32 8, i1 false) |
| 248 | // CHECK-NEXT: call void @_ZN7PR111241BC2Ev |
| 249 | // Make sure C::C doesn't overwrite parts of A while it is zero-initializing B |
| 250 | |
| 251 | struct B2 : virtual A { int B::*b; }; |
| 252 | struct C2 : B2 { C2(); }; |
| 253 | C2::C2() : A(3), B2() {} |
| 254 | // CHECK: define void @_ZN7PR111242C2C1Ev |
| 255 | // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* {{.*}}, i64 16, i32 8, i1 false) |
| 256 | // CHECK-NEXT: call void @_ZN7PR111242B2C2Ev |
| 257 | } |
| 258 | |
Richard Smith | 0dbe2fb | 2012-12-21 03:17:28 +0000 | [diff] [blame] | 259 | // Ensure we produce an i1 here, and don't assert. |
| 260 | // CHECK: define void @_Z9r170806_bv( |
| 261 | // CHECK: call void @_Z9r170806_ab(i1 zeroext false) |
| 262 | void r170806_a(bool b = bool()); |
| 263 | void r170806_b() { r170806_a(); } |
| 264 | |
John McCall | bdc4d80 | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 265 | // CHECK: define linkonce_odr void @_ZN8zeroinit2X3IiEC2Ev(%"struct.zeroinit::X3"* %this) unnamed_addr |
| 266 | // CHECK: call void @llvm.memset.p0i8.i64 |
| 267 | // CHECK-NEXT: call void @_ZN8zeroinit2X2IiEC2Ev |
| 268 | // CHECK-NEXT: ret void |