From: Craig Topper Date: Wed, 20 Aug 2014 04:41:36 +0000 (+0000) Subject: Fix an off by 1 bug that prevented SmallPtrSet from using all of its 'small' capacity... X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=78832c6e7d33094c6ef9e99b07dac6f60c0a1207;hp=ae8d297579f7fef5faa19bc4211347a252374914;p=oota-llvm.git 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216044 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Support/SmallPtrSet.cpp b/lib/Support/SmallPtrSet.cpp index a80e095ec35..621b90fa755 100644 --- a/lib/Support/SmallPtrSet.cpp +++ b/lib/Support/SmallPtrSet.cpp @@ -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);