| 1 |
/* PR tree-optimization/98597 */ |
| 2 |
/* { dg-do compile } */ |
| 3 |
/* { dg-options "-O2 -fno-tree-vectorize -Wuninitialized" } */ |
| 4 |
|
| 5 |
union U { double d; int i; float f; }; |
| 6 |
struct S { char a; int b; char c; unsigned d; union U e; int f[3]; unsigned g[3]; }; |
| 7 |
struct T { char t; struct S u; int v; }; |
| 8 |
typedef short V[2][2]; |
| 9 |
void baz (V *); |
| 10 |
|
| 11 |
static inline int |
| 12 |
bar (char *p) |
| 13 |
{ |
| 14 |
return *(int *) p; |
| 15 |
} |
| 16 |
|
| 17 |
void |
| 18 |
foo (int *q) |
| 19 |
{ |
| 20 |
struct T t; |
| 21 |
t.t = 1; |
| 22 |
t.u.c = 2; |
| 23 |
char *pt = (char *) &t; |
| 24 |
q[0] = bar (pt + __builtin_offsetof (struct T, u.b)); /* { dg-warning "'t\\.u\\.b' is used uninitialized" } */ |
| 25 |
q[1] = bar (pt + __builtin_offsetof (struct T, u.e)); /* { dg-warning "'\\*\\(int \\*\\)\\(\\(char \\*\\)&t \\+ offsetof\\(struct T, u\\.e\\)\\)' is used uninitialized" } */ |
| 26 |
q[2] = bar (pt + __builtin_offsetof (struct T, v)); /* { dg-warning "'t\\.v' is used uninitialized" } */ |
| 27 |
q[3] = bar (pt + __builtin_offsetof (struct T, u.d)); /* { dg-warning "'\\*\\(int \\*\\)\\(\\(char \\*\\)&t \\+ offsetof\\(struct T, u\\.d\\)\\)' is used uninitialized" } */ |
| 28 |
q[4] = bar (pt + __builtin_offsetof (struct T, u.f[2])); /* { dg-warning "'t\\.u\\.f\\\[2\\\]' is used uninitialized" } */ |
| 29 |
q[5] = bar (pt + __builtin_offsetof (struct T, u.g[2])); /* { dg-warning "'\\*\\(int \\*\\)\\(\\(char \\*\\)&t \\+ offsetof\\(struct T, u\\.g\\\[2\\\]\\)\\)' is used uninitialized" } */ |
| 30 |
int s[3]; |
| 31 |
s[0] = 1; |
| 32 |
char *ps = (char *) s; |
| 33 |
q[6] = bar (ps + sizeof (int)); /* { dg-warning "'s\\\[1\\\]' is used uninitialized" } */ |
| 34 |
unsigned w[2][2]; |
| 35 |
w[0][0] = 1; |
| 36 |
char *pw = (char *) w; |
| 37 |
q[7] = bar (pw + 3 * sizeof (unsigned)); /* { dg-warning "'\\*\\(int \\*\\)\\(&w\\\[1\\\]\\\[1\\\]\\)' is used uninitialized" } */ |
| 38 |
struct T x[3][3]; |
| 39 |
x[0][0].t = 1; |
| 40 |
char *px = (char *) x; |
| 41 |
q[8] = bar (px + 5 * sizeof (struct T) + __builtin_offsetof (struct T, u.b)); /* { dg-warning "'x\\\[1\\\]\\\[2\\\]\\.u\\.b' is used uninitialized" } */ |
| 42 |
q[9] = bar (px + 6 * sizeof (struct T) + __builtin_offsetof (struct T, u.d)); /* { dg-warning "'\\*\\(int \\*\\)\\(\\(char \\*\\)&x\\\[2\\\]\\\[0\\\] \\+ offsetof\\(struct T, u\\.d\\)\\)' is used uninitialized" } */ |
| 43 |
#if defined(__i386__) || defined(__x86_64__) |
| 44 |
/* memcpy folding is too target dependent to test it everywhere. */ |
| 45 |
V u[2], v[2]; |
| 46 |
u[0][0][0] = 1; |
| 47 |
__builtin_memcpy (&v[1], &u[1], sizeof (V)); /* { dg-warning "'u' is used uninitialized" "" { target i?86-*-* x86_64-*-* } } */ |
| 48 |
baz (&v[1]); |
| 49 |
#endif |
| 50 |
} |