summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/SmallPtrSet.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@gmail.com>2014-08-20 04:41:36 +0000
committerCraig Topper <craig.topper@gmail.com>2014-08-20 04:41:36 +0000
commit298f63803b7195f366931fc23b5f7e8b8ec495ca (patch)
tree4de980b9db5e4d612e2c1cca9150e156fc50226c /llvm/lib/Support/SmallPtrSet.cpp
parentb8083476f11b6a8ba8976d28840c60cfb89070de (diff)
downloadbcm5719-llvm-298f63803b7195f366931fc23b5f7e8b8ec495ca.tar.gz
bcm5719-llvm-298f63803b7195f366931fc23b5f7e8b8ec495ca.zip
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.
llvm-svn: 216044
Diffstat (limited to 'llvm/lib/Support/SmallPtrSet.cpp')
-rw-r--r--llvm/lib/Support/SmallPtrSet.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/llvm/lib/Support/SmallPtrSet.cpp b/llvm/lib/Support/SmallPtrSet.cpp
index a80e095ec35..621b90fa755 100644
--- a/llvm/lib/Support/SmallPtrSet.cpp
+++ b/llvm/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);
OpenPOWER on IntegriCloud