Skip to content

Commit 399fb1e

Browse files
committed
Clarify comments about relationship with eagerly-assume
1 parent 57f67e2 commit 399fb1e

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

clang/lib/StaticAnalyzer/Core/ExprEngine.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2810,6 +2810,13 @@ void ExprEngine::processBranch(
28102810
if (StTrue && StFalse)
28112811
assert(!isa<ObjCForCollectionStmt>(Condition));
28122812

2813+
// We want to ensure consistent behavior between `eagerly-assume=false`,
2814+
// when the state split is always performed by the `assumeCondition()`
2815+
// call within this function and `eagerly-assume=true` (the default), when
2816+
// some conditions (comparison operators, unary negation) can trigger a
2817+
// state split before this callback. There are some contrived corner cases
2818+
// that behave differently with and without `eagerly-assume`, but I don't
2819+
// know about an example that could plausibly appear in "real" code.
28132820
bool BothFeasible =
28142821
(StTrue && StFalse) ||
28152822
didEagerlyAssumeBifurcateAt(PrevState, dyn_cast<Expr>(Condition));

clang/test/Analysis/loop-assumptions.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,22 @@ void shortCircuitInLoopConditionRHS(int arg) {
163163
void eagerlyAssumeInSubexpression(int arg) {
164164
// The `EagerlyAssume` logic is another complication that can "split the
165165
// state" within the loop condition, but before the `processBranch()` call
166-
// which is (in theory) responsible for evaluating the loop condition.
167-
// The current implementation partially compensates this by noticing the
166+
// which would be "naturally" responsible for evaluating the loop condition.
167+
// The current implementation tries to handle this by noticing the
168168
// cases where the loop condition is targeted by `EagerlyAssume`, but does
169169
// not handle the (fortunately rare) case when `EagerlyAssume` hits a
170170
// sub-expression of the loop condition (as in this contrived test case).
171-
// FIXME: I don't know a real-world example for this inconsistency, but it
172-
// would be good to eliminate it eventually.
171+
// FIXME: It would be good to eventually eliminate this inconsistency, but
172+
// I don't know a realistic example that could appear in real-world code, so
173+
// this seems to be a low-priority goal.
173174
int i;
174175
for (i = 0; (i >= arg) - 1; i++) {
175176
clang_analyzer_numTimesReached(); // eagerlyassume-warning {{4}} noeagerlyassume-warning {{2}}
176177
}
177178

178179
// The 'combo' note intentionally appears if `assume-at-least-one-iteration`
179-
// is disabled, but also appears as a bug (or at least inaccuracy) when
180-
// `assume-at-least-one-iteration` is true but `EagerlyAssume` is also
181-
// enabled.
180+
// is disabled, but also appears as a bug when `eagerly-assume` and
181+
// `assume-at-least-one-iteration` are both enabled.
182182
clang_analyzer_dump(i); // combo-warning {{0}} expected-warning {{1}} expected-warning {{2}} eagerlyassume-warning {{3}}
183183
}
184184

0 commit comments

Comments
 (0)