| 1 |
/* PR libstdc++/88101 */ |
| 2 |
/* { dg-do run } */ |
| 3 |
|
| 4 |
union V { char a; signed char b; unsigned char c; }; |
| 5 |
struct T { char a; int b; union V c; }; |
| 6 |
union U { int a; long double b; struct T c; }; |
| 7 |
struct S { char a; union U b; long long c; char d; } s1, s2; |
| 8 |
|
| 9 |
__attribute__((noipa)) void |
| 10 |
foo (struct S *s, int x) |
| 11 |
{ |
| 12 |
s->a = -1; s->c = -1; s->d = -1; |
| 13 |
switch (x) |
| 14 |
{ |
| 15 |
case 0: |
| 16 |
s->b.a = -1; |
| 17 |
break; |
| 18 |
case 1: |
| 19 |
s->b.b = -12345.25L; |
| 20 |
break; |
| 21 |
case 2: |
| 22 |
s->b.c.a = -1; |
| 23 |
s->b.c.b = -1; |
| 24 |
s->b.c.c.b = -1; |
| 25 |
break; |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
int |
| 30 |
main () |
| 31 |
{ |
| 32 |
__builtin_memset (&s1, 0, sizeof (s1)); |
| 33 |
__builtin_memset (&s2, -1, sizeof (s2)); |
| 34 |
foo (&s1, 0); |
| 35 |
foo (&s2, 0); |
| 36 |
__builtin_clear_padding (&s2); |
| 37 |
if (s2.b.a != -1) |
| 38 |
__builtin_abort (); |
| 39 |
__builtin_clear_padding (&s2.b.a); |
| 40 |
__builtin_memset (&s2.b.a + 1, 0, sizeof (union U) - sizeof (s2.b.a)); |
| 41 |
if (__builtin_memcmp (&s1, &s2, sizeof (s1))) |
| 42 |
__builtin_abort (); |
| 43 |
__builtin_memset (&s1, 0, sizeof (s1)); |
| 44 |
__builtin_memset (&s2, -1, sizeof (s2)); |
| 45 |
foo (&s1, 1); |
| 46 |
foo (&s2, 1); |
| 47 |
__builtin_clear_padding (&s2); |
| 48 |
if (s2.b.b != -12345.25L) |
| 49 |
__builtin_abort (); |
| 50 |
__builtin_clear_padding (&s2.b.b); |
| 51 |
__builtin_memset (&s2.b.b + 1, 0, sizeof (union U) - sizeof (s2.b.b)); |
| 52 |
if (__builtin_memcmp (&s1, &s2, sizeof (s1))) |
| 53 |
__builtin_abort (); |
| 54 |
__builtin_memset (&s1, 0, sizeof (s1)); |
| 55 |
__builtin_memset (&s2, -1, sizeof (s2)); |
| 56 |
foo (&s1, 2); |
| 57 |
foo (&s2, 2); |
| 58 |
__builtin_clear_padding (&s2); |
| 59 |
if (s2.b.c.a != (char) -1 || s2.b.c.b != -1 || s2.b.c.c.b != -1) |
| 60 |
__builtin_abort (); |
| 61 |
__builtin_clear_padding (&s2.b.c); |
| 62 |
__builtin_memset (&s2.b.c + 1, 0, sizeof (union U) - sizeof (s2.b.c)); |
| 63 |
if (__builtin_memcmp (&s1, &s2, sizeof (s1))) |
| 64 |
__builtin_abort (); |
| 65 |
return 0; |
| 66 |
} |