[llvm] r320408 - Ensure moved-from container is cleared on move

George Burgess IV via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 11 11:22:59 PST 2017


Author: gbiv
Date: Mon Dec 11 11:22:59 2017
New Revision: 320408

URL: http://llvm.org/viewvc/llvm-project?rev=320408&view=rev
Log:
Ensure moved-from container is cleared on move

In all cases except for this optimistic attempt to reuse memory, the
moved-from TinyPtrVector was left `empty()` at the end of this
assignment. Though using a container after it's been moved from can be a
bit sketchy, it's probably best to just be consistent here.

Modified:
    llvm/trunk/include/llvm/ADT/TinyPtrVector.h
    llvm/trunk/unittests/ADT/TinyPtrVectorTest.cpp

Modified: llvm/trunk/include/llvm/ADT/TinyPtrVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/TinyPtrVector.h?rev=320408&r1=320407&r2=320408&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/TinyPtrVector.h (original)
+++ llvm/trunk/include/llvm/ADT/TinyPtrVector.h Mon Dec 11 11:22:59 2017
@@ -97,6 +97,7 @@ public:
       if (RHS.Val.template is<EltTy>()) {
         V->clear();
         V->push_back(RHS.front());
+        RHS.Val = (EltTy)nullptr;
         return *this;
       }
       delete V;

Modified: llvm/trunk/unittests/ADT/TinyPtrVectorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/TinyPtrVectorTest.cpp?rev=320408&r1=320407&r2=320408&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/TinyPtrVectorTest.cpp (original)
+++ llvm/trunk/unittests/ADT/TinyPtrVectorTest.cpp Mon Dec 11 11:22:59 2017
@@ -152,6 +152,12 @@ TYPED_TEST(TinyPtrVectorTest, CopyAndMov
   TypeParam Move(std::move(Copy2));
   this->expectValues(Move, this->testArray(42));
   this->expectValues(Copy2, this->testArray(0));
+
+  TypeParam MultipleElements(this->testArray(2));
+  TypeParam SingleElement(this->testArray(1));
+  MultipleElements = std::move(SingleElement);
+  this->expectValues(MultipleElements, this->testArray(1));
+  this->expectValues(SingleElement, this->testArray(0));
 }
 
 TYPED_TEST(TinyPtrVectorTest, CopyAndMoveTest) {




More information about the llvm-commits mailing list