summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/ADT/SmallPtrSet.h6
-rw-r--r--lib/Support/SmallPtrSet.cpp5
2 files changed, 7 insertions, 4 deletions
diff --git a/include/llvm/ADT/SmallPtrSet.h b/include/llvm/ADT/SmallPtrSet.h
index c7f5e5bfc0..b52aebf7d5 100644
--- a/include/llvm/ADT/SmallPtrSet.h
+++ b/include/llvm/ADT/SmallPtrSet.h
@@ -293,14 +293,16 @@ public:
SmallPtrSet<PtrType, SmallSize> &
operator=(const SmallPtrSet<PtrType, SmallSize> &RHS) {
- CopyFrom(RHS);
+ if (&RHS != this)
+ CopyFrom(RHS);
return *this;
}
#if LLVM_HAS_RVALUE_REFERENCES
SmallPtrSet<PtrType, SmallSize>&
operator=(SmallPtrSet<PtrType, SmallSize> &&RHS) {
- MoveFrom(SmallSizePowTwo, std::move(RHS));
+ if (&RHS != this)
+ MoveFrom(SmallSizePowTwo, std::move(RHS));
return *this;
}
#endif
diff --git a/lib/Support/SmallPtrSet.cpp b/lib/Support/SmallPtrSet.cpp
index fa8d91545e..f873d91d6e 100644
--- a/lib/Support/SmallPtrSet.cpp
+++ b/lib/Support/SmallPtrSet.cpp
@@ -218,8 +218,7 @@ SmallPtrSetImpl::SmallPtrSetImpl(const void **SmallStorage, unsigned SmallSize,
/// 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) {
- if (&RHS == this)
- return;
+ assert(&RHS != this && "Self-copy should be handled by the caller.");
if (isSmall() && RHS.isSmall())
assert(CurArraySize == RHS.CurArraySize &&
@@ -256,6 +255,8 @@ void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) {
#if LLVM_HAS_RVALUE_REFERENCES
void SmallPtrSetImpl::MoveFrom(unsigned SmallSize, SmallPtrSetImpl &&RHS) {
+ assert(&RHS != this && "Self-move should be handled by the caller.");
+
if (!isSmall())
free(CurArray);