Skip to content

Commit 78d1f32

Browse files
committed
Add a test to clarify that we only deal with loop conditions
1 parent 1e28c6f commit 78d1f32

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

clang/test/Analysis/loop-assumptions.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,20 @@ void innerLoopOpaqueCondition(int arg) {
200200
}
201201
}
202202
}
203+
204+
void onlyLoopConditions(int arg) {
205+
// This "don't assume third iteration" logic only examines the conditions of
206+
// loop statements and does not affect the analysis of code that implements
207+
// similar behavior with different language features like if + break, goto,
208+
// recursive functions, ...
209+
int i = 0;
210+
while (1) {
211+
clang_analyzer_numTimesReached(); // expected-warning {{4}}
212+
213+
// This is not a loop condition.
214+
if (i++ > arg)
215+
break;
216+
}
217+
218+
clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
219+
}

0 commit comments

Comments
 (0)