summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Dergachev <artem.dergachev@gmail.com>2019-01-18 00:16:25 +0000
committerArtem Dergachev <artem.dergachev@gmail.com>2019-01-18 00:16:25 +0000
commit342a7ac8d6419aec9a79ea4ac3c93bbb6beeba26 (patch)
tree51c050b8cd9c68f5d9acd632f19065ea8c9863d4
parent2ed0e79bb8efc3d642e3d8212e17a160f5ebb499 (diff)
downloadbcm5719-llvm-342a7ac8d6419aec9a79ea4ac3c93bbb6beeba26.tar.gz
bcm5719-llvm-342a7ac8d6419aec9a79ea4ac3c93bbb6beeba26.zip
[analyzer] MoveChecker: Add one more common resetting method, "append".
This is especially crucial for reports related to use-after-move of standard library objects. rdar://problem/47338505 Differential Revision: https://reviews.llvm.org/D56824 llvm-svn: 351500
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp6
-rw-r--r--clang/test/Analysis/use-after-move.cpp8
2 files changed, 11 insertions, 3 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
index 6efa2dfbe5b..95b5ac6d1dd 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
@@ -502,9 +502,9 @@ bool MoveChecker::isStateResetMethod(const CXXMethodDecl *MethodDec) const {
std::string MethodName = MethodDec->getName().lower();
// TODO: Some of these methods (eg., resize) are not always resetting
// the state, so we should consider looking at the arguments.
- if (MethodName == "reset" || MethodName == "clear" ||
- MethodName == "destroy" || MethodName == "resize" ||
- MethodName == "shrink")
+ if (MethodName == "assign" || MethodName == "clear" ||
+ MethodName == "destroy" || MethodName == "reset" ||
+ MethodName == "resize" || MethodName == "shrink")
return true;
}
return false;
diff --git a/clang/test/Analysis/use-after-move.cpp b/clang/test/Analysis/use-after-move.cpp
index 280724512f8..435976c5a7c 100644
--- a/clang/test/Analysis/use-after-move.cpp
+++ b/clang/test/Analysis/use-after-move.cpp
@@ -89,6 +89,7 @@ public:
void destroy();
void clear();
void resize(std::size_t);
+ void assign(const A &);
bool empty() const;
bool isEmpty() const;
operator bool() const;
@@ -531,6 +532,13 @@ void moveStateResetFunctionsTest() {
a.foo(); // no-warning
a.b.foo(); // no-warning
}
+ {
+ A a;
+ A b = std::move(a);
+ a.assign(A()); // no-warning
+ a.foo(); // no-warning
+ a.b.foo(); // no-warning
+ }
}
// Moves or uses that occur as part of template arguments.
OpenPOWER on IntegriCloud