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 operator new(size_t,void * __p)10inline void* operator new(size_t, void* __p) throw() { return __p; } 11 bar()12void __attribute__((noinline)) bar() {} 13 foo(double * p,int n)14long __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); main()29int 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 } 39