]> granicus.if.org Git - clang/commit
[analyzer] Add checker modeling potential C++ self-assignment
authorDevin Coughlin <dcoughlin@apple.com>
Mon, 18 Jul 2016 17:23:30 +0000 (17:23 +0000)
committerDevin Coughlin <dcoughlin@apple.com>
Mon, 18 Jul 2016 17:23:30 +0000 (17:23 +0000)
commit2cc3f4d704218646d2b4845f8535aa982f318f16
treebd539febd7f8cb17ec5a03bde7c958eaf8fbeb15
parentab11ab0ba3a8ff24a8d6b4d06fc4aa1a0568571d
[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).

A patch by Ádám Balogh!

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275820 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]