This is an archive of the discontinued LLVM Phabricator instance.

[analyzer][UninitializedObjectChecker] Added "NotesAsWarnings" flag
ClosedPublic

Authored by Szelethus on Jun 18 2018, 9:23 AM.

Diff Detail

Repository
rC Clang

Event Timeline

Szelethus created this revision.Jun 18 2018, 9:23 AM

LGTM provided the nit on passing arguments is fixed.

lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
698

registerChecker passes through arguments to the constructor. Could we use that instead of mutable fields?

This revision is now accepted and ready to land.Jun 18 2018, 10:39 AM

I wonder if this could be done when plist is emitted generally, independent of any checks.

NoQ added inline comments.Jun 18 2018, 6:59 PM
lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
698

Really? Yay. I never noticed that. I think currently all checkers that need options use mutable fields for that purpose, and everybody thought it was intended to work this way.

I'm not super worried about fields being mutable because all checker callbacks are const (so you're still protected from mutating them in all of your code), but that'd definitely make the code look better.

NoQ added a comment.Jun 18 2018, 7:04 PM

Also, great, and can i has tests?^^

Like a simple code snippet with two // RUN: ... -analyzer-output=text lines and different expected-warnings/notes under #ifs.

Szelethus updated this revision to Diff 151866.Jun 19 2018, 1:23 AM
In D48285#1136059, @NoQ wrote:

Also, great, and can i has tests?^^

Like a simple code snippet with two // RUN: ... -analyzer-output=text lines and different expected-warnings/notes under #ifs.

I intended to, but forgot git add. Whoops. I didn't find a satisfying way to add it to the existing tests without surrounding the entire file with #if, so I added a new test file instead.

I wonder if this could be done when plist is emitted generally, independent of any checks.

Well, there's -analyzer-config notes-as-events=true. By the time plist files are generated, every warning is just regarded as an event (as far as I know).

lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
698

Well, I didn't really find that to be the case. Even if it was, getBooleanOption(StringRef, /*DefaultVal*/ bool, const ento::CheckerBase *); depends on the constructed checker, so I don't think I can pull this off.

There actually is a way to get boolean options without having to pass the checker as an argument, but then it wouldn't be a checker specific option:
-analyzer-config Pedantic=true
instead of
-analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true.

Szelethus retitled this revision from [analyzer]{UninitializedObjectChecker] Added "NotesAsWarnings" flag to [analyzer][UninitializedObjectChecker] Added "NotesAsWarnings" flag.Jun 23 2018, 4:31 AM
NoQ accepted this revision.Jun 26 2018, 4:42 PM

Looks great, thanks!

lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
698

Yeah, well, i guess if you just use this as the last argument of getBooleanOption(), you'll still have CheckName unset during construction.

A slight refactoring might help, but it doesn't currently work "out of the box".

This revision was automatically updated to reflect the committed changes.