1/* { dg-do run } */ 2/* { dg-options "-fsanitize=undefined -fno-sanitize-recover=undefined" } */ 3 4int c; 5 6__attribute__((noinline, noclone)) void 7f1 (int *a, char *b) 8{ 9 __builtin_memcpy (a, b, sizeof (*a)); 10} 11 12__attribute__((noinline, noclone)) void 13f2 (int *a, char *b) 14{ 15 __builtin_memcpy (b, a, sizeof (*a)); 16} 17 18__attribute__((noinline, noclone)) void 19f3 (char *b) 20{ 21 __builtin_memcpy (&c, b, sizeof (c)); 22} 23 24__attribute__((noinline, noclone)) void 25f4 (char *b) 26{ 27 __builtin_memcpy (b, &c, sizeof (c)); 28} 29 30struct 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 44f5 (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 49int 50main () 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} 67