@@ -109,7 +109,6 @@ void testQualifiedParameters(const int * p, const int * const q, const int a[10]
109
109
q[1 ], 1 [q], q[-1 ], // expected-note3{{used in buffer access here}}
110
110
a[1 ], // expected-note{{used in buffer access here}} `a` is of pointer type
111
111
b[1 ][2 ] // expected-note{{used in buffer access here}} `b[1]` is of array type
112
- // expected-warning@-1{{unsafe buffer access}}
113
112
);
114
113
}
115
114
@@ -128,29 +127,41 @@ T_t funRetT();
128
127
T_t * funRetTStar ();
129
128
130
129
void testStructMembers (struct T * sp, struct T s, T_t * sp2, T_t s2) {
131
- foo (sp->a [1 ], // expected-warning{{unsafe buffer access}}
130
+ foo (sp->a [1 ],
132
131
sp->b [1 ], // expected-warning{{unsafe buffer access}}
133
- sp->c .a [1 ], // expected-warning{{unsafe buffer access}}
132
+ sp->c .a [1 ],
134
133
sp->c .b [1 ], // expected-warning{{unsafe buffer access}}
135
- s.a [1 ], // expected-warning{{unsafe buffer access}}
134
+ s.a [1 ],
136
135
s.b [1 ], // expected-warning{{unsafe buffer access}}
137
- s.c .a [1 ], // expected-warning{{unsafe buffer access}}
136
+ s.c .a [1 ],
138
137
s.c .b [1 ], // expected-warning{{unsafe buffer access}}
139
- sp2->a [1 ], // expected-warning{{unsafe buffer access}}
138
+ sp2->a [1 ],
140
139
sp2->b [1 ], // expected-warning{{unsafe buffer access}}
141
- sp2->c .a [1 ], // expected-warning{{unsafe buffer access}}
140
+ sp2->c .a [1 ],
142
141
sp2->c .b [1 ], // expected-warning{{unsafe buffer access}}
143
- s2.a [1 ], // expected-warning{{unsafe buffer access}}
142
+ s2.a [1 ],
144
143
s2.b [1 ], // expected-warning{{unsafe buffer access}}
145
- s2.c .a [1 ], // expected-warning{{unsafe buffer access}}
144
+ s2.c .a [1 ],
146
145
s2.c .b [1 ], // expected-warning{{unsafe buffer access}}
147
- funRetT ().a [1 ], // expected-warning{{unsafe buffer access}}
146
+ funRetT ().a [1 ],
148
147
funRetT ().b [1 ], // expected-warning{{unsafe buffer access}}
149
- funRetTStar ()->a [1 ], // expected-warning{{unsafe buffer access}}
148
+ funRetTStar ()->a [1 ],
150
149
funRetTStar ()->b [1 ] // expected-warning{{unsafe buffer access}}
151
150
);
152
151
}
153
152
153
+ union Foo {
154
+ bool b;
155
+ int arr[10 ];
156
+ };
157
+
158
+ int testUnionMembers (Foo f) {
159
+ int a = f.arr [0 ];
160
+ a = f.arr [5 ];
161
+ a = f.arr [10 ]; // expected-warning{{unsafe buffer access}}
162
+ return a;
163
+ }
164
+
154
165
int garray[10 ]; // expected-warning{{'garray' is an unsafe buffer that does not perform bounds checks}}
155
166
int * gp = garray; // expected-warning{{'gp' is an unsafe pointer used for buffer access}}
156
167
int gvar = gp[1 ]; // FIXME: file scope unsafe buffer access is not warned
@@ -213,7 +224,6 @@ void testTypedefs(T_ptr_t p) {
213
224
// expected-warning@-1{{'p' is an unsafe pointer used for buffer access}}
214
225
foo (p[1 ], // expected-note{{used in buffer access here}}
215
226
p[1 ].a [1 ], // expected-note{{used in buffer access here}}
216
- // expected-warning@-1{{unsafe buffer access}}
217
227
p[1 ].b [1 ] // expected-note{{used in buffer access here}}
218
228
// expected-warning@-1{{unsafe buffer access}}
219
229
);
@@ -223,10 +233,9 @@ template<typename T, int N> T f(T t, T * pt, T a[N], T (&b)[N]) {
223
233
// expected-warning@-1{{'t' is an unsafe pointer used for buffer access}}
224
234
// expected-warning@-2{{'pt' is an unsafe pointer used for buffer access}}
225
235
// expected-warning@-3{{'a' is an unsafe pointer used for buffer access}}
226
- // expected-warning@-4{{'b' is an unsafe buffer that does not perform bounds checks}}
227
236
foo (pt[1 ], // expected-note{{used in buffer access here}}
228
237
a[1 ], // expected-note{{used in buffer access here}}
229
- b[1 ]); // expected-note{{used in buffer access here}}
238
+ b[1 ]);
230
239
return &t[1 ]; // expected-note{{used in buffer access here}}
231
240
}
232
241
@@ -376,7 +385,7 @@ int testArrayAccesses(int n, int idx) {
376
385
typedef int A[3 ];
377
386
const A tArr = {4 , 5 , 6 };
378
387
foo (tArr[0 ], tArr[1 ]);
379
- return cArr[0 ][1 ]; // expected-warning{{unsafe buffer access}}
388
+ return cArr[0 ][1 ];
380
389
}
381
390
382
391
void testArrayPtrArithmetic (int x[]) { // expected-warning{{'x' is an unsafe pointer used for buffer access}}
0 commit comments