This revision was automatically updated to reflect the committed changes.
Closed by commit rC348235: [analyzer] MoveChecker: Add more common state 
resetting methods. (authored by dergachev, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D54563?vs=176512&id=176537#toc

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54563/new/

https://reviews.llvm.org/D54563

Files:
  lib/StaticAnalyzer/Checkers/MoveChecker.cpp
  test/Analysis/use-after-move.cpp


Index: lib/StaticAnalyzer/Checkers/MoveChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/MoveChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MoveChecker.cpp
@@ -343,8 +343,11 @@
       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;
Index: test/Analysis/use-after-move.cpp
===================================================================
--- test/Analysis/use-after-move.cpp
+++ test/Analysis/use-after-move.cpp
@@ -15,6 +15,8 @@
 
 namespace std {
 
+typedef __typeof(sizeof(int)) size_t;
+
 template <typename>
 struct remove_reference;
 
@@ -110,6 +112,7 @@
   void reset();
   void destroy();
   void clear();
+  void resize(std::size_t);
   bool empty() const;
   bool isEmpty() const;
   operator bool() const;
@@ -403,6 +406,13 @@
     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.


Index: lib/StaticAnalyzer/Checkers/MoveChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/MoveChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MoveChecker.cpp
@@ -343,8 +343,11 @@
       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;
Index: test/Analysis/use-after-move.cpp
===================================================================
--- test/Analysis/use-after-move.cpp
+++ test/Analysis/use-after-move.cpp
@@ -15,6 +15,8 @@
 
 namespace std {
 
+typedef __typeof(sizeof(int)) size_t;
+
 template <typename>
 struct remove_reference;
 
@@ -110,6 +112,7 @@
   void reset();
   void destroy();
   void clear();
+  void resize(std::size_t);
   bool empty() const;
   bool isEmpty() const;
   operator bool() const;
@@ -403,6 +406,13 @@
     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

Reply via email to