diff --git a/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp b/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp --- a/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp +++ b/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp @@ -137,10 +137,13 @@ // Reverse the operation and add directly to state. const llvm::APSInt &Zero = BVF.getValue(0, T); + llvm::APSInt Adjustment = Zero; + computeAdjustment(Sym, Adjustment); + if (Assumption) - return assumeSymNE(State, Sym, Zero, Zero); - else - return assumeSymEQ(State, Sym, Zero, Zero); + return assumeSymNE(State, Sym, Zero, Adjustment); + + return assumeSymEQ(State, Sym, Zero, Adjustment); } ProgramStateRef RangedConstraintManager::assumeSymRel(ProgramStateRef State, diff --git a/clang/test/Analysis/infeasible_paths.c b/clang/test/Analysis/infeasible_paths.c new file mode 100644 --- /dev/null +++ b/clang/test/Analysis/infeasible_paths.c @@ -0,0 +1,25 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s + +// expected-no-diagnostics + +void clang_analyzer_warnIfReached(); + +void unsupportedSymAssumption_1(int a) { + int b = a + 1; + if (b + 1) + return; + // At this point, b == -1, a == -2 + // and this condition is always true. + if (b < 1) + return; + clang_analyzer_warnIfReached(); // no-warning +} + +void unsupportedSymAssumption_2(int a) { + int b = a - 1; + if (!b) + return; + if (b) + return; + clang_analyzer_warnIfReached(); // no-warning +}