[clang] [analyzer] Improve constraint inferring on concrete div/mod (PR #65448)

Ding Fei via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 15 10:50:49 PDT 2023


================
@@ -1824,6 +1835,94 @@ RangeSet SymbolicRangeInferrer::VisitBinaryOperator<BO_Rem>(Range LHS,
   return {RangeFactory, ValueFactory.getValue(Min), ValueFactory.getValue(Max)};
 }
 
+RangeSet SymbolicRangeInferrer::handleConcreteModulo(Range LHS,
+                                                     llvm::APSInt Modulo,
+                                                     QualType T) {
+  APSIntType ResultType = ValueFactory.getAPSIntType(T);
+  llvm::APSInt Zero = ResultType.getZeroValue();
+  llvm::APSInt One = ResultType.getValue(1);
+
+  if (Modulo == Zero)
+    return RangeFactory.getEmptySet();
+  if (Modulo < 0)
+    Modulo = -Modulo;
----------------
danix800 wrote:

Actually `X % Y == X % -Y`, not `X % Y == -X % Y` or `X % Y == -X % -Y`. Sign of Y is not significant.

https://github.com/llvm/llvm-project/pull/65448


More information about the cfe-commits mailing list