diff --git a/compiler-rt/lib/scudo/standalone/vector.h b/compiler-rt/lib/scudo/standalone/vector.h --- a/compiler-rt/lib/scudo/standalone/vector.h +++ b/compiler-rt/lib/scudo/standalone/vector.h @@ -19,13 +19,14 @@ // small vectors. The current implementation supports only POD types. template class VectorNoCtor { public: - void init(uptr InitialCapacity = 0) { - Data = reinterpret_cast(&LocalData[0]); + constexpr void init(uptr InitialCapacity = 0) { + Data = &LocalData[0]; CapacityBytes = sizeof(LocalData); - reserve(InitialCapacity); + if (InitialCapacity > capacity()) + reserve(InitialCapacity); } void destroy() { - if (Data != reinterpret_cast(&LocalData[0])) + if (Data != &LocalData[0]) unmap(Data, CapacityBytes); } T &operator[](uptr I) { @@ -55,7 +56,7 @@ uptr size() const { return Size; } const T *data() const { return Data; } T *data() { return Data; } - uptr capacity() const { return CapacityBytes / sizeof(T); } + constexpr uptr capacity() const { return CapacityBytes / sizeof(T); } void reserve(uptr NewSize) { // Never downsize internal buffer. if (NewSize > capacity()) @@ -91,14 +92,14 @@ } T *Data = nullptr; - u8 LocalData[256] = {}; + T LocalData[256 / sizeof(T)] = {}; uptr CapacityBytes = 0; uptr Size = 0; }; template class Vector : public VectorNoCtor { public: - Vector() { VectorNoCtor::init(); } + constexpr Vector() { VectorNoCtor::init(); } explicit Vector(uptr Count) { VectorNoCtor::init(Count); this->resize(Count);