llvm / llvm/llvm-project

[Analyzer] clang-analyzer-optin.core.EnumCastOutOfRange ignores -isystem : warns for code in system headers

Open
#196,259 2 comments 1 reaction 0 assignees View on GitHub
clang:static analyzer
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

clang-analyzer-optin.core.EnumCastOutOfRange reports warnings whose diagnostic location is inside a system header (included via -isystem).

Reproducer
[Godbolt (clang-analyzer-optin.core.EnumCastOutOfRange warning)](https://godbolt.org/z/ecsG4jjY7)

Boost (included via -isystem):

`#include

int main() {
static const auto reVendor = boost::regex("^(.*?) - (.*)$");
boost::smatch mVendor;
std::string value = "example - value";
boost::regex_match(value, mVendor, reVendor);
return 0;
}
`

and it reports warning in boost (system library):
`/opt/compiler-explorer/libs/boost_1_78_0/boost/regex/v5/match_flags.hpp:98:10: warning: The value '163840' provided to the cast expression is not in the valid range of values for '_match_flags' [clang-analyzer-optin.core.EnumCastOutOfRange]
98 | { return static_cast(static_cast(m1) | static_cast(m2)); }
| ^
/opt/compiler-explorer/libs/boost_1_78_0/boost/regex/v5/match_flags.hpp:38:14: note: enum declared here
38 | typedef enum _match_flags
| ~~~~~^~~~~~~~~~~~
39 | {
| ~
40 | match_default = 0,
| ~~~~~~~~~~~~~~~~~~
41 | match_not_bol = 1, /* first is not start of line */
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42 | match_not_eol = match_not_bol << 1, /* last is not end of line */
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43 | match_not_bob = match_not_eol << 1, /* first is not start of buffer */
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44 | match_not_eob = match_not_bob << 1, /* last is not end of buffer */
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45 | match_not_bow = match_not_eob << 1, /* first is not start of word */
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46 | match_not_eow = match_not_bow << 1, /* last is not end of word */
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47 | match_not_dot_newline = match_not_eow << 1, /* \n is not matched by '.' */
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48 | match_not_dot_null = match_not_dot_newline << 1, /* '\0' is not matched by '.' */
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49 | match_prev_avail = match_not_dot_null << 1, /* *--first is a valid expression */
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
50 | match_init = match_prev_avail << 1, /* internal use */
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51 | match_any = match_init << 1, /* don't care what we match */
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52 | match_not_null = match_any << 1, /* string can't be null */
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53 | match_continuous = match_not_null << 1, /* each grep match must continue from */
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`
Thanks

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.