| 1 |
/* PR sanitizer/71498 */ |
| 2 |
/* { dg-do run } */ |
| 3 |
/* { dg-options "-fsanitize=bounds -Wno-array-bounds" } */ |
| 4 |
/* { dg-options "-fsanitize=bounds -Wno-array-bounds -Wno-volatile" { target c++ } } */ |
| 5 |
|
| 6 |
struct S { int a[100]; int b, c; } s; |
| 7 |
|
| 8 |
__attribute__((noinline, noclone)) int |
| 9 |
foo (int x) |
| 10 |
{ |
| 11 |
return s.a[x]; |
| 12 |
} |
| 13 |
|
| 14 |
__attribute__((noinline, noclone)) int |
| 15 |
bar (int x) |
| 16 |
{ |
| 17 |
static int *d = &s.a[99]; |
| 18 |
asm volatile ("" : : "r" (&d)); |
| 19 |
return s.a[x]; |
| 20 |
} |
| 21 |
|
| 22 |
int |
| 23 |
main () |
| 24 |
{ |
| 25 |
volatile int a = 0; |
| 26 |
a += foo (100); |
| 27 |
a += bar (100); |
| 28 |
return 0; |
| 29 |
} |
| 30 |
|
| 31 |
/* { dg-output "index 100 out of bounds for type 'int \\\[100\\\]'\[^\n\r]*(\n|\r\n|\r)" } */ |
| 32 |
/* { dg-output "\[^\n\r]*index 100 out of bounds for type 'int \\\[100\\\]'\[^\n\r]*(\n|\r\n|\r)" } */ |