[PATCH] D33672: [analyzer] INT50-CPP. Do not cast to an out-of-range enumeration checker

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 29 04:53:03 PDT 2018


aaron.ballman added inline comments.


================
Comment at: lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp:19
+//   of casting an integer value that is out of range
+//===----------------------------------------------------------------------===//
+
----------------
ZaMaZaN4iK wrote:
> Szelethus wrote:
> > ZaMaZaN4iK wrote:
> > > aaron.ballman wrote:
> > > > If this check is intended to conform to CERT's INT50-CPP rule, you should put a link to the wiki entry for it here as well.
> > > Which wiki entry do you mean?
> > Maybe this one? https://wiki.sei.cmu.edu/confluence/display/cplusplus/INT50-CPP.+Do+not+cast+to+an+out-of-range+enumeration+value
> Added a note about CERT's coding standard recommendaation. Didn't add the reference to web page because web pages can become broken. I think standard and check names are quite good explanation for here
That was the wiki entry I was talking about, but we do typically add links directly to coding guidelines that we implement checks for (at least, we do in clang-tidy, perhaps the static analyzer has a different policy) -- it makes it easier for folks reading the code to reference the rationale behind why the check behaves the way it does. However, what you have is also fine -- it's searchable.


================
Comment at: test/Analysis/enum-cast-out-of-range.cpp:1
+// RUN: %clang_analyze_cc1 \
+// RUN:   -analyzer-checker=core,alpha.cplusplus.EnumCastOutOfRange \
----------------
Can you add a test for bit-field assignment. e.g.,
```
struct S {
  some_enum E : 4;
};

int main(void) {
  struct S s;
  s.E = 9;
}
```


https://reviews.llvm.org/D33672





More information about the cfe-commits mailing list