https://gcc.gnu.org/g:d508d24282c6a8172be2abcb2223232f452b667f
commit r16-48-gd508d24282c6a8172be2abcb2223232f452b667f Author: Andrew Pinski <quic_apin...@quicinc.com> Date: Thu Jan 9 12:53:27 2025 -0800 Add assert to array_slice::begin/end So while debugging PR 118320, I found it was useful to have an assert inside array_slice::begin/end that the array slice isvalid rather than getting an segfault. This adds an assert that is only enabled for checking. OK? Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * vec.h (array_slice::begin): Assert that the slice is valid. (array_slice::end): Likewise. Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com> Diff: --- gcc/vec.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gcc/vec.h b/gcc/vec.h index 915df06f03e9..eae4b0feb4bc 100644 --- a/gcc/vec.h +++ b/gcc/vec.h @@ -2395,11 +2395,11 @@ public: array_slice (vec<OtherT, A, vl_embed> *v) : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} - iterator begin () { return m_base; } - iterator end () { return m_base + m_size; } + iterator begin () { gcc_checking_assert (is_valid ()); return m_base; } + iterator end () { gcc_checking_assert (is_valid ()); return m_base + m_size; } - const_iterator begin () const { return m_base; } - const_iterator end () const { return m_base + m_size; } + const_iterator begin () const { gcc_checking_assert (is_valid ()); return m_base; } + const_iterator end () const { gcc_checking_assert (is_valid ()); return m_base + m_size; } value_type &front (); value_type &back ();