Fortran: Fix PR 47485.
[gcc.git] / gcc / testsuite / g++.dg / torture / alias-1.C
blob01eb86ca2a4c91daaf22fa8809c67ed84a420ec5
1 // Verify we don't try to allocate the same stack slot for
2 // buf1 and buf2 in qux.  While there is a CLOBBER stmt for buf1
3 // from inlined destructor, the buf1 variable doesn't go out of scope
4 // until after the baz call.
5 // { dg-do run }
6 // { dg-skip-if "requires hosted libstdc++ for cstring" { ! hostedlib } }
8 #include <new>
9 #include <cstring>
10 #include <cstdlib>
12 char *p;
13 struct S { char buf[128]; S () { memset (buf, ' ', 128); }; ~S () {}; };
15 __attribute__((noipa)) void
16 foo (char *x)
18   p = x;
21 __attribute__((noipa)) int
22 bar (S *x)
24   return x->buf[12];
27 __attribute__((noipa)) void
28 baz (char *x)
30   S *a = new (p) (S);
31   S *b = new (x) (S);
32   memset (a->buf, '0', 128);
33   memset (b->buf, '1', 128);
34   if (bar (a) != '0' || bar (b) != '1')
35     abort ();
36   b->~S ();
37   a->~S ();
40 __attribute__((noipa)) void
41 qux ()
43   char buf1[128];
44   foo (buf1);
45   S *p = new (buf1) (S);
46   bar (p);
47   p->~S ();
48   {
49     char buf2[128];
50     baz (buf2);
51   }
54 int
55 main ()
57   qux ();