1/* { dg-do run } */
2/* { dg-options "-fsanitize=bounds" } */
3
4/* Test negative bounds.  */
5
6struct S { int a[10]; };
7
8__attribute__ ((noinline, noclone))
9void
10fn1 (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))
22void
23fn2 (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))
33void
34fn3 (void)
35{
36  volatile int i;
37  volatile struct S s;
38  asm ("" : : "r" (&s.a) : "memory");
39  i = s.a[-1];
40}
41
42int
43main (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\\\]'" } */
55