• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -emit-llvm -o - -fcxx-exceptions -fexceptions | FileCheck %s
2 
3 typedef __typeof(sizeof(0)) size_t;
4 
5 // Declare the reserved global placement new.
6 void *operator new(size_t, void*);
7 
8 // This just shouldn't crash.
9 namespace test0 {
10   struct allocator {
11     allocator();
12     allocator(const allocator&);
13     ~allocator();
14   };
15 
16   void f();
g(bool b,bool c)17   void g(bool b, bool c) {
18     if (b) {
19       if (!c)
20         throw allocator();
21 
22       return;
23     }
24     f();
25   }
26 }
27 
28 namespace test1 {
29   struct A { A(int); A(int, int); ~A(); void *p; };
30 
a()31   A *a() {
32     // CHECK:    define [[A:%.*]]* @_ZN5test11aEv()
33     // CHECK:      [[NEW:%.*]] = call i8* @_Znwm(i64 8)
34     // CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
35     // CHECK-NEXT: invoke void @_ZN5test11AC1Ei([[A]]* [[CAST]], i32 5)
36     // CHECK:      ret [[A]]* [[CAST]]
37     // CHECK:      call void @_ZdlPv(i8* [[NEW]])
38     return new A(5);
39   }
40 
b()41   A *b() {
42     // CHECK:    define [[A:%.*]]* @_ZN5test11bEv()
43     // CHECK:      [[NEW:%.*]] = call i8* @_Znwm(i64 8)
44     // CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
45     // CHECK-NEXT: [[FOO:%.*]] = invoke i32 @_ZN5test13fooEv()
46     // CHECK:      invoke void @_ZN5test11AC1Ei([[A]]* [[CAST]], i32 [[FOO]])
47     // CHECK:      ret [[A]]* [[CAST]]
48     // CHECK:      call void @_ZdlPv(i8* [[NEW]])
49     extern int foo();
50     return new A(foo());
51   }
52 
53   struct B { B(); ~B(); operator int(); int x; };
54   B makeB();
55 
c()56   A *c() {
57     // CHECK:    define [[A:%.*]]* @_ZN5test11cEv()
58     // CHECK:      [[ACTIVE:%.*]] = alloca i1
59     // CHECK-NEXT: [[NEW:%.*]] = call i8* @_Znwm(i64 8)
60     // CHECK-NEXT: store i1 true, i1* [[ACTIVE]]
61     // CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
62     // CHECK-NEXT: invoke void @_ZN5test11BC1Ev([[B:%.*]]* [[T0:%.*]])
63     // CHECK:      [[T1:%.*]] = getelementptr inbounds [[B]], [[B]]* [[T0]], i32 0, i32 0
64     // CHECK-NEXT: [[T2:%.*]] = load i32, i32* [[T1]], align 4
65     // CHECK-NEXT: invoke void @_ZN5test11AC1Ei([[A]]* [[CAST]], i32 [[T2]])
66     // CHECK:      store i1 false, i1* [[ACTIVE]]
67     // CHECK-NEXT: invoke void @_ZN5test11BD1Ev([[B]]* [[T0]])
68     // CHECK:      ret [[A]]* [[CAST]]
69     // CHECK:      [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
70     // CHECK-NEXT: br i1 [[ISACTIVE]]
71     // CHECK:      call void @_ZdlPv(i8* [[NEW]])
72     return new A(B().x);
73   }
74 
75   //   rdar://11904428
76   //   Terminate landing pads should call __cxa_begin_catch first.
77   // CHECK:      define linkonce_odr hidden void @__clang_call_terminate(i8*) [[NI_NR_NUW:#[0-9]+]] comdat
78   // CHECK-NEXT:   [[T0:%.*]] = call i8* @__cxa_begin_catch(i8* %0) [[NUW:#[0-9]+]]
79   // CHECK-NEXT:   call void @_ZSt9terminatev() [[NR_NUW:#[0-9]+]]
80   // CHECK-NEXT:   unreachable
81 
d()82   A *d() {
83     // CHECK:    define [[A:%.*]]* @_ZN5test11dEv()
84     // CHECK:      [[ACTIVE:%.*]] = alloca i1
85     // CHECK-NEXT: [[NEW:%.*]] = call i8* @_Znwm(i64 8)
86     // CHECK-NEXT: store i1 true, i1* [[ACTIVE]]
87     // CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
88     // CHECK-NEXT: invoke void @_ZN5test11BC1Ev([[B:%.*]]* [[T0:%.*]])
89     // CHECK:      [[T1:%.*]] = invoke i32 @_ZN5test11BcviEv([[B]]* [[T0]])
90     // CHECK:      invoke void @_ZN5test11AC1Ei([[A]]* [[CAST]], i32 [[T1]])
91     // CHECK:      store i1 false, i1* [[ACTIVE]]
92     // CHECK-NEXT: invoke void @_ZN5test11BD1Ev([[B]]* [[T0]])
93     // CHECK:      ret [[A]]* [[CAST]]
94     // CHECK:      [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
95     // CHECK-NEXT: br i1 [[ISACTIVE]]
96     // CHECK:      call void @_ZdlPv(i8* [[NEW]])
97     return new A(B());
98   }
99 
e()100   A *e() {
101     // CHECK:    define [[A:%.*]]* @_ZN5test11eEv()
102     // CHECK:      [[ACTIVE:%.*]] = alloca i1
103     // CHECK-NEXT: [[NEW:%.*]] = call i8* @_Znwm(i64 8)
104     // CHECK-NEXT: store i1 true, i1* [[ACTIVE]]
105     // CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
106     // CHECK-NEXT: invoke void @_ZN5test11BC1Ev([[B:%.*]]* [[T0:%.*]])
107     // CHECK:      [[T1:%.*]] = invoke i32 @_ZN5test11BcviEv([[B]]* [[T0]])
108     // CHECK:      invoke void @_ZN5test11BC1Ev([[B]]* [[T2:%.*]])
109     // CHECK:      [[T3:%.*]] = invoke i32 @_ZN5test11BcviEv([[B]]* [[T2]])
110     // CHECK:      invoke void @_ZN5test11AC1Eii([[A]]* [[CAST]], i32 [[T1]], i32 [[T3]])
111     // CHECK:      store i1 false, i1* [[ACTIVE]]
112     // CHECK-NEXT: invoke void @_ZN5test11BD1Ev([[B]]* [[T2]])
113     // CHECK:      invoke void @_ZN5test11BD1Ev([[B]]* [[T0]])
114     // CHECK:      ret [[A]]* [[CAST]]
115     // CHECK:      [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
116     // CHECK-NEXT: br i1 [[ISACTIVE]]
117     // CHECK:      call void @_ZdlPv(i8* [[NEW]])
118     return new A(B(), B());
119   }
f()120   A *f() {
121     return new A(makeB().x);
122   }
g()123   A *g() {
124     return new A(makeB());
125   }
h()126   A *h() {
127     return new A(makeB(), makeB());
128   }
129 
i()130   A *i() {
131     // CHECK:    define [[A:%.*]]* @_ZN5test11iEv()
132     // CHECK:      [[X:%.*]] = alloca [[A]]*, align 8
133     // CHECK:      [[ACTIVE:%.*]] = alloca i1
134     // CHECK:      [[NEW:%.*]] = call i8* @_Znwm(i64 8)
135     // CHECK-NEXT: store i1 true, i1* [[ACTIVE]]
136     // CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
137     // CHECK-NEXT: invoke void @_ZN5test15makeBEv([[B:%.*]]* sret [[T0:%.*]])
138     // CHECK:      [[T1:%.*]] = invoke i32 @_ZN5test11BcviEv([[B]]* [[T0]])
139     // CHECK:      invoke void @_ZN5test11AC1Ei([[A]]* [[CAST]], i32 [[T1]])
140     // CHECK:      store i1 false, i1* [[ACTIVE]]
141     // CHECK-NEXT: store [[A]]* [[CAST]], [[A]]** [[X]], align 8
142     // CHECK:      invoke void @_ZN5test15makeBEv([[B:%.*]]* sret [[T2:%.*]])
143     // CHECK:      [[RET:%.*]] = load [[A]]*, [[A]]** [[X]], align 8
144     // CHECK:      invoke void @_ZN5test11BD1Ev([[B]]* [[T2]])
145     // CHECK:      invoke void @_ZN5test11BD1Ev([[B]]* [[T0]])
146     // CHECK:      ret [[A]]* [[RET]]
147     // CHECK:      [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
148     // CHECK-NEXT: br i1 [[ISACTIVE]]
149     // CHECK:      call void @_ZdlPv(i8* [[NEW]])
150     A *x;
151     return (x = new A(makeB()), makeB(), x);
152   }
153 }
154 
155 namespace test2 {
156   struct A {
157     A(int); A(int, int); ~A();
158     void *p;
159     void *operator new(size_t);
160     void operator delete(void*, size_t);
161   };
162 
a()163   A *a() {
164     // CHECK:    define [[A:%.*]]* @_ZN5test21aEv()
165     // CHECK:      [[NEW:%.*]] = call i8* @_ZN5test21AnwEm(i64 8)
166     // CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
167     // CHECK-NEXT: invoke void @_ZN5test21AC1Ei([[A]]* [[CAST]], i32 5)
168     // CHECK:      ret [[A]]* [[CAST]]
169     // CHECK:      invoke void @_ZN5test21AdlEPvm(i8* [[NEW]], i64 8)
170     // CHECK:      call void @__clang_call_terminate(i8* {{%.*}}) [[NR_NUW]]
171     return new A(5);
172   }
173 }
174 
175 namespace test3 {
176   struct A {
177     A(int); A(int, int); A(const A&); ~A();
178     void *p;
179     void *operator new(size_t, void*, double);
180     void operator delete(void*, void*, double);
181   };
182 
183   void *foo();
184   double bar();
185   A makeA(), *makeAPtr();
186 
a()187   A *a() {
188     // CHECK:    define [[A:%.*]]* @_ZN5test31aEv()
189     // CHECK:      [[FOO:%.*]] = call i8* @_ZN5test33fooEv()
190     // CHECK:      [[BAR:%.*]] = call double @_ZN5test33barEv()
191     // CHECK:      [[NEW:%.*]] = call i8* @_ZN5test31AnwEmPvd(i64 8, i8* [[FOO]], double [[BAR]])
192     // CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
193     // CHECK-NEXT: invoke void @_ZN5test31AC1Ei([[A]]* [[CAST]], i32 5)
194     // CHECK:      ret [[A]]* [[CAST]]
195     // CHECK:      invoke void @_ZN5test31AdlEPvS1_d(i8* [[NEW]], i8* [[FOO]], double [[BAR]])
196     // CHECK:      call void @__clang_call_terminate(i8* {{%.*}}) [[NR_NUW]]
197     return new(foo(),bar()) A(5);
198   }
199 
200   // rdar://problem/8439196
b(bool cond)201   A *b(bool cond) {
202 
203     // CHECK:    define [[A:%.*]]* @_ZN5test31bEb(i1 zeroext
204     // CHECK:      [[SAVED0:%.*]] = alloca i8*
205     // CHECK-NEXT: [[SAVED1:%.*]] = alloca i8*
206     // CHECK-NEXT: [[CLEANUPACTIVE:%.*]] = alloca i1
207 
208     // CHECK:      [[COND:%.*]] = trunc i8 {{.*}} to i1
209     // CHECK-NEXT: store i1 false, i1* [[CLEANUPACTIVE]]
210     // CHECK-NEXT: br i1 [[COND]]
211     return (cond ?
212 
213     // CHECK:      [[FOO:%.*]] = call i8* @_ZN5test33fooEv()
214     // CHECK-NEXT: [[NEW:%.*]] = call i8* @_ZN5test31AnwEmPvd(i64 8, i8* [[FOO]], double [[CONST:.*]])
215     // CHECK-NEXT: store i8* [[NEW]], i8** [[SAVED0]]
216     // CHECK-NEXT: store i8* [[FOO]], i8** [[SAVED1]]
217     // CHECK-NEXT: store i1 true, i1* [[CLEANUPACTIVE]]
218     // CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
219     // CHECK-NEXT: invoke void @_ZN5test35makeAEv([[A]]* sret [[CAST]])
220     // CHECK: br label
221     //   -> cond.end
222             new(foo(),10.0) A(makeA()) :
223 
224     // CHECK:      [[MAKE:%.*]] = call [[A]]* @_ZN5test38makeAPtrEv()
225     // CHECK:      br label
226     //   -> cond.end
227             makeAPtr());
228 
229     // cond.end:
230     // CHECK:      [[RESULT:%.*]] = phi [[A]]* {{.*}}[[CAST]]{{.*}}[[MAKE]]
231     // CHECK:      ret [[A]]* [[RESULT]]
232 
233     // in the EH path:
234     // CHECK:      [[ISACTIVE:%.*]] = load i1, i1* [[CLEANUPACTIVE]]
235     // CHECK-NEXT: br i1 [[ISACTIVE]]
236     // CHECK:      [[V0:%.*]] = load i8*, i8** [[SAVED0]]
237     // CHECK-NEXT: [[V1:%.*]] = load i8*, i8** [[SAVED1]]
238     // CHECK-NEXT: invoke void @_ZN5test31AdlEPvS1_d(i8* [[V0]], i8* [[V1]], double [[CONST]])
239   }
240 }
241 
242 namespace test4 {
243   struct A {
244     A(int); A(int, int); ~A();
245     void *p;
246     void *operator new(size_t, void*, void*);
247     void operator delete(void*, size_t, void*, void*); // not a match
248   };
249 
a()250   A *a() {
251     // CHECK:    define [[A:%.*]]* @_ZN5test41aEv()
252     // CHECK:      [[FOO:%.*]] = call i8* @_ZN5test43fooEv()
253     // CHECK-NEXT: [[BAR:%.*]] = call i8* @_ZN5test43barEv()
254     // CHECK-NEXT: [[NEW:%.*]] = call i8* @_ZN5test41AnwEmPvS1_(i64 8, i8* [[FOO]], i8* [[BAR]])
255     // CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
256     // CHECK-NEXT: call void @_ZN5test41AC1Ei([[A]]* [[CAST]], i32 5)
257     // CHECK-NEXT: ret [[A]]* [[CAST]]
258     extern void *foo(), *bar();
259 
260     return new(foo(),bar()) A(5);
261   }
262 }
263 
264 // PR7908
265 namespace test5 {
266   struct T { T(); ~T(); };
267 
268   struct A {
269     A(const A &x, const T &t = T());
270     ~A();
271   };
272 
273   void foo();
274 
275   // CHECK-LABEL:    define void @_ZN5test54testEv()
276   // CHECK:      [[EXNSLOT:%.*]] = alloca i8*
277   // CHECK-NEXT: [[SELECTORSLOT:%.*]] = alloca i32
278   // CHECK-NEXT: [[A:%.*]] = alloca [[A_T:%.*]], align 1
279   // CHECK-NEXT: [[T:%.*]] = alloca [[T_T:%.*]], align 1
280   // CHECK-NEXT: invoke void @_ZN5test53fooEv()
281   // CHECK:      [[EXN:%.*]] = load i8*, i8** [[EXNSLOT]]
282   // CHECK-NEXT: [[ADJ:%.*]] = call i8* @__cxa_get_exception_ptr(i8* [[EXN]])
283   // CHECK-NEXT: [[SRC:%.*]] = bitcast i8* [[ADJ]] to [[A_T]]*
284   // CHECK-NEXT: invoke void @_ZN5test51TC1Ev([[T_T]]* [[T]])
285   // CHECK:      invoke void @_ZN5test51AC1ERKS0_RKNS_1TE([[A_T]]* [[A]], [[A_T]]* dereferenceable({{[0-9]+}}) [[SRC]], [[T_T]]* dereferenceable({{[0-9]+}}) [[T]])
286   // CHECK:      invoke void @_ZN5test51TD1Ev([[T_T]]* [[T]])
287   // CHECK:      call i8* @__cxa_begin_catch(i8* [[EXN]]) [[NUW]]
288   // CHECK-NEXT: invoke void @_ZN5test51AD1Ev([[A_T]]* [[A]])
289   // CHECK:      call void @__cxa_end_catch()
test()290   void test() {
291     try {
292       foo();
293     } catch (A a) {
294     }
295   }
296 }
297 
298 // PR9303: invalid assert on this
299 namespace test6 {
300   bool cond();
test()301   void test() {
302     try {
303     lbl:
304       if (cond()) goto lbl;
305     } catch (...) {
306     }
307   }
308 }
309 
310 // PR9298
311 namespace test7 {
312   struct A { A(); ~A(); };
313   struct B {
314     // The throw() operator means that a bad allocation is signalled
315     // with a null return, which means that the initializer is
316     // evaluated conditionally.
317     static void *operator new(size_t size) throw();
318     B(const A&, B*);
319     ~B();
320   };
321 
test()322   B *test() {
323     // CHECK: define [[B:%.*]]* @_ZN5test74testEv()
324     // CHECK:      [[OUTER_NEW:%.*]] = alloca i1
325     // CHECK-NEXT: alloca [[A:%.*]],
326     // CHECK-NEXT: alloca i8*
327     // CHECK-NEXT: alloca i32
328     // CHECK-NEXT: [[OUTER_A:%.*]] = alloca i1
329     // CHECK-NEXT: alloca i8*
330     // CHECK-NEXT: [[INNER_NEW:%.*]] = alloca i1
331     // CHECK-NEXT: alloca [[A]]
332     // CHECK-NEXT: [[INNER_A:%.*]] = alloca i1
333 
334     // Allocate the outer object.
335     // CHECK-NEXT: [[NEW:%.*]] = call i8* @_ZN5test71BnwEm(
336     // CHECK-NEXT: icmp eq i8* [[NEW]], null
337 
338     // These stores, emitted before the outermost conditional branch,
339     // deactivate the temporary cleanups.
340     // CHECK-NEXT: store i1 false, i1* [[OUTER_NEW]]
341     // CHECK-NEXT: store i1 false, i1* [[OUTER_A]]
342     // CHECK-NEXT: store i1 false, i1* [[INNER_NEW]]
343     // CHECK-NEXT: store i1 false, i1* [[INNER_A]]
344     // CHECK-NEXT: br i1
345 
346     // We passed the first null check; activate that cleanup and continue.
347     // CHECK:      store i1 true, i1* [[OUTER_NEW]]
348     // CHECK-NEXT: bitcast
349 
350     // Create the first A temporary and activate that cleanup.
351     // CHECK-NEXT: invoke void @_ZN5test71AC1Ev(
352     // CHECK:      store i1 true, i1* [[OUTER_A]]
353 
354     // Allocate the inner object.
355     // CHECK-NEXT: [[NEW:%.*]] = call i8* @_ZN5test71BnwEm(
356     // CHECK-NEXT: icmp eq i8* [[NEW]], null
357     // CHECK-NEXT: br i1
358 
359     // We passed the second null check; save that pointer, activate
360     // that cleanup, and continue.
361     // CHECK:      store i8* [[NEW]]
362     // CHECK-NEXT: store i1 true, i1* [[INNER_NEW]]
363     // CHECK-NEXT: bitcast
364 
365     // Build the second A temporary and activate that cleanup.
366     // CHECK-NEXT: invoke void @_ZN5test71AC1Ev(
367     // CHECK:      store i1 true, i1* [[INNER_A]]
368 
369     // Build the inner B object and deactivate the inner delete cleanup.
370     // CHECK-NEXT: invoke void @_ZN5test71BC1ERKNS_1AEPS0_(
371     // CHECK:      store i1 false, i1* [[INNER_NEW]]
372     // CHECK:      phi
373 
374     // Build the outer B object and deactivate the outer delete cleanup.
375     // CHECK-NEXT: invoke void @_ZN5test71BC1ERKNS_1AEPS0_(
376     // CHECK:      store i1 false, i1* [[OUTER_NEW]]
377     // CHECK:      phi
378     // CHECK-NEXT: store [[B]]*
379 
380     // Destroy the inner A object.
381     // CHECK-NEXT: load i1, i1* [[INNER_A]]
382     // CHECK-NEXT: br i1
383     // CHECK:      invoke void @_ZN5test71AD1Ev(
384 
385     // Destroy the outer A object.
386     // CHECK:      load i1, i1* [[OUTER_A]]
387     // CHECK-NEXT: br i1
388     // CHECK:      invoke void @_ZN5test71AD1Ev(
389 
390     return new B(A(), new B(A(), 0));
391   }
392 }
393 
394 // Just don't crash.
395 namespace test8 {
396   struct A {
397     // Having both of these is required to trigger the assert we're
398     // trying to avoid.
399     A(const A&);
400     A&operator=(const A&);
401 
402     ~A();
403   };
404 
405   A makeA();
test()406   void test() {
407     throw makeA();
408   }
409   // CHECK-LABEL: define void @_ZN5test84testEv
410 }
411 
412 // Make sure we generate the correct code for the delete[] call which
413 // happens if A::A() throws.  (We were previously calling delete[] on
414 // a pointer to the first array element, not the pointer returned by new[].)
415 // PR10870
416 namespace test9 {
417   struct A {
418     A();
419     ~A();
420   };
test()421   A* test() {
422     return new A[10];
423   }
424   // CHECK: define {{%.*}}* @_ZN5test94testEv
425   // CHECK: [[TEST9_NEW:%.*]] = call i8* @_Znam
426   // CHECK: call void @_ZdaPv(i8* [[TEST9_NEW]])
427 }
428 
429 // In a destructor with a function-try-block, a return statement in a
430 // catch handler behaves differently from running off the end of the
431 // catch handler.  PR13102.
432 namespace test10 {
433   extern void cleanup();
434   extern bool suppress;
435 
436   struct A { ~A(); };
~A()437   A::~A() try { cleanup(); } catch (...) { return; }
438   // CHECK-LABEL:    define void @_ZN6test101AD1Ev(
439   // CHECK:      invoke void @_ZN6test107cleanupEv()
440   // CHECK-NOT:  rethrow
441   // CHECK:      ret void
442 
443   struct B { ~B(); };
~B()444   B::~B() try { cleanup(); } catch (...) {}
445   // CHECK-LABEL:    define void @_ZN6test101BD1Ev(
446   // CHECK:      invoke void @_ZN6test107cleanupEv()
447   // CHECK:      call i8* @__cxa_begin_catch
448   // CHECK-NEXT: invoke void @__cxa_rethrow()
449   // CHECK:      unreachable
450 
451   struct C { ~C(); };
~C()452   C::~C() try { cleanup(); } catch (...) { if (suppress) return; }
453   // CHECK-LABEL:    define void @_ZN6test101CD1Ev(
454   // CHECK:      invoke void @_ZN6test107cleanupEv()
455   // CHECK:      call i8* @__cxa_begin_catch
456   // CHECK-NEXT: load i8, i8* @_ZN6test108suppressE, align 1
457   // CHECK-NEXT: trunc
458   // CHECK-NEXT: br i1
459   // CHECK:      call void @__cxa_end_catch()
460   // CHECK-NEXT: br label
461   // CHECK:      invoke void @__cxa_rethrow()
462   // CHECK:      unreachable
463 }
464 
465 // Ensure that an exception in a constructor destroys
466 // already-constructed array members.  PR14514
467 namespace test11 {
468   struct A {
469     A();
~Atest11::A470     ~A() {}
471   };
472 
473   struct C {
474     A single;
475     A array[2][3];
476 
477     C();
478   };
479 
C()480   C::C() {
481     throw 0;
482   }
483   // CHECK-LABEL:    define void @_ZN6test111CC2Ev(
484   // CHECK:      [[THIS:%.*]] = load [[C:%.*]]*, [[C:%.*]]** {{%.*}}
485   //   Construct single.
486   // CHECK-NEXT: [[SINGLE:%.*]] = getelementptr inbounds [[C]], [[C]]* [[THIS]], i32 0, i32 0
487   // CHECK-NEXT: call void @_ZN6test111AC1Ev([[A:%.*]]* [[SINGLE]])
488   //   Construct array.
489   // CHECK-NEXT: [[ARRAY:%.*]] = getelementptr inbounds [[C]], [[C]]* [[THIS]], i32 0, i32 1
490   // CHECK-NEXT: [[ARRAYBEGIN:%.*]] = getelementptr inbounds [2 x [3 x [[A]]]], [2 x [3 x [[A]]]]* [[ARRAY]], i32 0, i32 0, i32 0
491   // CHECK-NEXT: [[ARRAYEND:%.*]] = getelementptr inbounds [[A]], [[A]]* [[ARRAYBEGIN]], i64 6
492   // CHECK-NEXT: br label
493   // CHECK:      [[CUR:%.*]] = phi [[A]]* [ [[ARRAYBEGIN]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ]
494   // CHECK-NEXT: invoke void @_ZN6test111AC1Ev([[A:%.*]]* [[CUR]])
495   // CHECK:      [[NEXT]] = getelementptr inbounds [[A]], [[A]]* [[CUR]], i64 1
496   // CHECK-NEXT: [[DONE:%.*]] = icmp eq [[A]]* [[NEXT]], [[ARRAYEND]]
497   // CHECK-NEXT: br i1 [[DONE]],
498   //   throw 0;
499   // CHECK:      invoke void @__cxa_throw(
500   //   Landing pad 1, from constructor in array-initialization loop:
501   // CHECK:      landingpad
502   //     - First, destroy already-constructed bits of array.
503   // CHECK:      [[EMPTY:%.*]] = icmp eq [[A]]* [[ARRAYBEGIN]], [[CUR]]
504   // CHECK-NEXT: br i1 [[EMPTY]]
505   // CHECK:      [[AFTER:%.*]] = phi [[A]]* [ [[CUR]], {{%.*}} ], [ [[ELT:%.*]], {{%.*}} ]
506   // CHECK-NEXT: [[ELT]] = getelementptr inbounds [[A]], [[A]]* [[AFTER]], i64 -1
507   // CHECK-NEXT: invoke void @_ZN6test111AD1Ev([[A]]* [[ELT]])
508   // CHECK:      [[DONE:%.*]] = icmp eq [[A]]* [[ELT]], [[ARRAYBEGIN]]
509   // CHECK-NEXT: br i1 [[DONE]],
510   //     - Next, chain to cleanup for single.
511   // CHECK:      br label
512   //   Landing pad 2, from throw site.
513   // CHECK:      landingpad
514   //     - First, destroy all of array.
515   // CHECK:      [[ARRAYBEGIN:%.*]] = getelementptr inbounds [2 x [3 x [[A]]]], [2 x [3 x [[A]]]]* [[ARRAY]], i32 0, i32 0, i32 0
516   // CHECK-NEXT: [[ARRAYEND:%.*]] = getelementptr inbounds [[A]], [[A]]* [[ARRAYBEGIN]], i64 6
517   // CHECK-NEXT: br label
518   // CHECK:      [[AFTER:%.*]] = phi [[A]]* [ [[ARRAYEND]], {{%.*}} ], [ [[ELT:%.*]], {{%.*}} ]
519   // CHECK-NEXT: [[ELT]] = getelementptr inbounds [[A]], [[A]]* [[AFTER]], i64 -1
520   // CHECK-NEXT: invoke void @_ZN6test111AD1Ev([[A]]* [[ELT]])
521   // CHECK:      [[DONE:%.*]] = icmp eq [[A]]* [[ELT]], [[ARRAYBEGIN]]
522   // CHECK-NEXT: br i1 [[DONE]],
523   //     - Next, chain to cleanup for single.
524   // CHECK:      br label
525   //   Finally, the cleanup for single.
526   // CHECK:      invoke void @_ZN6test111AD1Ev([[A]]* [[SINGLE]])
527   // CHECK:      br label
528   // CHECK:      resume
529   //   (After this is a terminate landingpad.)
530 }
531 
532 namespace test12 {
533   struct A {
534     void operator delete(void *, void *);
535     A();
536   };
537 
test(void * ptr)538   A *test(void *ptr) {
539     return new (ptr) A();
540   }
541   // CHECK-LABEL: define {{.*}} @_ZN6test124testEPv(
542   // CHECK:       [[PTR:%.*]] = load i8*, i8*
543   // CHECK-NEXT:  [[CAST:%.*]] = bitcast i8* [[PTR]] to [[A:%.*]]*
544   // CHECK-NEXT:  invoke void @_ZN6test121AC1Ev([[A]]* [[CAST]])
545   // CHECK:       ret [[A]]* [[CAST]]
546   // CHECK:       invoke void @_ZN6test121AdlEPvS1_(i8* [[PTR]], i8* [[PTR]])
547 }
548 
549 // CHECK: attributes [[NI_NR_NUW]] = { noinline noreturn nounwind }
550