Skip to content

Commit

Permalink
[analyzer] ConditionBRVisitor: Remove GDM checking
Browse files Browse the repository at this point in the history
Summary:
Removed the `GDM` checking what could prevent reports made by this visitor.
Now we rely on constraint changes instead.
(It reapplies 356318 with a feature from 356319 because build-bot failure.)

Reviewers: NoQ, george.karpenkov

Reviewed By: NoQ

Subscribers: cfe-commits, jdoerfert, gerazo, xazax.hun, baloghadamsoftware,
szepet, a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D54811

llvm-svn: 356322
  • Loading branch information
Charusso committed Mar 16, 2019
1 parent 17c8ca8 commit cf0b4e3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
Expand Up @@ -79,6 +79,9 @@ class ConstraintManager {
ConstraintManager() = default;
virtual ~ConstraintManager();

virtual bool haveEqualConstraints(ProgramStateRef S1,
ProgramStateRef S2) const = 0;

virtual ProgramStateRef assume(ProgramStateRef state,
DefinedSVal Cond,
bool Assumption) = 0;
Expand Down
Expand Up @@ -588,11 +588,15 @@ class ProgramStateManager {
ProgramStateRef getPersistentStateWithGDM(ProgramStateRef FromState,
ProgramStateRef GDMState);

bool haveEqualEnvironments(ProgramStateRef S1, ProgramStateRef S2) {
bool haveEqualConstraints(ProgramStateRef S1, ProgramStateRef S2) const {
return ConstraintMgr->haveEqualConstraints(S1, S2);
}

bool haveEqualEnvironments(ProgramStateRef S1, ProgramStateRef S2) const {
return S1->Env == S2->Env;
}

bool haveEqualStores(ProgramStateRef S1, ProgramStateRef S2) {
bool haveEqualStores(ProgramStateRef S1, ProgramStateRef S2) const {
return S1->store == S2->store;
}

Expand Down
Expand Up @@ -220,6 +220,11 @@ class SMTConstraintManager : public clang::ento::SimpleConstraintManager {
OS << nl;
}

bool haveEqualConstraints(ProgramStateRef S1,
ProgramStateRef S2) const override {
return S1->get<ConstraintSMT>() == S2->get<ConstraintSMT>();
}

bool canReasonAbout(SVal X) const override {
const TargetInfo &TI = getBasicVals().getContext().getTargetInfo();

Expand Down
11 changes: 5 additions & 6 deletions clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
Expand Up @@ -1816,13 +1816,10 @@ ConditionBRVisitor::VisitNodeImpl(const ExplodedNode *N,
BugReporterContext &BRC, BugReport &BR) {
ProgramPoint progPoint = N->getLocation();
ProgramStateRef CurrentState = N->getState();
ProgramStateRef PrevState = N->getFirstPred()->getState();
ProgramStateRef PreviousState = N->getFirstPred()->getState();

// Compare the GDMs of the state, because that is where constraints
// are managed. Note that ensure that we only look at nodes that
// were generated by the analyzer engine proper, not checkers.
if (CurrentState->getGDM().getRoot() ==
PrevState->getGDM().getRoot())
// If the constraint information does not changed there is no assumption.
if (BRC.getStateManager().haveEqualConstraints(CurrentState, PreviousState))
return nullptr;

// If an assumption was made on a branch, it should be caught
Expand Down Expand Up @@ -1892,6 +1889,8 @@ std::shared_ptr<PathDiagnosticPiece> ConditionBRVisitor::VisitTerminator(
break;
}

Cond = Cond->IgnoreParens();

// However, when we encounter a logical operator as a branch condition,
// then the condition is actually its RHS, because LHS would be
// the condition for the logical operator terminator.
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
Expand Up @@ -230,6 +230,11 @@ class RangeConstraintManager : public RangedConstraintManager {
// Implementation for interface from ConstraintManager.
//===------------------------------------------------------------------===//

bool haveEqualConstraints(ProgramStateRef S1,
ProgramStateRef S2) const override {
return S1->get<ConstraintRange>() == S2->get<ConstraintRange>();
}

bool canReasonAbout(SVal X) const override;

ConditionTruthVal checkNull(ProgramStateRef State, SymbolRef Sym) override;
Expand Down

0 comments on commit cf0b4e3

Please sign in to comment.