3 #include "../../gcc.dg/analyzer/analyzer-decls.h"
13 struct iter
* __attribute__((noinline
))
14 iter_new (int start
, int end
, int step
)
16 struct iter
*it
= (struct iter
*)malloc (sizeof (struct iter
));
26 int __attribute__((noinline
))
27 iter_done_p (struct iter
*it
)
29 return it
->val
>= it
->end
;
32 void __attribute__((noinline
))
33 iter_next (struct iter
*it
)
38 /* Example of an iterator object, to see how well we cope with a well-disguised
39 iteration from 0 to n with a step of 1. */
43 __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
45 struct iter
*it
= iter_new (0, n
, 1);
46 while (!iter_done_p (it
))
48 __analyzer_eval (it
->val
< n
); /* { dg-warning "TRUE" "true" } */
49 /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
50 /* TODO(xfail^^^): ideally we ought to figure out i > 0 after 1st iteration. */
52 __analyzer_eval (it
->val
== 0); /* { dg-warning "TRUE" "true on 1st iter" } */
53 /* { dg-warning "UNKNOWN" "unknown" { target *-*-* } .-1 } */
54 /* TODO: should we ought to figure out i > 0 after 1st iteration? */
56 __analyzer_eval (it
->val
>= 0); /* { dg-warning "TRUE" } */
58 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
63 __analyzer_eval (it
->val
>= n
); /* { dg-warning "TRUE" "true" { xfail *-*-* } } */
64 /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
66 __analyzer_eval (it
->val
== n
); /* { dg-warning "TRUE" "desired" { xfail *-*-* } } */
67 /* { dg-warning "UNKNOWN" "status quo" { target *-*-* } .-1 } */
68 /* TODO(xfail^^^): it only figures out i >= 256, rather than i == 256. */
72 __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */