File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -237,6 +237,37 @@ void loop_suppress_in_third_iteration(int len) {
237237 }
238238}
239239
240+ int no_suppression_when_no_assumption_zero_iterations (unsigned len ) {
241+ if (len != 0 ) {
242+ // This 'if' introduces a state split between len == 0 and len != 0.
243+ }
244+
245+ // On the branch where we assumed that len is zero, this loop will be
246+ // skipped. We (intentionally) don't suppress this execution path becasue
247+ // here the analyzer doesn't assume anything new when it evaluates the loop
248+ // condition.
249+ for (unsigned i = 0 ; i < len ; i ++ )
250+ if (GlobalArray [i ] > 0 )
251+ return GlobalArray [i ];
252+
253+ return GlobalArray [len - 1 ]; // expected-warning{{Out of bound access to memory}}
254+ }
255+
256+ void no_suppression_when_no_assumption_third_iteration (int len ) {
257+ if (len < 20 ) {
258+ // This 'if' introduces a state split with len >= 20 on one branch.
259+ }
260+
261+ int buf [2 ] = {0 };
262+ for (int i = 0 ; i < len ; i ++ ) {
263+ // As in no_suppression_when_no_assumption_zero_iterations, the suppression
264+ // only activates when the analyzer assumes something new in the loop
265+ // condition. On the branch where `len >= 20` entering the third iteration
266+ // doesn't involve a new assumption, so this warning is not suppressed:
267+ buf [i ] = 1 ; // expected-warning{{Out of bound access to memory}}
268+ }
269+ }
270+
240271void loop_suppress_in_third_iteration_cast (int len ) {
241272 int buf [2 ] = {0 };
242273 for (int i = 0 ; (unsigned )(i < len ); i ++ ) {
You can’t perform that action at this time.
0 commit comments