Debian Codegraph @

gcc/testsuite/g++.dg/init/new16.C

raw
1 // { dg-do run }
2 // { dg-options "-O2 -fstrict-aliasing" }
3
4 // Test that we don't let TBAA reorder an assignment across a
5 // placement new.
6 // See PR 29286.
7
8 typedef __SIZE_TYPE__ size_t;
9
10 inline void* operator new(size_t, void* __p) throw() { return __p; }
11
12 void __attribute__((noinline)) bar() {}
13
14 long __attribute__((noinline)) foo(double *p, int n)
15 {
16 long *f;
17 for (int i=0; i<n; ++i)
18 {
19 int *l = (int *)p;
20 *l = 0;
21 f = new (p) long;
22 *f = -1;
23 }
24 bar ();
25 return *f;
26 }
27
28 extern "C" void abort(void);
29 int main()
30 {
31 union {
32 int i;
33 long l;
34 } u;
35 if (foo((double *)&u, 1) != -1)
36 abort ();
37 return 0;
38 }