1 /* { dg-do run } */
2 /* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */
3 /* { dg-options "-fsanitize=undefined" } */
4
5 static char a[128] __attribute__ ((aligned(4096)));
6 static int b[128] __attribute__ ((aligned(4096)));
7
8 __attribute__ ((noinline, noclone)) int
fn1(int i)9 fn1 (int i)
10 {
11 asm ("");
12 return a[i & 127];
13 }
14
15 __attribute__ ((noinline, noclone)) int
fn2(int i)16 fn2 (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
fn3(int i)29 fn3 (int i)
30 {
31 asm ("");
32 return b[i & 127];
33 }
34
35 __attribute__ ((noinline, noclone)) int
fn4(int i)36 fn4 (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
fn5(int i,int j)49 fn5 (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]*\\^" } */
60
61 __attribute__ ((noinline, noclone)) int
fn6(int i)62 fn6 (int i)
63 {
64 asm ("");
65 return b[i & 0];
66 }
67
68 int
main(void)69 main (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