This is an archive of the discontinued LLVM Phabricator instance.

[analyzer][UninitializedObjectChecker] New flag to ignore records based on it's fields
ClosedPublic

Authored by Szelethus on Sep 5 2018, 4:47 AM.

Details

Summary

Based on a suggestion from @george.karpenkov.

In some cases, structs are used as unions with a help of a tag/kind field. This patch adds a new string flag (a pattern), that is matched against the fields of a record, and should a match be found, the entire record is ignored.

For more info refer to http://lists.llvm.org/pipermail/cfe-dev/2018-August/058906.html and to the responses to that, especially http://lists.llvm.org/pipermail/cfe-dev/2018-August/059215.html.

Diff Detail

Event Timeline

Szelethus created this revision.Sep 5 2018, 4:47 AM
Szelethus updated this revision to Diff 164050.Sep 5 2018, 8:38 AM

Added doc to www/analyzer/alpha_checks.html.

lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
468
  1. Since you are using match, you would reject an extra prefix - but what about an extra suffix?
  2. Would it make sense to expose the entire regexp as a flag? Then you could remove the boolean flag (if you can change the regexp to match if only the entire field name matches, then an empty regexp would correspond to "no matches")
Szelethus retitled this revision from [analyzer][UninitializedObjectChecker] New flag to ignore union-like constructs to [analyzer][UninitializedObjectChecker] New flag to ignore records based on it's fields.
Szelethus edited the summary of this revision. (Show Details)

Generalized the patch so that the user can supply the pattern that is matched against the fields of the records.

Szelethus marked an inline comment as done.Sep 10 2018, 10:31 AM
Szelethus added inline comments.
lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
468
  1. Added a new test case, seems to be fine ^-^
  2. Sounds cool, so I made it happen.
NoQ accepted this revision.Sep 13 2018, 7:15 PM

I hope we'll be able to come up with a reasonable default regex.

test/Analysis/cxx-uninitialized-object-unionlike-constructs.cpp
1–4

If you like, you can make a directory for your tests, instead of a filename prefix.

Btw, thanks for pointing out that we can use \ in run-lines, i never noticed it before you started using it.

This revision is now accepted and ready to land.Sep 13 2018, 7:15 PM
Szelethus marked an inline comment as done.Sep 14 2018, 3:07 AM
Szelethus added inline comments.
test/Analysis/cxx-uninitialized-object-unionlike-constructs.cpp
1–4

Cheers! I actually saw this trick in D45050.

This revision was automatically updated to reflect the committed changes.