| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-fsanitize=undefined -fno-sanitize-recover=undefined" } */ |
| 3 |
|
| 4 |
int c; |
| 5 |
|
| 6 |
__attribute__((noinline, noclone)) void |
| 7 |
f1 (int *a, char *b) |
| 8 |
{ |
| 9 |
__builtin_memcpy (a, b, sizeof (*a)); |
| 10 |
} |
| 11 |
|
| 12 |
__attribute__((noinline, noclone)) void |
| 13 |
f2 (int *a, char *b) |
| 14 |
{ |
| 15 |
__builtin_memcpy (b, a, sizeof (*a)); |
| 16 |
} |
| 17 |
|
| 18 |
__attribute__((noinline, noclone)) void |
| 19 |
f3 (char *b) |
| 20 |
{ |
| 21 |
__builtin_memcpy (&c, b, sizeof (c)); |
| 22 |
} |
| 23 |
|
| 24 |
__attribute__((noinline, noclone)) void |
| 25 |
f4 (char *b) |
| 26 |
{ |
| 27 |
__builtin_memcpy (b, &c, sizeof (c)); |
| 28 |
} |
| 29 |
|
| 30 |
struct T |
| 31 |
{ |
| 32 |
char a; |
| 33 |
short b; |
| 34 |
int c; |
| 35 |
long d; |
| 36 |
long long e; |
| 37 |
short f; |
| 38 |
float g; |
| 39 |
double h; |
| 40 |
long double i; |
| 41 |
} __attribute__((packed)); |
| 42 |
|
| 43 |
__attribute__((noinline, noclone)) int |
| 44 |
f5 (struct T *p) |
| 45 |
{ |
| 46 |
return p->a + p->b + p->c + p->d + p->e + p->f + p->g + p->h + p->i; |
| 47 |
} |
| 48 |
|
| 49 |
int |
| 50 |
main () |
| 51 |
{ |
| 52 |
struct S { int a; char b[sizeof (int) + 1]; } s; |
| 53 |
s.a = 6; |
| 54 |
f2 (&s.a, &s.b[1]); |
| 55 |
f1 (&s.a, &s.b[1]); |
| 56 |
c = s.a + 1; |
| 57 |
f4 (&s.b[1]); |
| 58 |
f3 (&s.b[1]); |
| 59 |
if (c != 7 || s.a != 6) |
| 60 |
__builtin_abort (); |
| 61 |
struct U { long long a; long double b; char c; struct T d; } u; |
| 62 |
__builtin_memset (&u, 0, sizeof (u)); |
| 63 |
if (f5 (&u.d) != 0) |
| 64 |
__builtin_abort (); |
| 65 |
return 0; |
| 66 |
} |