1 /* Limit this to known non-strict alignment targets. */
2 /* { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } } */
3 /* { dg-options "-O -fsanitize=alignment -fsanitize-recover=alignment -Wno-address-of-packed-member" } */
4
5 struct R { int a; } r;
6 struct S { struct R a; char b; long long c; short d[10]; };
7 struct T { char a; long long b; };
8 struct U { char a; int b; int c; long long d; struct S e; struct T f; } __attribute__((packed));
9 struct V { long long a; struct S b; struct T c; struct U u; } v;
10
11 __attribute__((noinline, noclone)) int
bar(int x,struct R y,struct R z)12 bar (int x, struct R y, struct R z)
13 {
14 return x + y.a;
15 }
16
17 __attribute__((noinline, noclone)) int
foo(struct S * p,struct S * q)18 foo (struct S *p, struct S *q)
19 {
20 int i = bar (0, r, r);
21 i += bar (1, p->a, r);
22 i += bar (2, r, q->a);
23 return i;
24 }
25
26 int
main()27 main ()
28 {
29 char *p = (char *) &v.u.e;
30 struct S *q, *r;
31 asm volatile ("" : "=r" (q) : "0" (p));
32 asm volatile ("" : "=r" (r) : "0" (p));
33 if (foo (q, r) != 3)
34 __builtin_abort ();
35 return 0;
36 }
37
38 /* { dg-output "\.c:21:\[0-9]*: \[^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct S', which requires \[48] byte alignment.*" } */
39 /* { dg-output "\.c:22:\[0-9]*: \[^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct S', which requires \[48] byte alignment" } */
40