| 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 -std=c++11" } |
| 4 |
|
| 5 |
#include <new> |
| 6 |
|
| 7 |
struct U |
| 8 |
{ |
| 9 |
int a; |
| 10 |
void foo () {} |
| 11 |
}; |
| 12 |
struct V |
| 13 |
{ |
| 14 |
V () : a (0) {}; |
| 15 |
~V () { a = 0; }; |
| 16 |
int a; |
| 17 |
void foo () {} |
| 18 |
static void bar () {} |
| 19 |
}; |
| 20 |
struct S { long int l; char buf[1 + sizeof (U) + 2 * sizeof (V)]; } s; |
| 21 |
|
| 22 |
int |
| 23 |
main (void) |
| 24 |
{ |
| 25 |
U *p = (U *) &s.buf[1]; |
| 26 |
p->foo (); |
| 27 |
char *q = &s.buf[1 + sizeof (U)]; |
| 28 |
V *u = new (q) V; |
| 29 |
u->a = 1; |
| 30 |
u->~V (); |
| 31 |
V *v = new (&s.buf[1 + sizeof (U) + sizeof (V)]) V; |
| 32 |
v->foo (); |
| 33 |
v->bar (); // We don't instrument this right now. |
| 34 |
v->~V (); |
| 35 |
} |
| 36 |
|
| 37 |
// { dg-output "\.C:26:\[0-9]*:\[\^\n\r]*member call on misaligned address 0x\[0-9a-fA-F]* for type 'struct U', which requires 4 byte alignment.*" } |
| 38 |
// { dg-output "\.C:28:\[0-9]*:\[\^\n\r]*constructor call on misaligned address 0x\[0-9a-fA-F]* for type 'struct V', which requires 4 byte alignment.*" } |
| 39 |
// { dg-output "\.C:14:\[0-9]*:\[\^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct V', which requires 4 byte alignment.*" } |
| 40 |
// { dg-output "\.C:29:\[0-9]*:\[\^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct V', which requires 4 byte alignment.*" } |
| 41 |
// { dg-output "\.C:30:\[0-9]*:\[\^\n\r]*member call on misaligned address 0x\[0-9a-fA-F]* for type 'struct V', which requires 4 byte alignment.*" } |
| 42 |
// { dg-output "\.C:15:\[0-9]*:\[\^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct V', which requires 4 byte alignment.*" } |
| 43 |
// { dg-output "\.C:31:\[0-9]*:\[\^\n\r]*constructor call on misaligned address 0x\[0-9a-fA-F]* for type 'struct V', which requires 4 byte alignment.*" } |
| 44 |
// { dg-output "\.C:32:\[0-9]*:\[\^\n\r]*member call on misaligned address 0x\[0-9a-fA-F]* for type 'struct V', which requires 4 byte alignment.*" } |
| 45 |
// { dg-output "\.C:34:\[0-9]*:\[\^\n\r]*member call on misaligned address 0x\[0-9a-fA-F]* for type 'struct V', which requires 4 byte alignment" } |