From: Andrew Pinski Date: Thu, 9 Jan 2025 20:53:27 +0000 (-0800) Subject: Add assert to array_slice::begin/end X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d508d24282c6a8172be2abcb2223232f452b667f;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/vec.h b/gcc/vec.h index 915df06f03e..eae4b0feb4b 100644 --- a/gcc/vec.h +++ b/gcc/vec.h @@ -2395,11 +2395,11 @@ public: array_slice (vec *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 ();