This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Display the checker name in the text output
ClosedPublic

Authored by Szelethus on Mar 23 2020, 6:14 AM.

Details

Summary

Exactly what it says on the tin! There is no reason I think not to have this.

Also, I added test files for checkers that emit warning under the wrong name.

Diff Detail

Event Timeline

Szelethus created this revision.Mar 23 2020, 6:14 AM
martong added inline comments.Mar 23 2020, 6:54 AM
clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
95

StringRef? getCheckerName() returns with StringRef...

109–110

Why the .str() ?

clang/test/Analysis/incorrect-checker-names.mm
2

This seems like a copy of an existing test file, though I don't know which. Wouldn't it be better to adjust the original test file?

Szelethus marked 3 inline comments as done.Mar 23 2020, 7:32 AM
Szelethus added inline comments.
clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
95

Mind that we're constructing a string here from a bunch of smaller ones, we need an owning container. With that said, I could use a string stream instead.

109–110

StringRef no longer converts to std::string implicitly.

clang/test/Analysis/incorrect-checker-names.mm
2

Good observation, these test cases are indeed copied from other files. The justification behind it however is to highlight that these are the checkers that need fixing. Adding FIXMEs to other thousand-line test files don't grab the attention enough :)

NoQ added a comment.Mar 23 2020, 4:46 PM

Sounds great!

Does the checker name get printed on the final note as well in text output? We should probably test it.

clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
313–316

Why do we need an option? Is it just for tests? Is it for clang-tidy to avoid printing the checker name twice?

clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
109–110

But it seems to have been fine before(?)

clang/test/Analysis/incorrect-checker-names.cpp
7

Do you have a plan to address this FIXME? Does clang-tidy have the same problem?

Szelethus marked 3 inline comments as done.Mar 24 2020, 2:51 AM
Szelethus added inline comments.
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
313–316

Why do we need an option?

Well, we don't, but there is just no reason not to make this configurable, as seen in the debug checker test file. It would be unnecessary noise in their case.

Is it just for tests?

Tests are a big motivating factor, but it just doesn't hurt to know (just like in clang-tidy!). I suspect this change affects developers or powerusers more than any others, and could accelerate debugging and/or configuring just a tiny bit more.

Is it for clang-tidy to avoid printing the checker name twice?

Clang-tidy isnt affected, as they use the PD_NONE output type, not PD_TEXT.

clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
109–110

Mind that I changed the parameter of reportPiece to std::string from StringRef.

clang/test/Analysis/incorrect-checker-names.cpp
7

It does not. This is the issue of emitting reports under the wrong name, and I do have plans to address it, though I'm very anxious about RetainCountChecker. Its huge, the modeling/bug emission parts of it a very much intertwined, and me dum dum about ObjC.

NoQ added inline comments.Mar 24 2020, 4:20 AM
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
313–316

Clang-tidy isnt affected, as they use the PD_NONE output type, not PD_TEXT.

But they do have path notes printed out. It would have been terrible if they didn't have path notes.

Szelethus marked an inline comment as done.Mar 27 2020, 6:41 AM
Szelethus added inline comments.
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
313–316
Szelethus updated this revision to Diff 255668.Apr 7 2020, 6:57 AM
Szelethus marked 8 inline comments as done.

Fixing according to the reviews!

clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
109–110

Couldn't see the forest behind the trees :^)

martong accepted this revision.Apr 8 2020, 7:28 AM

I was just wondering if it would make sense to have a test with display-checker-name=true. Other than that, LGTM!

This revision is now accepted and ready to land.Apr 8 2020, 7:28 AM

I was just wondering if it would make sense to have a test with display-checker-name=true. Other than that, LGTM!

Could do! Thanks!

This revision was automatically updated to reflect the committed changes.