Skip to content

Commit 41e94d7

Browse files
committed
Don't apply obsolete EagerlyAssume info
1 parent 8791294 commit 41e94d7

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

clang/lib/StaticAnalyzer/Core/ExprEngine.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3749,9 +3749,10 @@ ExprEngine::getEagerlyAssumeBifurcationTags() {
37493749
return std::make_pair(&TrueTag, &FalseTag);
37503750
}
37513751

3752-
/// The last expression where EagerlyAssume produced two transitions (i.e. it
3753-
/// activated and the true and false cases were both feasible).
3754-
REGISTER_TRAIT_WITH_PROGRAMSTATE(LastEagerlyAssumeBifurcationAt, const Expr *)
3752+
/// If the last EagerlyAssume attempt was successful (i.e. the true and false
3753+
/// cases were both feasible), this state trait stores the expression where it
3754+
/// happened; otherwise this holds nullptr.
3755+
REGISTER_TRAIT_WITH_PROGRAMSTATE(LastEagerlyAssumeExprIfSuccessful, const Expr *)
37553756

37563757
void ExprEngine::evalEagerlyAssumeBifurcation(ExplodedNodeSet &Dst,
37573758
ExplodedNodeSet &Src,
@@ -3768,6 +3769,7 @@ void ExprEngine::evalEagerlyAssumeBifurcation(ExplodedNodeSet &Dst,
37683769
}
37693770

37703771
ProgramStateRef State = Pred->getState();
3772+
State = State->set<LastEagerlyAssumeExprIfSuccessful>(nullptr);
37713773
SVal V = State->getSVal(Ex, Pred->getLocationContext());
37723774
std::optional<nonloc::SymbolVal> SEV = V.getAs<nonloc::SymbolVal>();
37733775
if (SEV && SEV->isExpression()) {
@@ -3776,8 +3778,8 @@ void ExprEngine::evalEagerlyAssumeBifurcation(ExplodedNodeSet &Dst,
37763778
auto [StateTrue, StateFalse] = State->assume(*SEV);
37773779

37783780
if (StateTrue && StateFalse) {
3779-
StateTrue = StateTrue->set<LastEagerlyAssumeBifurcationAt>(Ex);
3780-
StateFalse = StateFalse->set<LastEagerlyAssumeBifurcationAt>(Ex);
3781+
StateTrue = StateTrue->set<LastEagerlyAssumeExprIfSuccessful>(Ex);
3782+
StateFalse = StateFalse->set<LastEagerlyAssumeExprIfSuccessful>(Ex);
37813783
}
37823784

37833785
// First assume that the condition is true.
@@ -3799,7 +3801,7 @@ void ExprEngine::evalEagerlyAssumeBifurcation(ExplodedNodeSet &Dst,
37993801

38003802
bool ExprEngine::didEagerlyAssumeBifurcateAt(ProgramStateRef State,
38013803
const Expr *Ex) const {
3802-
return Ex && State->get<LastEagerlyAssumeBifurcationAt>() == Ex;
3804+
return Ex && State->get<LastEagerlyAssumeExprIfSuccessful>() == Ex;
38033805
}
38043806

38053807
void ExprEngine::VisitGCCAsmStmt(const GCCAsmStmt *A, ExplodedNode *Pred,

clang/test/Analysis/loop-assumptions.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,16 @@ void dontRememberOldBifurcation(int arg) {
6565
// at the first iteration of the loop, but does not make any new assumptions
6666
// in the subsequent iterations, so the analyzer should continue evaluating
6767
// the loop.
68-
// FIXME: This is mishandled in `eagerly-assume` mode (which is enabled by
69-
// default), because `didEagerlyAssumeBifurcateAt()` returns true for the
70-
// loop condition -- referring to the bifurcation which happened on an early
71-
// iteration.
68+
// Previously this was mishandled in `eagerly-assume` mode (which is enabled
69+
// by default), because the code remembered that there was a bifurcation on
70+
// the first iteration of the loop and didn't realize that this is obsolete.
7271

7372
// NOTE: The variable `i` is introduced to ensure that the iterations of the
7473
// loop change the state -- otherwise the analyzer stops iterating because it
7574
// returns to the same `ExplodedNode`.
7675
int i = 0;
7776
while (arg > 3) {
78-
clang_analyzer_numTimesReached(); // noeagerlyassume-warning {{4}} eagerlyassume-warning {{2}}
77+
clang_analyzer_numTimesReached(); // expected-warning {{4}}
7978
i++;
8079
}
8180

@@ -90,10 +89,8 @@ void dontAssumeFourthIterartion(int arg) {
9089
// iterations (because it knows that `arg != 2` at that point), so it
9190
// performs a third iteration, but it does not assume that a fourth iteration
9291
// is also possible.
93-
// FIXME: This test case is also affected by the bug described in
94-
// `dontRememberOldBifurcation()`.
9592
for (int i = 0; i < arg; i++)
96-
clang_analyzer_numTimesReached(); // noeagerlyassume-warning {{3}} eagerlyassume-warning {{2}}
93+
clang_analyzer_numTimesReached(); // expected-warning {{3}}
9794

9895
clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
9996
}

0 commit comments

Comments
 (0)