[PATCH] D30295: [analyzer] clarify undef shift result when shift count is negative or exceeds the bit width

Daniel Marjamäki via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 22 09:41:48 PDT 2017


danielmarjamaki marked 4 inline comments as done.
danielmarjamaki added inline comments.


================
Comment at: lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp:126
+           << BinaryOperator::getOpcodeStr(B->getOpcode())
+           << "' expression is undefined due to shift count >= width of type";
+      } else {
----------------
zaks.anna wrote:
> It's best not to use ">=" in diagnostic messages.
> Suggestions: "due to shift count >= width of type" ->
> - "due to shifting by a value larger than the width of type"
> - "due to shifting by 5, which is larger than the width of type 'int'" // Providing the exact value and the type would be very useful and this information is readily available to us. Note that the users might not see the type or the value because of macros and such.
I used "due to shifting by 5, which is larger than the width of type 'int'"

However I did not see an easy way to show the exact value. So I added getConcreteValue(). Maybe you have a better suggestion. If it's a ConcreteInt I show the exact value, but if it's some range etc then I write "due to shifting by a value that is larger..." instead.

The message "due to shifting by 64, which is larger than the width of type 'unsigned long long'" is a bit weird imho. Because 64 is not larger than the width. Not sure how this can be rephrazed better though.


Repository:
  rL LLVM

https://reviews.llvm.org/D30295





More information about the cfe-commits mailing list