]> granicus.if.org Git - clang/commit
[analyzer] Add checker modeling potential C++ self-assignment
authorDevin Coughlin <dcoughlin@apple.com>
Thu, 21 Jul 2016 23:42:31 +0000 (23:42 +0000)
committerDevin Coughlin <dcoughlin@apple.com>
Thu, 21 Jul 2016 23:42:31 +0000 (23:42 +0000)
commit887e0c0ff4e75920ef06d921c79802eb4701e90a
tree545565cb735a596336935413d1f99bd59b49ba08
parent4c0ade365e84c43c9ca2431c4f13e71ca5340fe3
[analyzer] Add checker modeling potential C++ self-assignment

This checker checks copy and move assignment operators whether they are
protected against self-assignment. Since C++ core guidelines discourages
explicit checking for `&rhs==this` in general we take a different approach: in
top-frame analysis we branch the exploded graph for two cases, where &rhs==this
and &rhs!=this and let existing checkers (e.g. unix.Malloc) do the rest of the
work. It is important that we check all copy and move assignment operator in top
frame even if we checked them already since self-assignments may happen
undetected even in the same translation unit (e.g. using random indices for an
array what may or may not be the same).

This reapplies r275820 after fixing a string-lifetime issue discovered by the
bots.

A patch by Ádám Balogh!

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@276365 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/StaticAnalyzer/Checkers/Checkers.td
include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h
lib/StaticAnalyzer/Checkers/CMakeLists.txt
lib/StaticAnalyzer/Checkers/CXXSelfAssignmentChecker.cpp [new file with mode: 0644]
lib/StaticAnalyzer/Core/BugReporter.cpp
lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
test/Analysis/self-assign.cpp [new file with mode: 0644]