]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add assert to array_slice::begin/end
authorAndrew Pinski <quic_apinski@quicinc.com>
Thu, 9 Jan 2025 20:53:27 +0000 (12:53 -0800)
committerAndrew Pinski <quic_apinski@quicinc.com>
Mon, 21 Apr 2025 15:23:07 +0000 (08:23 -0700)
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_apinski@quicinc.com>
gcc/vec.h

index 915df06f03e99c131d37b94538e4d84b99309fad..eae4b0feb4bc483987cd0c92a5059ae25def2056 100644 (file)
--- 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 ();