Skip to content

Commit cbb46e5

Browse files
committed
Add 'no suppression when no assumption' testcases
1 parent e7e6ded commit cbb46e5

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

clang/test/Analysis/out-of-bounds.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
240271
void loop_suppress_in_third_iteration_cast(int len) {
241272
int buf[2] = {0};
242273
for (int i = 0; (unsigned)(i < len); i++) {

0 commit comments

Comments
 (0)