Fix an off by 1 bug that prevented SmallPtrSet from using all of its 'small' capacity...
authorCraig Topper <craig.topper@gmail.com>
Wed, 20 Aug 2014 04:41:36 +0000 (04:41 +0000)
committerCraig Topper <craig.topper@gmail.com>
Wed, 20 Aug 2014 04:41:36 +0000 (04:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216044 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/SmallPtrSet.cpp

index a80e095ec35a927a7c1a3adb81a71a9b771539be..621b90fa75572bfe4c534a90a1238cac24a3a66f 100644 (file)
@@ -43,7 +43,7 @@ bool SmallPtrSetImplBase::insert_imp(const void * Ptr) {
         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(const void **SmallStorage,
   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);