Debian Codegraph @

gcc/testsuite/c-c++-common/ubsan/bounds-6.c

raw
1 /* { dg-do run } */
2 /* { dg-options "-fsanitize=bounds -Wall -Wextra -Wno-array-bounds" } */
3
4 /* Test off-by-one. */
5
6 struct S { int a; int b; } s[4], *t;
7 struct U { int a[10]; } u[4], *v;
8 volatile int *a, *b, *c;
9 volatile void *d;
10 volatile int e[4][4];
11
12 int
13 main (void)
14 {
15 t = &s[4]; // OK
16 a = &s[4].a; // Error
17 b = &s[4].b; // Error
18 d = &e[4]; // OK
19 c = &e[4][0]; // Error
20 c = &e[3][4]; // OK
21 c = &e[3][3]; // OK
22
23 a = &u[4].a[9]; // Error
24 a = &u[4].a[10]; // Error
25 a = &u[3].a[9]; // OK
26 a = &u[3].a[10]; // OK
27 a = &u[3].a[11]; // Error, warns with -Warray-bounds, but only if VRP runs
28
29 return 0;
30 }
31
32 /* { dg-output "index 4 out of bounds for type 'S \\\[4\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
33 /* { dg-output "\[^\n\r]*index 4 out of bounds for type 'S \\\[4\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
34 /* { dg-output "\[^\n\r]*index 4 out of bounds for type 'int \\\[4\\\]\\\[4\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
35 /* { dg-output "\[^\n\r]*index 4 out of bounds for type 'U \\\[4\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
36 /* { dg-output "\[^\n\r]*index 4 out of bounds for type 'U \\\[4\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
37 /* { dg-output "\[^\n\r]*index 11 out of bounds for type 'int \\\[10\\\]'" } */