1/* { dg-do run } */
2/* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */
3/* { dg-options "-fsanitize=undefined" } */
4
5static char a[128];
6static int b[128];
7
8__attribute__ ((noinline, noclone)) int
9fn1 (int i)
10{
11  asm ("");
12  return a[i & 127];
13}
14
15__attribute__ ((noinline, noclone)) int
16fn2 (int i)
17{
18  asm ("");
19  return a[i & 128];
20}
21
22/* { dg-output "index 128 out of bounds for type 'char \\\[128\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
23/* { dg-output "\[^\n\r]*load of address \[^\n\r]* with insufficient space for an object of type 'char'\[^\n\r]*(\n|\r\n|\r)" } */
24/* { dg-output "\[^\n\r]*note: pointer points here\[^\n\r]*(\n|\r\n|\r)" } */
25/* { dg-output "\[^\n\r]*\[^\n\r]*(\n|\r\n|\r)" } */
26/* { dg-output "\[^\n\r]*\\^\[^\n\r]*(\n|\r\n|\r)" } */
27
28__attribute__ ((noinline, noclone)) int
29fn3 (int i)
30{
31  asm ("");
32  return b[i & 127];
33}
34
35__attribute__ ((noinline, noclone)) int
36fn4 (int i)
37{
38  asm ("");
39  return b[i & 128];
40}
41
42/* { dg-output "\[^\n\r]*index 128 out of bounds for type 'int \\\[128\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
43/* { dg-output "\[^\n\r]*load of address \[^\n\r]* with insufficient space for an object of type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
44/* { dg-output "\[^\n\r]*note: pointer points here\[^\n\r]*(\n|\r\n|\r)" } */
45/* { dg-output "\[^\n\r]*\[^\n\r]*(\n|\r\n|\r)" } */
46/* { dg-output "\[^\n\r]*\\^\[^\n\r]*(\n|\r\n|\r)" } */
47
48__attribute__ ((noinline, noclone)) int
49fn5 (int i, int j)
50{
51  asm ("");
52  return b[i & j];
53}
54
55/* { dg-output "\[^\n\r]*index 128 out of bounds for type 'int \\\[128\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
56/* { dg-output "\[^\n\r]*load of address \[^\n\r]* with insufficient space for an object of type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
57/* { dg-output "\[^\n\r]*note: pointer points here\[^\n\r]*(\n|\r\n|\r)" } */
58/* { dg-output "\[^\n\r]*\[^\n\r]*(\n|\r\n|\r)" } */
59/* { dg-output "\[^\n\r]*\\^\[^\n\r]*(\n|\r\n|\r)" } */
60
61__attribute__ ((noinline, noclone)) int
62fn6 (int i)
63{
64  asm ("");
65  return b[i & 0];
66}
67
68int
69main (void)
70{
71  fn1 (128);
72  fn2 (128);
73  fn3 (128);
74  fn4 (128);
75  fn5 (128, 127);
76  fn5 (128, 128);
77  fn6 (128);
78  return 0;
79}
80