On Sat, Apr 19, 2025 at 5:04 PM Andrew Pinski <quic_apin...@quicinc.com> wrote:
>
> 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.

OK

> 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>
> ---
>  gcc/vec.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> 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<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 ();
> --
> 2.43.0
>

Reply via email to