blob: 5b66cdc0aab1a475cf5c0dde281a204655b332c3 (
plain)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
/* PR middle-end/94940 - spurious -Warray-bounds for a zero length array
member of union
{ dg-do compile }
{ dg-options "-O2 -Wall" } */
extern int n;
extern union Ua3_a0 {
int a3[3];
int a2[2]; // can only alias a3[0 - 2]
int a1[1]; // can alias all of the union
int a0[0]; // ditto
} ua3_a0;
void test_ua3_ua0_a0 (int i)
{
ua3_a0.a0[0] = 0; // { dg-bogus "\\\[-Warray-bounds" }
ua3_a0.a0[1] = 0; // { dg-bogus "\\\[-Warray-bounds" }
ua3_a0.a0[2] = 0; // { dg-bogus "\\\[-Warray-bounds" }
ua3_a0.a0[3] = 0; // { dg-warning "\\\[-Warray-bounds" }
ua3_a0.a0[4] = 0; // { dg-warning "\\\[-Warray-bounds" }
ua3_a0.a0[i] = 0; // { dg-bogus "\\\[-Warray-bounds" }
if (i < __LINE__)
i = 5;
ua3_a0.a0[i] = 0; // { dg-warning "\\\[-Warray-bounds" }
if (i > -1)
i = -1;
ua3_a0.a0[i] = 0; // { dg-warning "\\\[-Warray-bounds" }
}
void test_ua3_ua0_a1 (int i)
{
/* Abusing one-element array members the same way as those of
length zero is discouraged but so far acceted without warnings.
This should change at some point. */
ua3_a0.a1[0] = 0;
ua3_a0.a1[1] = 0;
ua3_a0.a1[2] = 0;
ua3_a0.a1[3] = 0; // { dg-warning "\\\[-Warray-bounds" }
ua3_a0.a1[i] = 0;
if (i > -1)
i = -1;
ua3_a0.a1[i] = 0; // { dg-warning "\\\[-Warray-bounds" }
if (i < 7)
i = 7;
ua3_a0.a1[i] = 0; // { dg-warning "\\\[-Warray-bounds" }
}
void test_ua3_ua0_a2 (int i)
{
ua3_a0.a2[0] = 0;
ua3_a0.a2[1] = 0;
ua3_a0.a2[2] = 0; // { dg-warning "\\\[-Warray-bounds" }
ua3_a0.a2[i] = 0;
if (i < __LINE__)
i = __LINE__;
ua3_a0.a2[i] = 0; // { dg-warning "\\\[-Warray-bounds" }
if (i > -1)
i = -1;
ua3_a0.a2[i] = 0; // { dg-warning "\\\[-Warray-bounds" }
}
extern union Ua2_a3 {
int a2[2]; // can only alias a3[0 - 1]
int a3[3];
} ua2_a3;
void test_ua2_ua3 (int i)
{
ua2_a3.a2[0] = 0; // { dg-bogus "\\\[-Warray-bounds" }
ua2_a3.a2[1] = 0; // { dg-bogus "\\\[-Warray-bounds" }
ua2_a3.a2[2] = 0; // { dg-warning "\\\[-Warray-bounds" }
ua2_a3.a2[i] = 0;
if (i < __LINE__)
i = __LINE__;
ua2_a3.a2[i] = 0; // { dg-warning "\\\[-Warray-bounds" }
}
extern struct SUa2_a0 {
union Ua2_a0 {
int a2[2];
int a0[0];
} u;
} sua2_a0;
void test_sua2_sua0 (int i)
{
n += sua2_a0.u.a0[0];
n += sua2_a0.u.a0[1];
n += sua2_a0.u.a0[2]; // { dg-warning "\\\[-Warray-bounds" }
n += sua2_a0.u.a0[i];
if (i < __LINE__)
i = __LINE__;
n += sua2_a0.u.a0[i]; // { dg-warning "\\\[-Warray-bounds" }
}
void test_sua2_sua0_ptr (int i)
{
union Ua2_a0 *p = &sua2_a0.u;
n += p->a0[0];
n += p->a0[1];
n += p->a0[2]; // { dg-warning "\\\[-Warray-bounds" }
n += p->a0[i];
}
extern struct SUSa3_a0 {
union USa3_a0 {
struct {
int a3[3];
} s;
int a2[2]; // can alias s.a3[0 - 2]
int a1[1]; // can alias s.a3[0 - 2]
int a0[0]; // can alias s.a3[0]
} u;
} susa3_ua0;
void test_susa3_sua0 (int i, int j)
{
n += susa3_ua0.u.a0[0];
n += susa3_ua0.u.a0[1];
n += susa3_ua0.u.a0[2];
n += susa3_ua0.u.a0[3]; // { dg-warning "\\\[-Warray-bounds" }
}
void test_susa3_sua0_ptr (int i, int j)
{
union USa3_a0 *p = &susa3_ua0.u;
n += p->a0[0];
n += p->a0[1];
n += p->a0[2];
n += p->a0[3]; // { dg-warning "\\\[-Warray-bounds" }
}
void test_susa3_sua1 (int i)
{
n += susa3_ua0.u.a1[0];
n += susa3_ua0.u.a1[1];
n += susa3_ua0.u.a1[2];
n += susa3_ua0.u.a1[3]; // { dg-warning "\\\[-Warray-bounds" }
if (i < __LINE__)
i = __LINE__;
n += susa3_ua0.u.a1[i]; // { dg-warning "\\\[-Warray-bounds" }
}
void test_susa3_sua2 (void)
{
n += susa3_ua0.u.a2[0];
n += susa3_ua0.u.a2[1];
n += susa3_ua0.u.a2[2]; // { dg-warning "\\\[-Warray-bounds" }
n += susa3_ua0.u.a2[3]; // { dg-warning "\\\[-Warray-bounds" }
}
extern struct {
union {
struct {
int a3[3];
} s1;
struct {
int a0[0];
} s2;
} u;
} susa3_usa0;
void test_susi3_susi0 (int i)
{
n += susa3_usa0.u.s2.a0[0];
n += susa3_usa0.u.s2.a0[1];
n += susa3_usa0.u.s2.a0[2];
n += susa3_usa0.u.s2.a0[3]; // { dg-warning "\\\[-Warray-bounds" }
n += susa3_usa0.u.s2.a0[i];
if (i < __LINE__)
i = __LINE__;
n += susa3_usa0.u.s2.a0[i]; // { dg-warning "\\\[-Warray-bounds" }
}
|