projects
/
oota-llvm.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix bug 20125 - clang-format segfaults on bad config.
[oota-llvm.git]
/
lib
/
Support
/
SmallPtrSet.cpp
diff --git
a/lib/Support/SmallPtrSet.cpp
b/lib/Support/SmallPtrSet.cpp
index 9b86a7935138cc1aa716fe157d635a31f2400675..a80e095ec35a927a7c1a3adb81a71a9b771539be 100644
(file)
--- a/
lib/Support/SmallPtrSet.cpp
+++ b/
lib/Support/SmallPtrSet.cpp
@@
-20,7
+20,7
@@
using namespace llvm;
using namespace llvm;
-void SmallPtrSetImpl::shrink_and_clear() {
+void SmallPtrSetImpl
Base
::shrink_and_clear() {
assert(!isSmall() && "Can't shrink a small set!");
free(CurArray);
assert(!isSmall() && "Can't shrink a small set!");
free(CurArray);
@@
-34,7
+34,7
@@
void SmallPtrSetImpl::shrink_and_clear() {
memset(CurArray, -1, CurArraySize*sizeof(void*));
}
memset(CurArray, -1, CurArraySize*sizeof(void*));
}
-bool SmallPtrSetImpl::insert_imp(const void * Ptr) {
+bool SmallPtrSetImpl
Base
::insert_imp(const void * Ptr) {
if (isSmall()) {
// Check to see if it is already in the set.
for (const void **APtr = SmallArray, **E = SmallArray+NumElements;
if (isSmall()) {
// Check to see if it is already in the set.
for (const void **APtr = SmallArray, **E = SmallArray+NumElements;
@@
-71,7
+71,7
@@
bool SmallPtrSetImpl::insert_imp(const void * Ptr) {
return true;
}
return true;
}
-bool SmallPtrSetImpl::erase_imp(const void * Ptr) {
+bool SmallPtrSetImpl
Base
::erase_imp(const void * Ptr) {
if (isSmall()) {
// Check to see if it is in the set.
for (const void **APtr = SmallArray, **E = SmallArray+NumElements;
if (isSmall()) {
// Check to see if it is in the set.
for (const void **APtr = SmallArray, **E = SmallArray+NumElements;
@@
-98,12
+98,12
@@
bool SmallPtrSetImpl::erase_imp(const void * Ptr) {
return true;
}
return true;
}
-const void * const *SmallPtrSetImpl::FindBucketFor(const void *Ptr) const {
+const void * const *SmallPtrSetImpl
Base
::FindBucketFor(const void *Ptr) const {
unsigned Bucket = DenseMapInfo<void *>::getHashValue(Ptr) & (CurArraySize-1);
unsigned ArraySize = CurArraySize;
unsigned ProbeAmt = 1;
const void *const *Array = CurArray;
unsigned Bucket = DenseMapInfo<void *>::getHashValue(Ptr) & (CurArraySize-1);
unsigned ArraySize = CurArraySize;
unsigned ProbeAmt = 1;
const void *const *Array = CurArray;
- const void *const *Tombstone =
0
;
+ const void *const *Tombstone =
nullptr
;
while (1) {
// Found Ptr's bucket?
if (Array[Bucket] == Ptr)
while (1) {
// Found Ptr's bucket?
if (Array[Bucket] == Ptr)
@@
-127,7
+127,7
@@
const void * const *SmallPtrSetImpl::FindBucketFor(const void *Ptr) const {
/// Grow - Allocate a larger backing store for the buckets and move it over.
///
/// Grow - Allocate a larger backing store for the buckets and move it over.
///
-void SmallPtrSetImpl::Grow(unsigned NewSize) {
+void SmallPtrSetImpl
Base
::Grow(unsigned NewSize) {
// Allocate at twice as many buckets, but at least 128.
unsigned OldSize = CurArraySize;
// Allocate at twice as many buckets, but at least 128.
unsigned OldSize = CurArraySize;
@@
-163,8
+163,8
@@
void SmallPtrSetImpl::Grow(unsigned NewSize) {
}
}
}
}
-SmallPtrSetImpl
::SmallPtrSetImpl
(const void **SmallStorage,
- const SmallPtrSetImpl& that) {
+SmallPtrSetImpl
Base::SmallPtrSetImplBase
(const void **SmallStorage,
+ const SmallPtrSetImpl
Base
& that) {
SmallArray = SmallStorage;
// If we're becoming small, prepare to insert into our stack space
SmallArray = SmallStorage;
// If we're becoming small, prepare to insert into our stack space
@@
-186,9
+186,9
@@
SmallPtrSetImpl::SmallPtrSetImpl(const void **SmallStorage,
NumTombstones = that.NumTombstones;
}
NumTombstones = that.NumTombstones;
}
-#if LLVM_HAS_RVALUE_REFERENCES
-
SmallPtrSetImpl::SmallPtrSetImpl(const void **SmallStorage,
unsigned SmallSize,
-
SmallPtrSetImpl
&&that) {
+SmallPtrSetImplBase::SmallPtrSetImplBase(const void **SmallStorage,
+
unsigned SmallSize,
+
SmallPtrSetImplBase
&&that) {
SmallArray = SmallStorage;
// Copy over the basic members.
SmallArray = SmallStorage;
// Copy over the basic members.
@@
-206,12
+206,19
@@
SmallPtrSetImpl::SmallPtrSetImpl(const void **SmallStorage, unsigned SmallSize,
// 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);
+ that.NumElements = 0;
+ that.NumTombstones = 0;
}
}
-#endif
/// CopyFrom - implement operator= from a smallptrset that has the same pointer
/// type, but may have a different small size.
/// CopyFrom - implement operator= from a smallptrset that has the same pointer
/// type, but may have a different small size.
-void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) {
+void SmallPtrSetImplBase::CopyFrom(const SmallPtrSetImplBase &RHS) {
+ assert(&RHS != this && "Self-copy should be handled by the caller.");
+
if (isSmall() && RHS.isSmall())
assert(CurArraySize == RHS.CurArraySize &&
"Cannot assign sets with different small sizes");
if (isSmall() && RHS.isSmall())
assert(CurArraySize == RHS.CurArraySize &&
"Cannot assign sets with different small sizes");
@@
-245,8
+252,10
@@
void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) {
NumTombstones = RHS.NumTombstones;
}
NumTombstones = RHS.NumTombstones;
}
-#if LLVM_HAS_RVALUE_REFERENCES
-void SmallPtrSetImpl::MoveFrom(SmallPtrSetImpl &&RHS) {
+void SmallPtrSetImplBase::MoveFrom(unsigned SmallSize,
+ SmallPtrSetImplBase &&RHS) {
+ assert(&RHS != this && "Self-move should be handled by the caller.");
+
if (!isSmall())
free(CurArray);
if (!isSmall())
free(CurArray);
@@
-263,10
+272,15
@@
void SmallPtrSetImpl::MoveFrom(SmallPtrSetImpl &&RHS) {
CurArraySize = RHS.CurArraySize;
NumElements = RHS.NumElements;
NumTombstones = RHS.NumTombstones;
CurArraySize = RHS.CurArraySize;
NumElements = RHS.NumElements;
NumTombstones = RHS.NumTombstones;
+
+ // Make the RHS small and empty.
+ RHS.CurArraySize = SmallSize;
+ assert(RHS.CurArray == RHS.SmallArray);
+ RHS.NumElements = 0;
+ RHS.NumTombstones = 0;
}
}
-#endif
-void SmallPtrSetImpl
::swap(SmallPtrSetImpl
&RHS) {
+void SmallPtrSetImpl
Base::swap(SmallPtrSetImplBase
&RHS) {
if (this == &RHS) return;
// We can only avoid copying elements if neither set is small.
if (this == &RHS) return;
// We can only avoid copying elements if neither set is small.
@@
-316,7
+330,7
@@
void SmallPtrSetImpl::swap(SmallPtrSetImpl &RHS) {
std::swap(this->NumElements, RHS.NumElements);
}
std::swap(this->NumElements, RHS.NumElements);
}
-SmallPtrSetImpl
::~SmallPtrSetImpl
() {
+SmallPtrSetImpl
Base::~SmallPtrSetImplBase
() {
if (!isSmall())
free(CurArray);
}
if (!isSmall())
free(CurArray);
}