| 1 |
/* Test the attribute counted_by and its usage in bounds |
| 2 |
sanitizer. when counted_by field is negative value. */ |
| 3 |
/* { dg-do run } */ |
| 4 |
/* { dg-options "-fsanitize=bounds" } */ |
| 5 |
|
| 6 |
#include <stdlib.h> |
| 7 |
|
| 8 |
struct annotated { |
| 9 |
int b; |
| 10 |
int c[] __attribute__ ((counted_by (b))); |
| 11 |
} *array_annotated; |
| 12 |
|
| 13 |
void __attribute__((__noinline__)) setup (int annotated_count) |
| 14 |
{ |
| 15 |
array_annotated |
| 16 |
= (struct annotated *)malloc (sizeof (struct annotated)); |
| 17 |
array_annotated->b = annotated_count; |
| 18 |
|
| 19 |
return; |
| 20 |
} |
| 21 |
|
| 22 |
void __attribute__((__noinline__)) test (int annotated_index) |
| 23 |
{ |
| 24 |
array_annotated->c[annotated_index] = 2; |
| 25 |
} |
| 26 |
|
| 27 |
int main(int argc, char *argv[]) |
| 28 |
{ |
| 29 |
setup (-3); |
| 30 |
test (2); |
| 31 |
return 0; |
| 32 |
} |
| 33 |
|
| 34 |
/* { dg-output "24:21: runtime error: index 2 out of bounds for type" } */ |