| 1 |
/* PR sanitizer/108894 */ |
| 2 |
/* { dg-do run } */ |
| 3 |
/* { dg-options "-fsanitize=bounds -fsanitize-recover=bounds" } */ |
| 4 |
/* { dg-output "index 15 out of bounds for type 'int \\\[15\\\]'\[^\n\r]*(\n|\r\n|\r)" } */ |
| 5 |
/* { dg-output "\[^\n\r]*index 0 out of bounds for type 'int \\\[\\\*\\\]'\[^\n\r]*(\n|\r\n|\r)" } */ |
| 6 |
/* { dg-output "\[^\n\r]*index 16 out of bounds for type 'int \\\[15\\\]'" } */ |
| 7 |
|
| 8 |
struct A { int a; int b[]; }; |
| 9 |
struct B { int a; int b[0]; }; |
| 10 |
struct C { int a; int b[1]; }; |
| 11 |
struct D { int a; int b[2]; }; |
| 12 |
struct E { int a; int b[42]; }; |
| 13 |
struct F { int a; int b[0]; int c[2]; }; |
| 14 |
struct G { int a; int b[15]; int c[2]; }; |
| 15 |
|
| 16 |
__attribute__((noipa)) int |
| 17 |
foo (struct A *a) |
| 18 |
{ |
| 19 |
return a->b[14]; |
| 20 |
} |
| 21 |
|
| 22 |
__attribute__((noipa)) int |
| 23 |
bar (struct B *a) |
| 24 |
{ |
| 25 |
return a->b[0]; |
| 26 |
} |
| 27 |
|
| 28 |
__attribute__((noipa)) int |
| 29 |
baz (struct C *a) |
| 30 |
{ |
| 31 |
return a->b[1]; |
| 32 |
} |
| 33 |
|
| 34 |
__attribute__((noipa)) int |
| 35 |
qux (struct D *a) |
| 36 |
{ |
| 37 |
return a->b[2]; |
| 38 |
} |
| 39 |
|
| 40 |
__attribute__((noipa)) int |
| 41 |
corge (struct E *a) |
| 42 |
{ |
| 43 |
return a->b[14]; |
| 44 |
} |
| 45 |
|
| 46 |
__attribute__((noipa)) int |
| 47 |
freddy (struct F *a) |
| 48 |
{ |
| 49 |
return a->b[0]; |
| 50 |
} |
| 51 |
|
| 52 |
__attribute__((noipa)) int |
| 53 |
garply (struct G *a) |
| 54 |
{ |
| 55 |
return a->b[15]; |
| 56 |
} |
| 57 |
|
| 58 |
__attribute__((noipa)) int |
| 59 |
waldo (struct G *a) |
| 60 |
{ |
| 61 |
return a->b[16]; |
| 62 |
} |
| 63 |
|
| 64 |
int |
| 65 |
main () |
| 66 |
{ |
| 67 |
union { struct A a; struct B b; struct C c; |
| 68 |
struct D d; struct E e; struct F f; } u; |
| 69 |
struct G g; |
| 70 |
u.e.a = 42; |
| 71 |
__builtin_memset (u.e.b, 0, sizeof (u.e.b)); |
| 72 |
__builtin_memset (&g, 0, sizeof (g)); |
| 73 |
int r = garply (&g); |
| 74 |
r += foo (&u.a) + bar (&u.b) + baz (&u.c); |
| 75 |
r += qux (&u.d) + corge (&u.e) + freddy (&u.f); |
| 76 |
r += waldo (&g); |
| 77 |
if (r != 0) |
| 78 |
__builtin_abort (); |
| 79 |
} |