[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)
commitf57f90dfd1c328fc8bb9d9009be0b7690a7bd761
tree5a1492613ac13a456f4b016e80e4c623c9bd957f
parentc107a4875e40d0aceb6f542803fc71e0cfe86e46
[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

llvm-svn: 276365
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h
clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
clang/lib/StaticAnalyzer/Checkers/CXXSelfAssignmentChecker.cpp [new file with mode: 0644]
clang/lib/StaticAnalyzer/Core/BugReporter.cpp
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
clang/test/Analysis/self-assign.cpp [new file with mode: 0644]