| 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 -Wall -Wno-unused-variable -Wno-address-of-packed-member -std=c++11" } |
| 4 |
|
| 5 |
typedef const long int L; |
| 6 |
struct S { long int l; char buf[1 + sizeof (int) + sizeof (L)]; } s; |
| 7 |
struct T { char a; int b; long int c; } __attribute__((packed)); |
| 8 |
struct U { long int a; struct T b; } u; |
| 9 |
|
| 10 |
int |
| 11 |
main (void) |
| 12 |
{ |
| 13 |
int *p = (int *) &s.buf[1]; |
| 14 |
L *l = (L *) &s.buf[1 + sizeof(int)]; |
| 15 |
|
| 16 |
int &r = *p; |
| 17 |
auto &r2 = *p; |
| 18 |
L &lr = *l; |
| 19 |
|
| 20 |
// Try an rvalue reference. |
| 21 |
auto &&r3 = *p; |
| 22 |
|
| 23 |
// Don't evaluate the reference initializer twice. |
| 24 |
int i = 1; |
| 25 |
int *q = &i; |
| 26 |
int &qr = ++*q; |
| 27 |
if (i != 2) |
| 28 |
__builtin_abort (); |
| 29 |
|
| 30 |
int *s = &u.b.b; |
| 31 |
L *t = &u.b.c; |
| 32 |
int &r4 = *s; |
| 33 |
auto &r5 = *s; |
| 34 |
L &lr2 = *t; |
| 35 |
auto &&r6 = *s; |
| 36 |
} |
| 37 |
|
| 38 |
// { dg-output "\.C:16:\[0-9]*:\[\^\n\r]*reference binding to misaligned address 0x\[0-9a-fA-F]* for type 'int', which requires 4 byte alignment.*" } |
| 39 |
// { dg-output "\.C:17:\[0-9]*:\[\^\n\r]*reference binding to misaligned address 0x\[0-9a-fA-F]* for type 'int', which requires 4 byte alignment.*" } |
| 40 |
// { dg-output "\.C:18:\[0-9]*:\[\^\n\r]*reference binding to misaligned address 0x\[0-9a-fA-F]* for type 'const L', which requires \[48] byte alignment.*" } |
| 41 |
// { dg-output "\.C:21:\[0-9]*:\[\^\n\r]*reference binding to misaligned address 0x\[0-9a-fA-F]* for type 'int', which requires 4 byte alignment.*" } |
| 42 |
// { dg-output "\.C:32:\[0-9]*:\[\^\n\r]*reference binding to misaligned address 0x\[0-9a-fA-F]* for type 'int', which requires 4 byte alignment.*" } |
| 43 |
// { dg-output "\.C:33:\[0-9]*:\[\^\n\r]*reference binding to misaligned address 0x\[0-9a-fA-F]* for type 'int', which requires 4 byte alignment.*" } |
| 44 |
// { dg-output "\.C:34:\[0-9]*:\[\^\n\r]*reference binding to misaligned address 0x\[0-9a-fA-F]* for type 'const L', which requires \[48] byte alignment.*" } |
| 45 |
// { dg-output "\.C:35:\[0-9]*:\[\^\n\r]*reference binding to misaligned address 0x\[0-9a-fA-F]* for type 'int', which requires 4 byte alignment" } |