diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h index 3be1787bc39..a76e9c77f16 100644 --- a/include/llvm/ADT/SmallVector.h +++ b/include/llvm/ADT/SmallVector.h @@ -712,25 +712,33 @@ public: /// members are required. template class SmallVector : public SmallVectorImpl { + // SmallVector doesn't like growing from zero capacity. As a + // temporary workaround, avoid changing the growth algorithm by + // forcing capacity to be at least 1 in the constructors. + public: SmallVector() : SmallVectorImpl(0) { + this->reserve(1); // workaround } explicit SmallVector(unsigned Size, const T &Value = T()) : SmallVectorImpl(0) { - this->reserve(Size); + this->reserve(Size ? Size : 1); // workaround while (Size--) this->push_back(Value); } template SmallVector(ItTy S, ItTy E) : SmallVectorImpl(0) { + if (S == E) this->reserve(1); // workaround this->append(S, E); } SmallVector(const SmallVector &RHS) : SmallVectorImpl(0) { if (!RHS.empty()) SmallVectorImpl::operator=(RHS); + else + this->reserve(1); // workaround } const SmallVector &operator=(const SmallVector &RHS) {