Merge from trunk:
[official-gcc.git] / main / gcc / testsuite / c-c++-common / ubsan / align-3.c
bloba509fa992e566d0f19e1f73814998358a1b5a57a
1 /* { dg-do run } */
2 /* { dg-options "-fsanitize=undefined -fno-sanitize-recover" } */
4 int c;
6 __attribute__((noinline, noclone)) void
7 f1 (int *a, char *b)
9 __builtin_memcpy (a, b, sizeof (*a));
12 __attribute__((noinline, noclone)) void
13 f2 (int *a, char *b)
15 __builtin_memcpy (b, a, sizeof (*a));
18 __attribute__((noinline, noclone)) void
19 f3 (char *b)
21 __builtin_memcpy (&c, b, sizeof (c));
24 __attribute__((noinline, noclone)) void
25 f4 (char *b)
27 __builtin_memcpy (b, &c, sizeof (c));
30 struct T
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));
43 __attribute__((noinline, noclone)) int
44 f5 (struct T *p)
46 return p->a + p->b + p->c + p->d + p->e + p->f + p->g + p->h + p->i;
49 int
50 main ()
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;