Rebase.
[official-gcc.git] / gcc / testsuite / c-c++-common / ubsan / bounds-7.c
blobe08a3fd80ec2e9baf964a74d545944132e9862b2
1 /* { dg-do run } */
2 /* { dg-options "-fsanitize=bounds" } */
4 /* Test negative bounds. */
6 struct S { int a[10]; };
8 __attribute__ ((noinline, noclone))
9 void
10 fn1 (void)
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];
21 __attribute__ ((noinline, noclone))
22 void
23 fn2 (void)
25 volatile int i;
26 int m = 7;
27 volatile int a[m];
28 asm ("" : : "r" (&a) : "memory");
29 i = a[-1];
32 __attribute__ ((noinline, noclone))
33 void
34 fn3 (void)
36 volatile int i;
37 volatile struct S s;
38 asm ("" : : "r" (&s.a) : "memory");
39 i = s.a[-1];
42 int
43 main (void)
45 fn1 ();
46 fn2 ();
47 fn3 ();
48 return 0;
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\\\]'" } */