| 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 } } |
| 7 |
|
| 8 |
#include <new> |
| 9 |
#include <cstring> |
| 10 |
#include <cstdlib> |
| 11 |
|
| 12 |
char *p; |
| 13 |
struct S { char buf[128]; S () { memset (buf, ' ', 128); }; ~S () {}; }; |
| 14 |
|
| 15 |
__attribute__((noipa)) void |
| 16 |
foo (char *x) |
| 17 |
{ |
| 18 |
p = x; |
| 19 |
} |
| 20 |
|
| 21 |
__attribute__((noipa)) int |
| 22 |
bar (S *x) |
| 23 |
{ |
| 24 |
return x->buf[12]; |
| 25 |
} |
| 26 |
|
| 27 |
__attribute__((noipa)) void |
| 28 |
baz (char *x) |
| 29 |
{ |
| 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 (); |
| 38 |
} |
| 39 |
|
| 40 |
__attribute__((noipa)) void |
| 41 |
qux () |
| 42 |
{ |
| 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 |
} |
| 52 |
} |
| 53 |
|
| 54 |
int |
| 55 |
main () |
| 56 |
{ |
| 57 |
qux (); |
| 58 |
} |