@@ -211,6 +211,134 @@ class immutable_class {
211211 }
212212};
213213
214+ // Missing assignments
215+
216+ void missing_ptr (int *__counted_by (count) p, int count) {
217+ count = 0 ; // expected-warning{{bounds-attributed group requires assigning 'count, p', assignments to 'p' missing}}
218+ }
219+
220+ void missing_count (int *__counted_by (count) p, int count) {
221+ p = nullptr ; // expected-warning{{bounds-attributed group requires assigning 'count, p', assignments to 'count' missing}}
222+ }
223+
224+ void missing_structure (int *__counted_by (count) p, int count) {
225+ {
226+ p = nullptr ; // expected-warning{{bounds-attributed group requires assigning 'count, p', assignments to 'count' missing}}
227+ }
228+ {
229+ count = 0 ; // expected-warning{{bounds-attributed group requires assigning 'count, p', assignments to 'p' missing}}
230+ }
231+ }
232+
233+ void missing_structure2 (int *__counted_by (count) p, int count) {
234+ p = nullptr ; // expected-warning{{bounds-attributed group requires assigning 'count, p', assignments to 'count' missing}}
235+ {
236+ count = 0 ; // expected-warning{{bounds-attributed group requires assigning 'count, p', assignments to 'p' missing}}
237+ }
238+ }
239+
240+ void missing_structure3 (int *__counted_by (count) p, int count) {
241+ p = nullptr ; // expected-warning{{bounds-attributed group requires assigning 'count, p', assignments to 'count' missing}}
242+ if (count > 0 ) {
243+ count = 0 ; // expected-warning{{bounds-attributed group requires assigning 'count, p', assignments to 'p' missing}}
244+ }
245+ }
246+
247+ void missing_unrelated (int *__counted_by (count) p, int count, int *__counted_by(len) q, int len) {
248+ p = nullptr ; // expected-warning{{bounds-attributed group requires assigning 'count, p', assignments to 'count' missing}}
249+ len = 0 ; // expected-warning{{bounds-attributed group requires assigning 'len, q', assignments to 'q' missing}}
250+ }
251+
252+ void missing_complex_count1 (int *__counted_by (a + b) p, int a, int b) {
253+ p = nullptr ; // expected-warning{{bounds-attributed group requires assigning 'a, b, p', assignments to 'a, b' missing}}
254+ }
255+
256+ void missing_complex_count2 (int *__counted_by (a + b) p, int a, int b) {
257+ p = nullptr ;
258+ a = 0 ; // expected-warning{{bounds-attributed group requires assigning 'a, b, p', assignments to 'b' missing}}
259+ }
260+
261+ void missing_complex_count3 (int *__counted_by (a + b) p, int a, int b) {
262+ b = 0 ;
263+ p = nullptr ; // expected-warning{{bounds-attributed group requires assigning 'a, b, p', assignments to 'a' missing}}
264+ }
265+
266+ void missing_complex_count4 (int *__counted_by (a + b) p, int a, int b) {
267+ a = 0 ;
268+ b = 0 ; // expected-warning{{bounds-attributed group requires assigning 'a, b, p', assignments to 'p' missing}}
269+ }
270+
271+ void missing_complex_ptr1 (int *__counted_by (count) p, int *__counted_by(count) q, int count) {
272+ p = nullptr ; // expected-warning{{bounds-attributed group requires assigning 'count, p, q', assignments to 'count, q' missing}}
273+ }
274+
275+ void missing_complex_ptr2 (int *__counted_by (count) p, int *__counted_by(count) q, int count) {
276+ p = nullptr ;
277+ q = nullptr ; // expected-warning{{bounds-attributed group requires assigning 'count, p, q', assignments to 'count' missing}}
278+ }
279+
280+ void missing_complex_ptr3 (int *__counted_by (count) p, int *__counted_by(count) q, int count) {
281+ count = 0 ;
282+ p = nullptr ; // expected-warning{{bounds-attributed group requires assigning 'count, p, q', assignments to 'q' missing}}
283+ }
284+
285+ void missing_complex_ptr4 (int *__counted_by (count) p, int *__counted_by(count) q, int count) {
286+ q = nullptr ;
287+ count = 0 ; // expected-warning{{bounds-attributed group requires assigning 'count, p, q', assignments to 'p' missing}}
288+ }
289+
290+ // Missing assignments in struct
291+
292+ void missing_struct_ptr (cb *c) {
293+ c->count = 0 ; // expected-warning{{bounds-attributed group requires assigning 'count, p', assignments to 'p' missing}}
294+ }
295+
296+ void missing_struct_count (cb *c) {
297+ c->p = nullptr ; // expected-warning{{bounds-attributed group requires assigning 'count, p', assignments to 'count' missing}}
298+ }
299+
300+ void missing_struct_unrelated (cb *c, cb *d) {
301+ c->p = nullptr ; // expected-warning{{bounds-attributed group requires assigning 'count, p', assignments to 'count' missing}}
302+ d->count = 0 ; // expected-warning{{bounds-attributed group requires assigning 'count, p', assignments to 'p' missing}}
303+ }
304+
305+ // Duplicated assignments
306+
307+ void duplicated_ptr (int *__counted_by (count) p, int count) {
308+ p = nullptr ; // expected-note{{previously assigned here}}
309+ p = nullptr ; // expected-warning{{duplicated assignment to parameter 'p' in bounds-attributed group}}
310+ count = 0 ;
311+ }
312+
313+ void duplicated_ptr2 (int *__counted_by (count) p, int count) {
314+ p = nullptr ; // expected-note{{previously assigned here}}
315+ count = 0 ;
316+ p = nullptr ; // expected-warning{{duplicated assignment to parameter 'p' in bounds-attributed group}}
317+ }
318+
319+ void duplicated_count (int *__counted_by (count) p, int count) {
320+ p = nullptr ;
321+ count = 0 ; // expected-note{{previously assigned here}}
322+ count = 0 ; // expected-warning{{duplicated assignment to parameter 'count' in bounds-attributed group}}
323+ }
324+
325+ void duplicated_count2 (int *__counted_by (count) p, int count) {
326+ count = 0 ; // expected-note{{previously assigned here}}
327+ p = nullptr ;
328+ count = 0 ; // expected-warning{{duplicated assignment to parameter 'count' in bounds-attributed group}}
329+ }
330+
331+ void duplicated_complex (int *__counted_by (a + b) p,
332+ int *__counted_by(a + b + c) q,
333+ int a, int b, int c) {
334+ p = nullptr ;
335+ q = nullptr ; // expected-note{{previously assigned here}}
336+ a = 0 ;
337+ b = 0 ;
338+ c = 0 ;
339+ q = nullptr ; // expected-warning{{duplicated assignment to parameter 'q' in bounds-attributed group}}
340+ }
341+
214342// Assigns to bounds-attributed that we consider too complex to analyze.
215343
216344void too_complex_assign_to_ptr (int *__counted_by (count) p, int count, int *q) {
0 commit comments