diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp --- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp +++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp @@ -2104,7 +2104,12 @@ const llvm::APSInt &Int, const llvm::APSInt &Adjustment) { RangeSet New = getSymLTRange(St, Sym, Int, Adjustment); - return New.isEmpty() ? nullptr : setConstraint(St, Sym, New); + if (New.isEmpty()) + // this is infeasible assumption + return nullptr; + + ProgramStateRef NewState = setConstraint(St, Sym, New); + return trackNE(NewState, Sym, Int, Adjustment); } RangeSet RangeConstraintManager::getSymGTRange(ProgramStateRef St, @@ -2140,7 +2145,12 @@ const llvm::APSInt &Int, const llvm::APSInt &Adjustment) { RangeSet New = getSymGTRange(St, Sym, Int, Adjustment); - return New.isEmpty() ? nullptr : setConstraint(St, Sym, New); + if (New.isEmpty()) + // this is infeasible assumption + return nullptr; + + ProgramStateRef NewState = setConstraint(St, Sym, New); + return trackNE(NewState, Sym, Int, Adjustment); } RangeSet RangeConstraintManager::getSymGERange(ProgramStateRef St, diff --git a/clang/test/Analysis/equality_tracking.c b/clang/test/Analysis/equality_tracking.c --- a/clang/test/Analysis/equality_tracking.c +++ b/clang/test/Analysis/equality_tracking.c @@ -185,3 +185,37 @@ } } } + +void avoidInfeasibleConstraintforGT(int a, int b) { + int c = b - a; + if (c <= 0) + return; + // c > 0 + // b - a > 0 + // b > a + if (a != b) { + clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} + return; + } + clang_analyzer_warnIfReached(); // no warning + // a == b + if (c < 0) + ; +} + +void avoidInfeasibleConstraintforLT(int a, int b) { + int c = b - a; + if (c >= 0) + return; + // c < 0 + // b - a < 0 + // b < a + if (a != b) { + clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} + return; + } + clang_analyzer_warnIfReached(); // no warning + // a == b + if (c < 0) + ; +}