@@ -109,7 +109,6 @@ void testQualifiedParameters(const int * p, const int * const q, const int a[10]
109109 q[1 ], 1 [q], q[-1 ], // expected-note3{{used in buffer access here}}
110110 a[1 ], // expected-note{{used in buffer access here}} `a` is of pointer type
111111 b[1 ][2 ] // expected-note{{used in buffer access here}} `b[1]` is of array type
112- // expected-warning@-1{{unsafe buffer access}}
113112 );
114113}
115114
@@ -128,29 +127,41 @@ T_t funRetT();
128127T_t * funRetTStar ();
129128
130129void 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 ],
132131 sp->b [1 ], // expected-warning{{unsafe buffer access}}
133- sp->c .a [1 ], // expected-warning{{unsafe buffer access}}
132+ sp->c .a [1 ],
134133 sp->c .b [1 ], // expected-warning{{unsafe buffer access}}
135- s.a [1 ], // expected-warning{{unsafe buffer access}}
134+ s.a [1 ],
136135 s.b [1 ], // expected-warning{{unsafe buffer access}}
137- s.c .a [1 ], // expected-warning{{unsafe buffer access}}
136+ s.c .a [1 ],
138137 s.c .b [1 ], // expected-warning{{unsafe buffer access}}
139- sp2->a [1 ], // expected-warning{{unsafe buffer access}}
138+ sp2->a [1 ],
140139 sp2->b [1 ], // expected-warning{{unsafe buffer access}}
141- sp2->c .a [1 ], // expected-warning{{unsafe buffer access}}
140+ sp2->c .a [1 ],
142141 sp2->c .b [1 ], // expected-warning{{unsafe buffer access}}
143- s2.a [1 ], // expected-warning{{unsafe buffer access}}
142+ s2.a [1 ],
144143 s2.b [1 ], // expected-warning{{unsafe buffer access}}
145- s2.c .a [1 ], // expected-warning{{unsafe buffer access}}
144+ s2.c .a [1 ],
146145 s2.c .b [1 ], // expected-warning{{unsafe buffer access}}
147- funRetT ().a [1 ], // expected-warning{{unsafe buffer access}}
146+ funRetT ().a [1 ],
148147 funRetT ().b [1 ], // expected-warning{{unsafe buffer access}}
149- funRetTStar ()->a [1 ], // expected-warning{{unsafe buffer access}}
148+ funRetTStar ()->a [1 ],
150149 funRetTStar ()->b [1 ] // expected-warning{{unsafe buffer access}}
151150 );
152151}
153152
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+
154165int garray[10 ]; // expected-warning{{'garray' is an unsafe buffer that does not perform bounds checks}}
155166int * gp = garray; // expected-warning{{'gp' is an unsafe pointer used for buffer access}}
156167int gvar = gp[1 ]; // FIXME: file scope unsafe buffer access is not warned
@@ -213,7 +224,6 @@ void testTypedefs(T_ptr_t p) {
213224 // expected-warning@-1{{'p' is an unsafe pointer used for buffer access}}
214225 foo (p[1 ], // expected-note{{used in buffer access here}}
215226 p[1 ].a [1 ], // expected-note{{used in buffer access here}}
216- // expected-warning@-1{{unsafe buffer access}}
217227 p[1 ].b [1 ] // expected-note{{used in buffer access here}}
218228 // expected-warning@-1{{unsafe buffer access}}
219229 );
@@ -223,10 +233,9 @@ template<typename T, int N> T f(T t, T * pt, T a[N], T (&b)[N]) {
223233 // expected-warning@-1{{'t' is an unsafe pointer used for buffer access}}
224234 // expected-warning@-2{{'pt' is an unsafe pointer used for buffer access}}
225235 // 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}}
227236 foo (pt[1 ], // expected-note{{used in buffer access here}}
228237 a[1 ], // expected-note{{used in buffer access here}}
229- b[1 ]); // expected-note{{used in buffer access here}}
238+ b[1 ]);
230239 return &t[1 ]; // expected-note{{used in buffer access here}}
231240}
232241
@@ -376,7 +385,7 @@ int testArrayAccesses(int n, int idx) {
376385 typedef int A[3 ];
377386 const A tArr = {4 , 5 , 6 };
378387 foo (tArr[0 ], tArr[1 ]);
379- return cArr[0 ][1 ]; // expected-warning{{unsafe buffer access}}
388+ return cArr[0 ][1 ];
380389}
381390
382391void testArrayPtrArithmetic (int x[]) { // expected-warning{{'x' is an unsafe pointer used for buffer access}}
0 commit comments