1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
/* { dg-do run } */
/* { dg-options "-fsanitize=bounds -Wall -Wextra -Wno-unused -Wno-array-bounds -Wno-uninitialized" } */
/* Test runtime errors. */
struct S { int a[10]; };
struct T { int a[5]; int s[2]; };
int
foo_5 (void)
{
return 5;
}
__attribute__ ((noinline, noclone))
void
fn_p (int p)
{
(void) p;
}
static void __attribute__ ((noinline, noclone))
fn1 (void)
{
volatile int a[5];
asm ("" : : "r" (&a) : "memory");
a[2] = a[5];
}
static void __attribute__ ((noinline, noclone))
fn2 (void)
{
volatile int a[5];
volatile int j;
int i = 5;
int *p = &i;
asm ("" : : "r" (&a) : "memory");
j = a[*p];
}
static void __attribute__ ((noinline, noclone))
fn3 (void)
{
volatile int a[5];
fn_p (a[5]);
}
static void __attribute__ ((noinline, noclone))
fn4 (void)
{
struct T t;
asm ("" : : "r" (&t.a) : "memory");
t.a[foo_5 ()] = 1;
}
static void __attribute__ ((noinline, noclone))
fn5 (void)
{
int i = 5;
volatile int a[i];
asm ("" : : "r" (&a) : "memory");
a[2] = a[i];
}
static void __attribute__ ((noinline, noclone))
fn6 (void)
{
int i = 5;
volatile int a[i];
volatile int j;
fn_p (a[i]);
asm ("" : : "r" (&a) : "memory");
j = a[foo_5 ()];
}
static void __attribute__ ((noinline, noclone))
fn7 (void)
{
int n = 5;
volatile int i;
volatile int c[n][n][n];
asm ("" : : "r" (&c[5]) : "memory");
i = c[5][2][2];
asm ("" : : "r" (&c[2]) : "memory");
i = c[2][5][2];
asm ("" : : "r" (&c[2]) : "memory");
i = c[2][2][5];
}
static void __attribute__ ((noinline, noclone))
fn8 (void)
{
volatile int i;
volatile struct S s;
asm ("" : : "r" (&s.a) : "memory");
i = s.a[10];
}
static void __attribute__ ((noinline, noclone))
fn9 (void)
{
long int *volatile d[10][5];
asm ("" : : "r" (&d[10]) : "memory");
d[8][3] = d[10][0];
}
static void __attribute__ ((noinline, noclone))
fn10 (void)
{
/* Beware of side-effects. */
volatile int x = 10;
volatile int e[20];
e[x++] = 3;
if (x != 11)
__builtin_abort ();
e[x--] = 3;
if (x != 10)
__builtin_abort ();
}
static void __attribute__ ((noinline, noclone))
fn11 (void)
{
char ***volatile f[5];
asm ("" : : "r" (&f) : "memory");
f[2] = f[5];
}
static void __attribute__ ((noinline, noclone))
fn12 (int i)
{
volatile int a[5] = { };
int k = i ? a[i] : i;
}
int
main (void)
{
fn1 ();
fn2 ();
fn3 ();
fn4 ();
fn5 ();
fn6 ();
fn7 ();
fn8 ();
fn9 ();
fn10 ();
fn11 ();
fn12 (5);
return 0;
}
/* { dg-output "index 5 out of bounds for type 'int \\\[5\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*index 5 out of bounds for type 'int \\\[5\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*index 5 out of bounds for type 'int \\\[5\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*index 5 out of bounds for type 'int \\\[5\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*index 5 out of bounds for type 'int \\\[\\\*\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*index 5 out of bounds for type 'int \\\[\\\*\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*index 5 out of bounds for type 'int \\\[\\\*\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*index 5 out of bounds for type 'int \\\[\\\*\\\]\\\[\\\*\\\]\\\[\\\*\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*index 5 out of bounds for type 'int \\\[\\\*\\\]\\\[\\\*\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*index 5 out of bounds for type 'int \\\[\\\*\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*index 10 out of bounds for type 'int \\\[10\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*index 10 out of bounds for type 'long int \\\*\\\[10\\\]\\\[5\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*index 5 out of bounds for type 'char \\\*\\\*\\\*\\\[5\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*index 5 out of bounds for type 'int \\\[5\\\]'" } */
|