[PATCH] D110357: [Analyzer] Extend ConstraintAssignor to handle remainder op

Denys Petrov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 28 05:47:57 PDT 2021


ASDenysPetrov added inline comments.


================
Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1603-1604
 
+  template <typename SymT>
+  bool handleRem(const SymT *Sym, RangeSet Constraint) {
+    // a % b != 0 implies that a != 0.
----------------
steakhal wrote:
> Why is this not a `const` member function?
IMO it's better to rename the function `handleRemainderOp`.

Add a function description in comments above. 
E.g. Handle expressions like: `a % b == 0`. ... Returns `true` when //bla-bla//, otherwise returns `false`.


================
Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1609-1612
+      const SymExpr *LHS = Sym->getLHS();
+      const llvm::APSInt &Zero =
+          Builder.getBasicValueFactory().getValue(0, LHS->getType());
+      State = RCM->assumeSymNE(State, LHS, Zero, Zero);
----------------
Maybe make some more complex assumptions to cover complex **LHS's**?


================
Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1708
   ProgramStateRef State;
+  RangeConstraintManager *RCM;
   SValBuilder &Builder;
----------------



================
Comment at: clang/test/Analysis/constraint-assignor.c:30
+  (void)x; // keep the constraints alive.
+}
----------------
Add some nested cases like `x % y % z == 0`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110357/new/

https://reviews.llvm.org/D110357



More information about the cfe-commits mailing list