[PATCH] D66014: [analyzer] Avoid unnecessary enum range check on LValueToRValue casts
Kristóf Umann via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 13 14:04:20 PDT 2019
Szelethus accepted this revision.
Szelethus added a comment.
LGTM, thanks! Do you need someone to commit this on your behalf? Also, could you please make the comments capitalized, terminated, and fitting in 80 columns?
================
Comment at: clang/test/Analysis/enum-cast-out-of-range.c:14-24
+ enum unscoped_unspecified_t InvalidBeforeRangeBegin = (enum unscoped_unspecified_t)(-5); // expected-warning {{The value provided to the cast expression is not in the valid range of values for the enum}}
+ enum unscoped_unspecified_t ValidNegativeValue1 = (enum unscoped_unspecified_t)(-4); // OK.
+ enum unscoped_unspecified_t ValidNegativeValue2 = (enum unscoped_unspecified_t)(-3); // OK.
+ enum unscoped_unspecified_t InvalidInsideRange1 = (enum unscoped_unspecified_t)(-2); // expected-warning {{The value provided to the cast expression is not in the valid range of values for the enum}}
+ enum unscoped_unspecified_t InvalidInsideRange2 = (enum unscoped_unspecified_t)(-1); // expected-warning {{The value provided to the cast expression is not in the valid range of values for the enum}}
+ enum unscoped_unspecified_t InvalidInsideRange3 = (enum unscoped_unspecified_t)(0); // expected-warning {{The value provided to the cast expression is not in the valid range of values for the enum}}
+ enum unscoped_unspecified_t ValidPositiveValue1 = (enum unscoped_unspecified_t)(1); // OK.
----------------
Note that you don't need to add the entire warning message here, and since its all the same, we could shorten it. Could you please format these lines like this?:
```lang=c++
enum unscoped_unspecified_t InvalidAfterRangeEnd = (enum unscoped_unspecified_t)(5);
// expected-warning at -1{{not in the valid range of values for the enum}}
```
If by some miracle the entire warning message fits in 80 columns, go for it! :)
Repository:
rC Clang
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D66014/new/
https://reviews.llvm.org/D66014
More information about the cfe-commits
mailing list