| 1 |
/* Limit this to known non-strict alignment targets. */ |
| 2 |
/* { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } } */ |
| 3 |
/* { dg-options "-fsanitize=alignment -Wno-address-of-packed-member" } */ |
| 4 |
|
| 5 |
struct S { int a; char b; long long c; short d[10]; }; |
| 6 |
struct T { char a; long long b; }; |
| 7 |
struct U { char a; int b; int c; long long d; struct S e; struct T f; } __attribute__((packed)); |
| 8 |
struct V { long long a; struct S b; struct T c; struct U u; } v; |
| 9 |
|
| 10 |
__attribute__((noinline, noclone)) void |
| 11 |
f1 (int *p, int *q, char *r, long long *s) |
| 12 |
{ |
| 13 |
*p = |
| 14 |
*q |
| 15 |
+ *r |
| 16 |
+ *s; |
| 17 |
} |
| 18 |
|
| 19 |
|
| 20 |
__attribute__((noinline, noclone)) int |
| 21 |
f2 (struct S *p) |
| 22 |
{ |
| 23 |
return p->a; |
| 24 |
} |
| 25 |
|
| 26 |
__attribute__((noinline, noclone)) long long |
| 27 |
f3 (struct S *p, int i) |
| 28 |
{ |
| 29 |
return p->c |
| 30 |
+ p->d[1] |
| 31 |
+ p->d[i]; |
| 32 |
} |
| 33 |
|
| 34 |
__attribute__((noinline, noclone)) long long |
| 35 |
f4 (long long *p) |
| 36 |
{ |
| 37 |
return *p; |
| 38 |
} |
| 39 |
|
| 40 |
int |
| 41 |
main () |
| 42 |
{ |
| 43 |
f1 (&v.u.b, &v.u.c, &v.u.a, &v.u.d); |
| 44 |
if (f2 (&v.u.e) + f3 (&v.u.e, 4) + f4 (&v.u.f.b) != 0) |
| 45 |
__builtin_abort (); |
| 46 |
return 0; |
| 47 |
} |
| 48 |
|
| 49 |
/* { dg-output "\.c:(14|15):\[0-9]*: \[^\n\r]*load of misaligned address 0x\[0-9a-fA-F]* for type 'int', which requires 4 byte alignment.*" } */ |
| 50 |
/* { dg-output "\.c:16:\[0-9]*: \[^\n\r]*load of misaligned address 0x\[0-9a-fA-F]* for type 'long long int', which requires \[48] byte alignment.*" } */ |
| 51 |
/* { dg-output "\.c:(13|16):\[0-9]*: \[^\n\r]*store to misaligned address 0x\[0-9a-fA-F]* for type 'int', which requires 4 byte alignment.*" } */ |
| 52 |
/* { dg-output "\.c:23:\[0-9]*: \[^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct S', which requires \[48] byte alignment.*" } */ |
| 53 |
/* { dg-output "\.c:(29|30):\[0-9]*: \[^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct S', which requires \[48] byte alignment.*" } */ |
| 54 |
/* { dg-output "\.c:30:\[0-9]*: \[^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct S', which requires \[48] byte alignment.*" } */ |
| 55 |
/* { dg-output "\.c:31:\[0-9]*: \[^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct S', which requires \[48] byte alignment.*" } */ |
| 56 |
/* { dg-output "\.c:37:\[0-9]*: \[^\n\r]*load of misaligned address 0x\[0-9a-fA-F]* for type 'long long int', which requires \[48] byte alignment" } */ |