| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-fsanitize=bounds" } */ |
| 3 |
|
| 4 |
/* Test negative bounds. */ |
| 5 |
|
| 6 |
struct S { int a[10]; }; |
| 7 |
|
| 8 |
__attribute__ ((noinline, noclone)) |
| 9 |
void |
| 10 |
fn1 (void) |
| 11 |
{ |
| 12 |
volatile int i; |
| 13 |
int m = -1; |
| 14 |
volatile int a[7]; |
| 15 |
asm ("" : : "r" (&a) : "memory"); |
| 16 |
i = a[-1]; |
| 17 |
asm ("" : : "r" (&a) : "memory"); |
| 18 |
i = a[m]; |
| 19 |
} |
| 20 |
|
| 21 |
__attribute__ ((noinline, noclone)) |
| 22 |
void |
| 23 |
fn2 (void) |
| 24 |
{ |
| 25 |
volatile int i; |
| 26 |
int m = 7; |
| 27 |
volatile int a[m]; |
| 28 |
asm ("" : : "r" (&a) : "memory"); |
| 29 |
i = a[-1]; |
| 30 |
} |
| 31 |
|
| 32 |
__attribute__ ((noinline, noclone)) |
| 33 |
void |
| 34 |
fn3 (void) |
| 35 |
{ |
| 36 |
volatile int i; |
| 37 |
volatile struct S s; |
| 38 |
asm ("" : : "r" (&s.a) : "memory"); |
| 39 |
i = s.a[-1]; |
| 40 |
} |
| 41 |
|
| 42 |
int |
| 43 |
main (void) |
| 44 |
{ |
| 45 |
fn1 (); |
| 46 |
fn2 (); |
| 47 |
fn3 (); |
| 48 |
return 0; |
| 49 |
} |
| 50 |
|
| 51 |
/* { dg-output "index -1 out of bounds for type 'int \\\[7\\\]'\[^\n\r]*(\n|\r\n|\r)" } */ |
| 52 |
/* { dg-output "\[^\n\r]*index -1 out of bounds for type 'int \\\[7\\\]'\[^\n\r]*(\n|\r\n|\r)" } */ |
| 53 |
/* { dg-output "\[^\n\r]*index -1 out of bounds for type 'int \\\[\\\*\\\]'\[^\n\r]*(\n|\r\n|\r)" } */ |
| 54 |
/* { dg-output "\[^\n\r]*index -1 out of bounds for type 'int \\\[10\\\]'" } */ |