-
Notifications
You must be signed in to change notification settings - Fork 385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix] Treat clang-diagnostic-* checkers as compiler flags #3874
[fix] Treat clang-diagnostic-* checkers as compiler flags #3874
Conversation
08a3c10
to
12bcf39
Compare
Previously the handling of clang-diagnostics was flawed, because tidy cannot enable those as a checker, only suppression of the resulting reports are available: https://github.com/kimgr/clang-tools-extra/blob/master/docs/clang-tidy.rst After this patch all of these checkers will be treated as compiler warning flags, this way the compiler warnings can be enabled as clang-diagnostics. There is an added benefit of this method, as the checker prefix based activation is also working now. The old -W notation will be deprecated, but for the time being still usable.
12bcf39
to
533b3c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The story here, as I understand it is the following. Both the CLI and the GUI could incorrectly let you believe that we handle compiler warnings as checkers, but that is only party true. We can't reliably enable/disable them. Not only that, the checker name they are displayed with start with "compiler-diagnostic-", but they must be named as "W" on the CLI.
Previously the handling of clang-diagnostics was flawed, because tidy cannot enable those as a checker, only suppression of the resulting reports are available:
Yes, because compiler warnings are flags to the compiler, not the analyzer component. This makes some sense for a compiler developer, but as a user of a static analyzer tool, compiler warnings should be checkers. If clang-tidy won't do it on its own for whetever reason, we need to make it so that CodeChecker acts as if they were.
https://github.com/kimgr/clang-tools-extra/blob/master/docs/clang-tidy.rst
This is painfully out of date. Back in the day, LLVM didn't have a single monorepo housing all of its subprojects, but all subprojects had their own repository (imagine how painful an LLVM-wide refactoring used to be!). Not only is this repo from that era, it is ~6 years before the merging, and its not even the official mirror either.
This is probably what you are after:
https://clang.llvm.org/extra/clang-tidy/#suppressing-undesired-diagnostics
After this patch all of these checkers will be treated as compiler warning flags,
Not the other way around?
this way the compiler warnings can be enabled as clang-diagnostics.
Meaning that the name of the checker on the GUI and the name to be used on the CLI will be identical.
checker_name += '*' | ||
|
||
# If clang-diagnostic is enabled, else add it as a disabled | ||
# check. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to say that all clang-diagnostics not explicitly enabled should be disabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll rephrase this comment. I wanted to write something like this:
If a clang-diagnostic is enabled add it as a -W flag, else add it as a disabled checker to the checkers list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This english is still a little broken.
|
||
# If clang-diagnostic is enabled, else add it as a disabled | ||
# check. | ||
if checker_name.startswith('clang-diagnostic-') and \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have the variable warning_name
, that holds the information on whether we recognized the checker as compiler warning, no? Why are we reinveting the wheel instead of reusing the result of get_compiler_warning_name
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the first iteration of this pr, I modified get_compiler_warning_name
in a manner that it worked on clang-diagnostic- checker names. I did not like this approach, because in that implementation all the disabled clang-diagnostic- checkers were included as -Wno compiler flags in the build command passed to tidy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think this is bad design. The code would look more readable if we moved that logic to get_compiler_warning_name
(where it belongs), and we really need to, check whether this is a disabled clang-diagnostic after the fact.
I think you are mistaken here. The intent is to forgo the The following matrix shows the current state of compiler warning activation
This is the intention of the patch.
Thanks for pointing out that I included an outdated (and forked) documentation. The official docs still state the same. From the official clang-tidy docs:
quote end
This was it thanks!
No, because of the previously mentioned facts.
Before the patch:
After the patch:
Thanks for the review. |
6c399c4
to
b8c89f6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny things left to attend to.
edit: Please do better in the summary.
checker_name += '*' | ||
|
||
# If clang-diagnostic is enabled, else add it as a disabled | ||
# check. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This english is still a little broken.
b8c89f6
to
c5f4858
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, sorry :)
The summary is nice.
Removes 'W' or 'Wno' from the compiler warning name, if this is a | ||
compiler warning. Returns None otherwise. | ||
Removes 'W' or 'Wno' from the compiler warning name, or | ||
'clang-diagnostic-' from the checker name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just not true right now.
|
||
# If clang-diagnostic is enabled, else add it as a disabled | ||
# check. | ||
if checker_name.startswith('clang-diagnostic-') and \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think this is bad design. The code would look more readable if we moved that logic to get_compiler_warning_name
(where it belongs), and we really need to, check whether this is a disabled clang-diagnostic after the fact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! If you wanna make things a bit simpler, go ahead, I'll leave that to you.
Previously the handling of clang-diagnostics was flawed because tidy cannot enable compiler warnings when specified as a checker, only suppression of the resulting reports are available:
From the official clang-tidy docs:
After this patch all of these checkers will be treated as compiler warning flags, this way the compiler warnings can be enabled as clang-diagnostics.
There is an added benefit of this method, as the checker prefix based activation is also working now.
Before the patch:
-e clang-diagnostic-...
notation did not produce any result because tidy wouldn't insert the corresponding compiler warning to the input compilation command. We thought adding it to the checks list enabled the warning, but it didn't.After the patch:
-e W...
notation results in a warning from CodeChecker to use the clang-diagnostic-unused-variable counterpart.-e clang-diagnostic-...
now properly works. and enables the related compiler warnings.--enable-all
, instead of adding every compiler warning individually to the build command,-Weverything
is added.There are some considerations regarding the old
-W...
notation.-W...
notation is be deprecated, but for the time being still usable.\--enable-all
the usage of-d -W...
notation is ignored, and results in a warning. The-d compiler-diagnostics-...
is the recommended way to disable a compiler warning.