This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Suppress false positives in std::shared_ptr
ClosedPublic

Authored by dcoughlin on Jul 6 2016, 8:55 AM.

Details

Reviewers
zaks.anna
NoQ
Summary

The analyzer does not model C++ temporary destructors completely and so reports false alarms about leaks of memory allocated by the internals of shared_ptr:

    
std::shared_ptr<int> p(new int(1));
p = nullptr; // 'Potential leak of memory pointed to by field __cntrl_'

To avoid these spurious diagnostics, this patch suppresses all diagnostics where the end of the path is inside a method in std::shared_ptr.

It also reorganizes the tests for suppressions in the C++ standard library to use a separate simulated header for library functions with bugs that were deliberately inserted to test suppression. This will prevent other tests from using these as models.

rdar://problem/23652766

Diff Detail

Event Timeline

dcoughlin updated this revision to Diff 62881.Jul 6 2016, 8:55 AM
dcoughlin retitled this revision from to [analyzer] Suppress false positives in std::shared_ptr.
dcoughlin updated this object.
dcoughlin added reviewers: zaks.anna, NoQ.
dcoughlin added a subscriber: cfe-commits.
zaks.anna accepted this revision.Jul 6 2016, 1:02 PM
zaks.anna edited edge metadata.

LGTM

This revision is now accepted and ready to land.Jul 6 2016, 1:02 PM
NoQ added inline comments.Jul 6 2016, 1:16 PM
test/Analysis/Inputs/system-header-simulator-cxx.h
249

You mean std::shared_ptr here?

Also, perhaps it's better to move this example into separate fake method; if this header emulator is used in another test, wouldn't the author of that test be surprised to see that operator=() is modeled that way?

dcoughlin added inline comments.Jul 6 2016, 1:35 PM
test/Analysis/Inputs/system-header-simulator-cxx.h
249

Yes, this is copy pasta!

249

Also, perhaps it's better to move this example into separate fake method; if this header emulator is used in another test, wouldn't the author of that test be surprised to see that operator=() is modeled that way?

We don't really model much in this this fake header, but I could move all the truly gross suppression stuff (basic string, _independent_bits_engine, shared_ptr) into a separate header and name it something that clearly indicates other tests shouldn't use it.

I'll update the patch.

dcoughlin updated this revision to Diff 62978.Jul 6 2016, 2:38 PM
dcoughlin updated this object.
dcoughlin edited edge metadata.

Address Artem's comments: fix a copy-pasta mistake and separate out std stubs with deliberate divide-by-zero bugs into their own simulated header file. This required moving the suppression tests into their own separate test.

NoQ accepted this revision.Jul 6 2016, 4:13 PM
NoQ edited edge metadata.

LGTM, all clear to me now :)

dcoughlin closed this revision.Jul 7 2016, 10:38 AM

This was committed in r274691. I forgot to add the Differential Revision line so phabricator didn't pick it up.