Details
- Reviewers
aaron.ballman alexfh
Diff Detail
Event Timeline
Aside from two tiny nits, LGTM. Thank you for working on this, it's a great feature! I think we should add something to the release notes to make sure it gets called out.
tools/llvm-project/extra/clang-tidy/ClangTidy.cpp | ||
---|---|---|
156 | Method can be const. | |
tools/llvm-project/extra/test/clang-tidy/werrors-plural.cpp | ||
7 | One of these tests should complete the -Werrors= chunk just to be sure it's getting printed properly. |
tools/llvm-project/extra/test/clang-tidy/werrors-plural.cpp | ||
---|---|---|
7 | Ah, I didn't pick up on that. What is the = for, then? |
Jonathan, can you explain what specific use case does this patch address? Why one severity level of native clang-tidy warnings (the current situation) is not enough, and two levels are enough?
I have out-of-tree checkers for a very strange out-of-tree target. Some of the checks are on the level of "this should break the build because it cannot possibly work on this target" and others on the level of "tell me about it, but don't force me to fix it". All of these checks are things that don't even remotely apply to other targets.
If you're wondering why I haven't hacked up Clang's sema to enforce these constraints, see again: out-of-tree backend... maintaining OOT changes there is expected to be very difficult. Clang-tidy however provides a very nice framework where they can be kept neatly off to the side, away from most of the merge hassles.
It'd be nice not to have to run clang-tidy twice & parse its output in order to achieve all of that, hence this patch.
tools/llvm-project/extra/test/clang-tidy/werrors-plural.cpp | ||
---|---|---|
7 | I considered that part of the name of the flag. I can drop that if you think it looks better. Or print out the whole thing as the user wrote it, if you think that's useful (though -checks= and -Werrors= lines are probably pretty long...). |
tools/llvm-project/extra/test/clang-tidy/werrors-plural.cpp | ||
---|---|---|
7 | I would just drop the =; it seems like that suggests there should be more text there. That would also be consistent with the way clang reports -Werror diagnostics (error: unused variable 'i' [-Werror,-Wunused-variable]) |
Thank you for the explanation. One more question: do you need to define Werrors differently in different directories?
If you're wondering why I haven't hacked up Clang's sema to enforce these constraints, see again: out-of-tree backend... maintaining OOT changes there is expected to be very difficult.
No, a sane person wouldn't suggest maintaining a local patch for Clang as a good solution ;)
Clang-tidy however provides a very nice framework where they can be kept neatly off to the side, away from most of the merge hassles.
It's one of the goals of clang-tidy to provide an easy way to maintain out-of-tree checks.
It'd be nice not to have to run clang-tidy twice & parse its output in order to achieve all of that, hence this patch.
Agreed, I want to ensure though, that this is the right approach. In particular, I wonder whether a way to assign labels or severities to clang-tidy diagnostics would be better. Another question is whether we can reuse something from the Clang diagnostic subsystem to map warning levels.
Yeah, for things like "if you do this, you will get terribad performance", it's useful to be able to let the user's build system control them independently with that kind of granularity. In some places it's acceptable to fail these checks (i.e. while porting code to this target), and in others it's mission-critical.
I could see this being useful in other contexts too. For example, hypothetically, one could imagine turning on the llvm-include-order check for all of llvm, and then making it -Werror for subdirectories where it has been cleaned up, ensuring monotonic progress.
If you're wondering why I haven't hacked up Clang's sema to enforce these constraints, see again: out-of-tree backend... maintaining OOT changes there is expected to be very difficult.
No, a sane person wouldn't suggest maintaining a local patch for Clang as a good solution ;)
:)
Clang-tidy however provides a very nice framework where they can be kept neatly off to the side, away from most of the merge hassles.
It's one of the goals of clang-tidy to provide an easy way to maintain out-of-tree checks.
Seems to be working out very well on my end... thanks for designing it that way!
It'd be nice not to have to run clang-tidy twice & parse its output in order to achieve all of that, hence this patch.
Agreed, I want to ensure though, that this is the right approach. In particular, I wonder whether a way to assign labels or severities to clang-tidy diagnostics would be better. Another question is whether we can reuse something from the Clang diagnostic subsystem to map warning levels.
For my purposes, this kind of trimodal { "it's definitely broken, and cannot possibly work", "hey, have you considered this?", "the tool didn't spot any problems" } granularity seems like the right fit, and lines up with Clang's diagnostics: notes usually stay notes, remarks stay remarks, warnings are sometimes errors and other times just warnings, and errors are errors.
Something else to think about: grouping a la -Wpedantic/-Wall/-Weverything might be useful. Some of that can be achieved by giving structure to the names of the checks, i.e.:
- footarget-perf-check1
- footarget-perf-check2
- footarget-correctness-check1
- footarget-correctness-check2
- footarget-portability-check1
(pardon my vagueness here)
But that kind of breaks down when you start to talk about putting existing upstream checks into these groups, because then you have to write things like: `-checks='-*,footarget-portability-*,google-runtime-int-std' (off the cuff example). Not sure if that's what you meant by "labels", but I see that as being orthogonal to the question of what a user should be forced to take action on.
tools/llvm-project/extra/test/clang-tidy/werrors-plural.cpp | ||
---|---|---|
7 | ok, sounds good. |
Thank you for explaining. The use case seems to be important enough to support it. And the solution seems to be good for now. A few concerns:
- Werrors isn't a good name for this. The only reason why a similar thing is called -Werror in compilers is that they use -W for warnings. I'd suggest TreatAsErrors, WarningsAsErrors or anything similar (with the proper casing change for the command line argument).
- Documentation is missing.
Looks good with a couple of nits. I'll be happy to submit your patch once you address the comments.
Also, please include more context in your patches. See http://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface.
clang-tidy/ClangTidy.cpp | ||
---|---|---|
156 ↗ | (On Diff #44650) | I'd call it getWarningsAsErrorsCount() |
clang-tidy/ClangTidyOptions.cpp | ||
130 ↗ | (On Diff #44650) | This line exceeds column limit. Please run clang-format on the changed files. |
Weird. That's probably because I've not marked it "Accepted". Now I tried a few other actions on the revision and it now shows as authored by myself. Really weird.
Anyway, thank you for working on this!
clang-tidy/tool/ClangTidyMain.cpp | ||
---|---|---|
362 ↗ | (On Diff #44759) | Was there any specific reason for returning the error count instead of returning 1. It results in undefined behaviour on POSIX shells if a value is returned outside the range of 0<=n<=255. See https://bugs.llvm.org/show_bug.cgi?id=46305 |
hardcoding happens here ^