diff --git a/include/llvm/ADT/SmallPtrSet.h b/include/llvm/ADT/SmallPtrSet.h index c7f5e5bfc0f..b52aebf7d55 100644 --- a/include/llvm/ADT/SmallPtrSet.h +++ b/include/llvm/ADT/SmallPtrSet.h @@ -293,14 +293,16 @@ public: SmallPtrSet & operator=(const SmallPtrSet &RHS) { - CopyFrom(RHS); + if (&RHS != this) + CopyFrom(RHS); return *this; } #if LLVM_HAS_RVALUE_REFERENCES SmallPtrSet& operator=(SmallPtrSet &&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 fa8d91545e7..f873d91d6e0 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);