[PATCH] D105273: [analyzer] Introduce range-based reasoning for subtraction operator

Manas Gupta via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 2 11:45:18 PDT 2021


manas marked 3 inline comments as done.
manas added a comment.

Thanks Valeriy.



================
Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1490
+  // the resulting range should be [Min, Max].
+  if (ResultType.isUnsigned()) {
+    return {RangeFactory, ValueFactory.getValue(Min),
----------------
vsavchenko wrote:
> Maybe you can include this as yet another condition in the next `if` statement?  Their bodies are identical.
True. I wanted to optimize the following `if` condition as it looks quite ugly right now! Although, I will concatenate these conditions for now and work on the optimization later.


================
Comment at: clang/test/Analysis/constant-folding.c:399
+    // (a - b) = [0, 5] U [UINT_MAX - 9, UINT_MAX]
+    clang_analyzer_eval((a - b) != 6); // expected-warning{{TRUE}}
+    clang_analyzer_eval((a - b) != UINT_MAX - 10); // expected-warning{{TRUE}}
----------------
vsavchenko wrote:
> Maybe you can check `(a - b) > 5 && (a - b) < UINT_MAX - 9` to cover the whole range?
That's true! I never thought of putting them together. Makes more sense.


================
Comment at: clang/test/Analysis/constant-folding.c:405
+
+  if (c >= INT_MAX - 5 && d >= INT_MAX - 5) {
+    // (c - d) = [-5, 5]
----------------
vsavchenko wrote:
> This is also Min and Max overflowing on the positive side.
I missed it! I will add another case for only Max overflowing on positive side and will keep this test as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105273



More information about the cfe-commits mailing list