Fix an error in the assignment operator that was causing an infinite loop in GVNPRE...
authorOwen Anderson <resistor@mac.com>
Mon, 9 Jul 2007 18:51:15 +0000 (18:51 +0000)
committerOwen Anderson <resistor@mac.com>
Mon, 9 Jul 2007 18:51:15 +0000 (18:51 +0000)
Patch by Chis Lattner.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@38467 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/SmallPtrSet.cpp

index 81c4bc752fb2d9ecad48a08a2db11bf6b0f3e063..5ad243033fcf37e71e7d938865f2e3b8b606d5a0 100644 (file)
@@ -182,6 +182,8 @@ void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) {
     if (!isSmall())
       delete [] CurArray;
     
+    NumElements = NumTombstones = 0;
+    
     // Get a power of two larger than twice the RHS size.
     CurArraySize = 1 << Log2_32(RHS.size()*4);
     
@@ -199,12 +201,18 @@ void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) {
   
   // Now that we know we have enough space, and that the current array is empty,
   // copy over all the elements from the RHS.
-  
   for (void **BucketPtr = RHS.CurArray, **E = RHS.CurArray+RHS.CurArraySize;
        BucketPtr != E; ++BucketPtr) {
     // Copy over the element if it is valid.
     void *Elt = *BucketPtr;
-    if (Elt != getTombstoneMarker() && Elt != getEmptyMarker())
-      *const_cast<void**>(FindBucketFor(Elt)) = Elt;
+    if (Elt != getTombstoneMarker() && Elt != getEmptyMarker()) {
+      if (isSmall())
+        SmallArray[NumElements++] = Elt;
+      else
+        *const_cast<void**>(FindBucketFor(Elt)) = Elt;
+    }
   }
+  
+  if (!isSmall())
+    NumElements = RHS.NumElements;
 }