[PATCH] D54563: [analyzer] MoveChecker Pt.4: Add a few more state reset methods.

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 14 18:57:29 PST 2018


NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet, rnkovacs, Szelethus.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, mikhail.ramalho, baloghadamsoftware.

This covers methods that //may// reset the state depending on the value of the argument: `resize()`, `shrink_to_fit()`, and `shrink()`. The latter is something i've seen on a custom collection; we don't have to hardcode those, but i guess it's a good safe way to be a bit better out of the box. As a TODO, we might want to warn anyway when the value of the argument is not `0`.


Repository:
  rC Clang

https://reviews.llvm.org/D54563

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


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
@@ -334,7 +334,8 @@
   if (MethodDec->getDeclName().isIdentifier()) {
     std::string MethodName = MethodDec->getName().lower();
     if (MethodName == "reset" || MethodName == "clear" ||
-        MethodName == "destroy")
+        MethodName == "destroy" || MethodName == "resize" ||
+        MethodName == "shrink" || MethodName == "shrink_to_fit")
       return true;
   }
   return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54563.174138.patch
Type: text/x-patch
Size: 1383 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181115/79682ec1/attachment.bin>


More information about the cfe-commits mailing list