Author: dergachev Date: Mon Dec 3 19:38:08 2018 New Revision: 348235 URL: http://llvm.org/viewvc/llvm-project?rev=348235&view=rev Log: [analyzer] MoveChecker: Add more common state resetting methods.
Includes "resize" and "shrink" because they can reset the object to a known state in certain circumstances. Differential Revision: https://reviews.llvm.org/D54563 Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp cfe/trunk/test/Analysis/use-after-move.cpp Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp?rev=348235&r1=348234&r2=348235&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp Mon Dec 3 19:38:08 2018 @@ -343,8 +343,11 @@ bool MoveChecker::isStateResetMethod(con return true; if (MethodDec->getDeclName().isIdentifier()) { 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 == "destroy" || MethodName == "resize" || + MethodName == "shrink") return true; } return false; Modified: cfe/trunk/test/Analysis/use-after-move.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/use-after-move.cpp?rev=348235&r1=348234&r2=348235&view=diff ============================================================================== --- cfe/trunk/test/Analysis/use-after-move.cpp (original) +++ cfe/trunk/test/Analysis/use-after-move.cpp Mon Dec 3 19:38:08 2018 @@ -15,6 +15,8 @@ namespace std { +typedef __typeof(sizeof(int)) size_t; + template <typename> struct remove_reference; @@ -110,6 +112,7 @@ public: void reset(); void destroy(); void clear(); + void resize(std::size_t); bool empty() const; bool isEmpty() const; operator bool() const; @@ -403,6 +406,13 @@ void moveStateResetFunctionsTest() { a.foo(); // no-warning a.b.foo(); // no-warning } + { + A a; + A b = std::move(a); + a.resize(0); // no-warning + a.foo(); // no-warning + a.b.foo(); // no-warning + } } // Moves or uses that occur as part of template arguments. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits