diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp index eda06c64a9f4b..91e71558314ad 100644 --- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp +++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp @@ -1363,11 +1363,7 @@ class SymbolicRangeInferrer template RangeSet VisitBinaryOperator(RangeSet LHS, RangeSet RHS, QualType T) { - // We should propagate information about unfeasbility of one of the - // operands to the resulting range. - if (LHS.isEmpty() || RHS.isEmpty()) { - return RangeFactory.getEmptySet(); - } + assert(!LHS.isEmpty() && !RHS.isEmpty()); Range CoarseLHS = fillGaps(LHS); Range CoarseRHS = fillGaps(RHS); @@ -1618,8 +1614,7 @@ template <> RangeSet SymbolicRangeInferrer::VisitBinaryOperator(RangeSet LHS, RangeSet RHS, QualType T) { - - assert(!LHS.isEmpty() && !RHS.isEmpty() && "Both ranges should be non-empty"); + assert(!LHS.isEmpty() && !RHS.isEmpty()); if (LHS.getAPSIntType() == RHS.getAPSIntType()) { if (intersect(RangeFactory, LHS, RHS).isEmpty()) @@ -1803,6 +1798,12 @@ RangeSet SymbolicRangeInferrer::VisitBinaryOperator(Range LHS, RangeSet SymbolicRangeInferrer::VisitBinaryOperator(RangeSet LHS, BinaryOperator::Opcode Op, RangeSet RHS, QualType T) { + // We should propagate information about unfeasbility of one of the + // operands to the resulting range. + if (LHS.isEmpty() || RHS.isEmpty()) { + return RangeFactory.getEmptySet(); + } + switch (Op) { case BO_NE: return VisitBinaryOperator(LHS, RHS, T); diff --git a/clang/test/Analysis/constant-folding-crash.cpp b/clang/test/Analysis/constant-folding-crash.cpp new file mode 100644 index 0000000000000..156bfa5dda6a6 --- /dev/null +++ b/clang/test/Analysis/constant-folding-crash.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s +// expected-no-diagnostics + +namespace bbi_77010 { +int crash_NE(int rhs, int lhs, int x) { + int band = lhs & rhs; + if (0 <= band) {} + if (rhs > 0) {} + return band != x; // no-crash D112621 +} +} // namespace bbi_77010