mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-12 17:32:19 +00:00
Revert "Fix allocations of SmallVector and SmallPtrSet so they are more prone to"
This reverts commit 617330909f0c26a3f2ab8601a029b9bdca48aa61. It broke the bots: /home/clangbuild2/clang-ppc64-2/llvm.src/unittests/ADT/SmallVectorTest.cpp:150: PushPopTest /home/clangbuild2/clang-ppc64-2/llvm.src/unittests/ADT/SmallVectorTest.cpp:118: Failure Value of: v[i].getValue() Actual: 0 Expected: value Which is: 2 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178334 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
617330909f
commit
ef484a376c
@ -54,6 +54,8 @@ protected:
|
|||||||
/// then the set is in 'small mode'.
|
/// then the set is in 'small mode'.
|
||||||
const void **CurArray;
|
const void **CurArray;
|
||||||
/// CurArraySize - The allocated size of CurArray, always a power of two.
|
/// CurArraySize - The allocated size of CurArray, always a power of two.
|
||||||
|
/// Note that CurArray points to an array that has CurArraySize+1 elements in
|
||||||
|
/// it, so that the end iterator actually points to valid memory.
|
||||||
unsigned CurArraySize;
|
unsigned CurArraySize;
|
||||||
|
|
||||||
// If small, this is # elts allocated consecutively
|
// If small, this is # elts allocated consecutively
|
||||||
@ -66,6 +68,9 @@ protected:
|
|||||||
SmallArray(SmallStorage), CurArray(SmallStorage), CurArraySize(SmallSize) {
|
SmallArray(SmallStorage), CurArray(SmallStorage), CurArraySize(SmallSize) {
|
||||||
assert(SmallSize && (SmallSize & (SmallSize-1)) == 0 &&
|
assert(SmallSize && (SmallSize & (SmallSize-1)) == 0 &&
|
||||||
"Initial size must be a power of two!");
|
"Initial size must be a power of two!");
|
||||||
|
// The end pointer, always valid, is set to a valid element to help the
|
||||||
|
// iterator.
|
||||||
|
CurArray[SmallSize] = 0;
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
~SmallPtrSetImpl();
|
~SmallPtrSetImpl();
|
||||||
@ -142,11 +147,9 @@ protected:
|
|||||||
class SmallPtrSetIteratorImpl {
|
class SmallPtrSetIteratorImpl {
|
||||||
protected:
|
protected:
|
||||||
const void *const *Bucket;
|
const void *const *Bucket;
|
||||||
const void *const *End;
|
|
||||||
public:
|
public:
|
||||||
explicit SmallPtrSetIteratorImpl(const void *const *BP, const void*const *E)
|
explicit SmallPtrSetIteratorImpl(const void *const *BP) : Bucket(BP) {
|
||||||
: Bucket(BP), End(E) {
|
AdvanceIfNotValid();
|
||||||
AdvanceIfNotValid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const SmallPtrSetIteratorImpl &RHS) const {
|
bool operator==(const SmallPtrSetIteratorImpl &RHS) const {
|
||||||
@ -161,10 +164,8 @@ protected:
|
|||||||
/// that is. This is guaranteed to stop because the end() bucket is marked
|
/// that is. This is guaranteed to stop because the end() bucket is marked
|
||||||
/// valid.
|
/// valid.
|
||||||
void AdvanceIfNotValid() {
|
void AdvanceIfNotValid() {
|
||||||
assert(Bucket <= End);
|
while (*Bucket == SmallPtrSetImpl::getEmptyMarker() ||
|
||||||
while (Bucket != End &&
|
*Bucket == SmallPtrSetImpl::getTombstoneMarker())
|
||||||
(*Bucket == SmallPtrSetImpl::getEmptyMarker() ||
|
|
||||||
*Bucket == SmallPtrSetImpl::getTombstoneMarker()))
|
|
||||||
++Bucket;
|
++Bucket;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -181,13 +182,12 @@ public:
|
|||||||
typedef std::ptrdiff_t difference_type;
|
typedef std::ptrdiff_t difference_type;
|
||||||
typedef std::forward_iterator_tag iterator_category;
|
typedef std::forward_iterator_tag iterator_category;
|
||||||
|
|
||||||
explicit SmallPtrSetIterator(const void *const *BP, const void *const *E)
|
explicit SmallPtrSetIterator(const void *const *BP)
|
||||||
: SmallPtrSetIteratorImpl(BP, E) {}
|
: SmallPtrSetIteratorImpl(BP) {}
|
||||||
|
|
||||||
// Most methods provided by baseclass.
|
// Most methods provided by baseclass.
|
||||||
|
|
||||||
const PtrTy operator*() const {
|
const PtrTy operator*() const {
|
||||||
assert(Bucket < End);
|
|
||||||
return PtrTraits::getFromVoidPointer(const_cast<void*>(*Bucket));
|
return PtrTraits::getFromVoidPointer(const_cast<void*>(*Bucket));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,8 +236,9 @@ template<class PtrType, unsigned SmallSize>
|
|||||||
class SmallPtrSet : public SmallPtrSetImpl {
|
class SmallPtrSet : public SmallPtrSetImpl {
|
||||||
// Make sure that SmallSize is a power of two, round up if not.
|
// Make sure that SmallSize is a power of two, round up if not.
|
||||||
enum { SmallSizePowTwo = RoundUpToPowerOfTwo<SmallSize>::Val };
|
enum { SmallSizePowTwo = RoundUpToPowerOfTwo<SmallSize>::Val };
|
||||||
/// SmallStorage - Fixed size storage used in 'small mode'.
|
/// SmallStorage - Fixed size storage used in 'small mode'. The extra element
|
||||||
const void *SmallStorage[SmallSizePowTwo];
|
/// ensures that the end iterator actually points to valid memory.
|
||||||
|
const void *SmallStorage[SmallSizePowTwo+1];
|
||||||
typedef PointerLikeTypeTraits<PtrType> PtrTraits;
|
typedef PointerLikeTypeTraits<PtrType> PtrTraits;
|
||||||
public:
|
public:
|
||||||
SmallPtrSet() : SmallPtrSetImpl(SmallStorage, SmallSizePowTwo) {}
|
SmallPtrSet() : SmallPtrSetImpl(SmallStorage, SmallSizePowTwo) {}
|
||||||
@ -274,10 +275,10 @@ public:
|
|||||||
typedef SmallPtrSetIterator<PtrType> iterator;
|
typedef SmallPtrSetIterator<PtrType> iterator;
|
||||||
typedef SmallPtrSetIterator<PtrType> const_iterator;
|
typedef SmallPtrSetIterator<PtrType> const_iterator;
|
||||||
inline iterator begin() const {
|
inline iterator begin() const {
|
||||||
return iterator(CurArray, CurArray+CurArraySize);
|
return iterator(CurArray);
|
||||||
}
|
}
|
||||||
inline iterator end() const {
|
inline iterator end() const {
|
||||||
return iterator(CurArray+CurArraySize, CurArray+CurArraySize);
|
return iterator(CurArray+CurArraySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow assignment from any smallptrset with the same element type even if it
|
// Allow assignment from any smallptrset with the same element type even if it
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
#include "llvm/Support/AlignOf.h"
|
#include "llvm/Support/AlignOf.h"
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
#include "llvm/Support/MathExtras.h"
|
|
||||||
#include "llvm/Support/type_traits.h"
|
#include "llvm/Support/type_traits.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
@ -268,8 +267,7 @@ template <typename T, bool isPodLike>
|
|||||||
void SmallVectorTemplateBase<T, isPodLike>::grow(size_t MinSize) {
|
void SmallVectorTemplateBase<T, isPodLike>::grow(size_t MinSize) {
|
||||||
size_t CurCapacity = this->capacity();
|
size_t CurCapacity = this->capacity();
|
||||||
size_t CurSize = this->size();
|
size_t CurSize = this->size();
|
||||||
// Always grow, even from zero.
|
size_t NewCapacity = 2*CurCapacity + 1; // Always grow, even from zero.
|
||||||
size_t NewCapacity = NextPowerOf2(2*CurCapacity+(CurCapacity==0));
|
|
||||||
if (NewCapacity < MinSize)
|
if (NewCapacity < MinSize)
|
||||||
NewCapacity = MinSize;
|
NewCapacity = MinSize;
|
||||||
T *NewElts = static_cast<T*>(malloc(NewCapacity*sizeof(T)));
|
T *NewElts = static_cast<T*>(malloc(NewCapacity*sizeof(T)));
|
||||||
|
@ -29,9 +29,13 @@ void SmallPtrSetImpl::shrink_and_clear() {
|
|||||||
NumElements = NumTombstones = 0;
|
NumElements = NumTombstones = 0;
|
||||||
|
|
||||||
// Install the new array. Clear all the buckets to empty.
|
// Install the new array. Clear all the buckets to empty.
|
||||||
CurArray = (const void**)malloc(sizeof(void*) * CurArraySize);
|
CurArray = (const void**)malloc(sizeof(void*) * (CurArraySize+1));
|
||||||
assert(CurArray && "Failed to allocate memory?");
|
assert(CurArray && "Failed to allocate memory?");
|
||||||
memset(CurArray, -1, CurArraySize*sizeof(void*));
|
memset(CurArray, -1, CurArraySize*sizeof(void*));
|
||||||
|
|
||||||
|
// The end pointer, always valid, is set to a valid element to help the
|
||||||
|
// iterator.
|
||||||
|
CurArray[CurArraySize] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SmallPtrSetImpl::insert_imp(const void * Ptr) {
|
bool SmallPtrSetImpl::insert_imp(const void * Ptr) {
|
||||||
@ -135,11 +139,15 @@ void SmallPtrSetImpl::Grow(unsigned NewSize) {
|
|||||||
bool WasSmall = isSmall();
|
bool WasSmall = isSmall();
|
||||||
|
|
||||||
// Install the new array. Clear all the buckets to empty.
|
// Install the new array. Clear all the buckets to empty.
|
||||||
CurArray = (const void**)malloc(sizeof(void*) * NewSize);
|
CurArray = (const void**)malloc(sizeof(void*) * (NewSize+1));
|
||||||
assert(CurArray && "Failed to allocate memory?");
|
assert(CurArray && "Failed to allocate memory?");
|
||||||
CurArraySize = NewSize;
|
CurArraySize = NewSize;
|
||||||
memset(CurArray, -1, NewSize*sizeof(void*));
|
memset(CurArray, -1, NewSize*sizeof(void*));
|
||||||
|
|
||||||
|
// The end pointer, always valid, is set to a valid element to help the
|
||||||
|
// iterator.
|
||||||
|
CurArray[NewSize] = 0;
|
||||||
|
|
||||||
// Copy over all the elements.
|
// Copy over all the elements.
|
||||||
if (WasSmall) {
|
if (WasSmall) {
|
||||||
// Small sets store their elements in order.
|
// Small sets store their elements in order.
|
||||||
@ -172,7 +180,7 @@ SmallPtrSetImpl::SmallPtrSetImpl(const void **SmallStorage,
|
|||||||
CurArray = SmallArray;
|
CurArray = SmallArray;
|
||||||
// Otherwise, allocate new heap space (unless we were the same size)
|
// Otherwise, allocate new heap space (unless we were the same size)
|
||||||
} else {
|
} else {
|
||||||
CurArray = (const void**)malloc(sizeof(void*) * that.CurArraySize);
|
CurArray = (const void**)malloc(sizeof(void*) * (that.CurArraySize+1));
|
||||||
assert(CurArray && "Failed to allocate memory?");
|
assert(CurArray && "Failed to allocate memory?");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +188,7 @@ SmallPtrSetImpl::SmallPtrSetImpl(const void **SmallStorage,
|
|||||||
CurArraySize = that.CurArraySize;
|
CurArraySize = that.CurArraySize;
|
||||||
|
|
||||||
// Copy over the contents from the other set
|
// Copy over the contents from the other set
|
||||||
memcpy(CurArray, that.CurArray, sizeof(void*)*CurArraySize);
|
memcpy(CurArray, that.CurArray, sizeof(void*)*(CurArraySize+1));
|
||||||
|
|
||||||
NumElements = that.NumElements;
|
NumElements = that.NumElements;
|
||||||
NumTombstones = that.NumTombstones;
|
NumTombstones = that.NumTombstones;
|
||||||
@ -201,9 +209,9 @@ void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) {
|
|||||||
// Otherwise, allocate new heap space (unless we were the same size)
|
// Otherwise, allocate new heap space (unless we were the same size)
|
||||||
} else if (CurArraySize != RHS.CurArraySize) {
|
} else if (CurArraySize != RHS.CurArraySize) {
|
||||||
if (isSmall())
|
if (isSmall())
|
||||||
CurArray = (const void**)malloc(sizeof(void*) * RHS.CurArraySize);
|
CurArray = (const void**)malloc(sizeof(void*) * (RHS.CurArraySize+1));
|
||||||
else
|
else
|
||||||
CurArray = (const void**)realloc(CurArray, sizeof(void*)*RHS.CurArraySize);
|
CurArray = (const void**)realloc(CurArray, sizeof(void*)*(RHS.CurArraySize+1));
|
||||||
assert(CurArray && "Failed to allocate memory?");
|
assert(CurArray && "Failed to allocate memory?");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,7 +219,7 @@ void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) {
|
|||||||
CurArraySize = RHS.CurArraySize;
|
CurArraySize = RHS.CurArraySize;
|
||||||
|
|
||||||
// Copy over the contents from the other set
|
// Copy over the contents from the other set
|
||||||
memcpy(CurArray, RHS.CurArray, sizeof(void*)*CurArraySize);
|
memcpy(CurArray, RHS.CurArray, sizeof(void*)*(CurArraySize+1));
|
||||||
|
|
||||||
NumElements = RHS.NumElements;
|
NumElements = RHS.NumElements;
|
||||||
NumTombstones = RHS.NumTombstones;
|
NumTombstones = RHS.NumTombstones;
|
||||||
|
@ -17,61 +17,6 @@
|
|||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
// SmallPtrSet swapping test.
|
// SmallPtrSet swapping test.
|
||||||
TEST(SmallPtrSetTest, GrowthTest) {
|
|
||||||
int i;
|
|
||||||
int buf[8];
|
|
||||||
for(i=0; i<8; ++i) buf[i]=0;
|
|
||||||
|
|
||||||
|
|
||||||
SmallPtrSet<int *, 4> s;
|
|
||||||
typedef SmallPtrSet<int *, 4>::iterator iter;
|
|
||||||
|
|
||||||
s.insert(&buf[0]);
|
|
||||||
s.insert(&buf[1]);
|
|
||||||
s.insert(&buf[2]);
|
|
||||||
s.insert(&buf[3]);
|
|
||||||
EXPECT_EQ(4U, s.size());
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
for(iter I=s.begin(), E=s.end(); I!=E; ++I, ++i)
|
|
||||||
(**I)++;
|
|
||||||
EXPECT_EQ(4, i);
|
|
||||||
for(i=0; i<8; ++i)
|
|
||||||
EXPECT_EQ(i<4?1:0,buf[i]);
|
|
||||||
|
|
||||||
s.insert(&buf[4]);
|
|
||||||
s.insert(&buf[5]);
|
|
||||||
s.insert(&buf[6]);
|
|
||||||
s.insert(&buf[7]);
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
for(iter I=s.begin(), E=s.end(); I!=E; ++I, ++i)
|
|
||||||
(**I)++;
|
|
||||||
EXPECT_EQ(8, i);
|
|
||||||
s.erase(&buf[4]);
|
|
||||||
s.erase(&buf[5]);
|
|
||||||
s.erase(&buf[6]);
|
|
||||||
s.erase(&buf[7]);
|
|
||||||
EXPECT_EQ(4U, s.size());
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
for(iter I=s.begin(), E=s.end(); I!=E; ++I, ++i)
|
|
||||||
(**I)++;
|
|
||||||
EXPECT_EQ(4, i);
|
|
||||||
for(i=0; i<8; ++i)
|
|
||||||
EXPECT_EQ(i<4?3:1,buf[i]);
|
|
||||||
|
|
||||||
s.clear();
|
|
||||||
for(i=0; i<8; ++i) buf[i]=0;
|
|
||||||
for(i=0; i<128; ++i) s.insert(&buf[i%8]); // test repeated entires
|
|
||||||
EXPECT_EQ(8U, s.size());
|
|
||||||
for(iter I=s.begin(), E=s.end(); I!=E; ++I, ++i)
|
|
||||||
(**I)++;
|
|
||||||
for(i=0; i<8; ++i)
|
|
||||||
EXPECT_EQ(1,buf[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TEST(SmallPtrSetTest, SwapTest) {
|
TEST(SmallPtrSetTest, SwapTest) {
|
||||||
int buf[10];
|
int buf[10];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user