[analyzer] MallocChecker: Suppress false positives in shared pointers.
authorArtem Dergachev <artem.dergachev@gmail.com>
Tue, 27 Feb 2018 21:19:33 +0000 (21:19 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Tue, 27 Feb 2018 21:19:33 +0000 (21:19 +0000)
commit5337efc69cdd59950faf0579043eb7aa8b9a3f2e
tree9d88ce04723033e99770a888d0e2023c34075fcc
parentdff5a44f29f758f7e02783f16686cdd93ddc21a7
[analyzer] MallocChecker: Suppress false positives in shared pointers.

Throw away MallocChecker warnings that occur after releasing a pointer within a
destructor (or its callees) after performing C11 atomic fetch_add or fetch_sub
within that destructor (or its callees).

This is an indication that the destructor's class is likely a
reference-counting pointer. The analyzer is not able to understand that the
original reference count is usually large enough to avoid most use-after-frees.

Even when the smart pointer is a local variable, we still have these false
positives that this patch suppresses, because the analyzer doesn't currently
support atomics well enough.

Differential Revision: https://reviews.llvm.org/D43791

llvm-svn: 326249
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/test/Analysis/NewDelete-atomics.cpp [new file with mode: 0644]