[llvm] r216044 - Fix an off by 1 bug that prevented SmallPtrSet from using all of its 'small' capacity. Then fix the early return in the move constructor that prevented 'small' moves from clearing the NumElements in the moved from object. The directed test missed this because it was always testing large moves due to the off by 1 bug.

Craig Topper craig.topper at gmail.com
Tue Aug 19 21:41:36 PDT 2014


Author: ctopper
Date: Tue Aug 19 23:41:36 2014
New Revision: 216044

URL: http://llvm.org/viewvc/llvm-project?rev=216044&view=rev
Log:
Fix an off by 1 bug that prevented SmallPtrSet from using all of its 'small' capacity. Then fix the early return in the move constructor that prevented 'small' moves from clearing the NumElements in the moved from object. The directed test missed this because it was always testing large moves due to the off by 1 bug.

Modified:
    llvm/trunk/lib/Support/SmallPtrSet.cpp

Modified: llvm/trunk/lib/Support/SmallPtrSet.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SmallPtrSet.cpp?rev=216044&r1=216043&r2=216044&view=diff
==============================================================================
--- llvm/trunk/lib/Support/SmallPtrSet.cpp (original)
+++ llvm/trunk/lib/Support/SmallPtrSet.cpp Tue Aug 19 23:41:36 2014
@@ -43,7 +43,7 @@ bool SmallPtrSetImplBase::insert_imp(con
         return false;
     
     // Nope, there isn't.  If we stay small, just 'pushback' now.
-    if (NumElements < CurArraySize-1) {
+    if (NumElements < CurArraySize) {
       SmallArray[NumElements++] = Ptr;
       return true;
     }
@@ -200,13 +200,12 @@ SmallPtrSetImplBase::SmallPtrSetImplBase
   if (that.isSmall()) {
     CurArray = SmallArray;
     memcpy(CurArray, that.CurArray, sizeof(void *) * CurArraySize);
-    return;
+  } else {
+    // Otherwise, we steal the large memory allocation and no copy is needed.
+    CurArray = that.CurArray;
+    that.CurArray = that.SmallArray;
   }
 
-  // Otherwise, we steal the large memory allocation and no copy is needed.
-  CurArray = that.CurArray;
-  that.CurArray = that.SmallArray;
-
   // Make the "that" object small and empty.
   that.CurArraySize = SmallSize;
   assert(that.CurArray == that.SmallArray);





More information about the llvm-commits mailing list