diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h index fdecb6c4481..a1373e2de75 100644 --- a/include/llvm/ADT/SmallVector.h +++ b/include/llvm/ADT/SmallVector.h @@ -19,6 +19,7 @@ #include #include #include +#include #ifdef _MSC_VER namespace std { @@ -116,10 +117,14 @@ public: const_reverse_iterator rend() const { return const_reverse_iterator(begin());} + /* These asserts could be "Begin + idx < End", but there are lots of places + in llvm where we use &v[v.size()] instead of v.end(). */ reference operator[](unsigned idx) { + assert (Begin + idx <= End); return Begin[idx]; } const_reference operator[](unsigned idx) const { + assert (Begin + idx <= End); return Begin[idx]; }