[PATCH] D45532: [StaticAnalyzer] Checker to find uninitialized fields after a constructor call

Umann Kristóf via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 25 02:35:41 PDT 2018


Szelethus updated this revision to Diff 143875.
Szelethus added a comment.

In this diff I

- added a `Pedantic` flag that is set to false by default to filter out results from objects that don't have a single field initialized,
- made it so that fields that are declared in system headers are now ignored,
- refactored `isFullyInitialized` to `hasUnintializedFields` (it returned true when there were in fact uninit fields),
- fixed everything mentioned in inline comments aside from the naming and the category,
- added TODOs for `FieldChainInfo::toString`, I decided to fix those in a later patch to keep the diff just a little bit smaller,
- added many more test cases, including tests for the `Pedantic` flag
- added support for arrays. Granted, they worked wonderfully with the checker before, but there was nothing mentioned about them in the code.

If you like how I implemented the `Pedantic` flag, then I think only the naming and choosing the correct category is left.

I also rechecked the entire LLVM/Clang project before the system header fix and after the fix with `Pedantic` set to true and set to false. Here are my findings:

How many reports did the checker emit?

- Without fields in system headers being ignored: 208 (only functional had some fields uninitialized)
- With fields in system headers being ignored and `Pedantic` set to true: 181
- With fields in system headers being ignored and `Pedantic` set to false: 150

Most of these are intentional, as a very large portion of the project is performance critical. I did however find some constructors with the checker that would benefit from having the rest of their fields initialized.
I also found some constructors that didn't use `= default` for no good reason.


https://reviews.llvm.org/D45532

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/CtorUninitializedMemberChecker.cpp
  test/Analysis/Inputs/system-header-simulator-ctor-uninitialized-member.h
  test/Analysis/ctor-uninitialized-member-inheritance.cpp
  test/Analysis/ctor-uninitialized-member.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45532.143875.patch
Type: text/x-patch
Size: 68969 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180425/5686a67a/attachment-0001.bin>


More information about the cfe-commits mailing list