[PATCH] D65239: [analyzer] RangeConstraintManager: Apply constraint ranges of bitwise operations

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 21 11:24:41 PDT 2019


NoQ added inline comments.


================
Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:503
+
+  if (!BinaryOperator::isBitwiseOrShiftOp(SIE->getOpcode()))
+    return State;
----------------
I suspect we have problems with bitwise OR here, which (unlike other bitwise/shift ops) may be true when the LHS is 0.


================
Comment at: clang/test/Analysis/bitwise-ranges.cpp:16
+  unsigned int A = X | 8;
+  clang_analyzer_eval((A > 0 && A < 0) || A == 0);
+  // expected-warning at -1 {{FALSE}}
----------------
The LHS of || is always false here, regardless of the value of `A` or constraints on it. This test tests something strange.


================
Comment at: clang/test/Analysis/bitwise-ranges.cpp:24
+  unsigned int C = X & 1;
+  clang_analyzer_eval((C >= 1 && C <= 1) || C == 0);
+  // expected-warning at -1 {{TRUE}}
----------------
The LHS of || is equivalent to `C == 1`.


================
Comment at: clang/test/Analysis/bitwise-ranges.cpp:28
+  unsigned int D = X << 1;
+  clang_analyzer_eval((D >= 1 && D <= 4294967295) || D == 0);
+  // expected-warning at -1 {{TRUE}}
----------------
This check is trivially true regardless of the value of D or constraints on it.


================
Comment at: clang/test/Analysis/bitwise-ranges.cpp:32
+  unsigned int E = X >> 1;
+  clang_analyzer_eval((E >= 1 && E <= 4294967295) || E == 0);
+  // expected-warning at -1 {{TRUE}}
----------------
Same here.


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

https://reviews.llvm.org/D65239





More information about the cfe-commits mailing list