This is an archive of the discontinued LLVM Phabricator instance.

[clang][Checkers] Fix PthreadLockChecker state cleanup at dead symbol.
ClosedPublic

Authored by balazske on Mar 12 2021, 7:10 AM.

Details

Summary

It is possible that an entry in 'DestroyRetVal' lives longer
than an entry in 'LockMap' if not removed at checkDeadSymbols.
The added test case demonstrates this.

Diff Detail

Event Timeline

balazske created this revision.Mar 12 2021, 7:10 AM
balazske requested review of this revision.Mar 12 2021, 7:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 12 2021, 7:10 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
balazske updated this revision to Diff 330243.Mar 12 2021, 7:17 AM

Improved commit message.

balazske retitled this revision from [clang][Checkers] Fix state cleanup at dead symbol. to [clang][Checkers] Fix PthreadLockChecker state cleanup at dead symbol..Mar 12 2021, 7:27 AM
clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
290–305

I'm just wondering, did you think about such way of fixing?

NoQ accepted this revision.Mar 12 2021, 9:46 PM
NoQ added a subscriber: NoQ.

Hmm this probably even deserves a warning? Like, the mutex goes out of scope but we don't know whether we've successfully destroyed it? Even if we perform the check later, we can't do anything about it anymore? (not sure how bad it is in practice)

clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
290–305

This involves keeping dead regions in the program state. I'd be pretty worried about it.

This revision is now accepted and ready to land.Mar 12 2021, 9:46 PM
balazske added a comment.EditedMar 16 2021, 1:08 AM

Exactly the case is (I think) that the mutex goes out of scope and we have not checked if it was really destroyed. Still the program can check later if it was destroyed (like the if in the test case). A resource leak may be the problem (if destroy failed) so a warning like "possible resource leak if destroy call fails" can be added. The case is detected in checkDeadSymbols that may make adding a good warning more difficult.

clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
290–305

This was my first idea but did not like it because state is not cleaned up correctly. (And LockMap contains data about unaccessible mutex.)