On 28/07/2025 16:36, Sam James wrote:
Alfie Richards <alfie.richa...@arm.com> writes:

Hi,

Small fix to resolve an UBSAN diagnostic.

Reg tested for Aarch64


To be sure: checked with bootstrap-ubsan too? (though note that it
doesn't error out by default, so you'd need to grep the logs or set
UBSAN_OPTIONS to make it error out)
Ah thank you, I was struggling to recreate the error but just wasn't looking in the right place. Confirmed that the fix does fix it. >
Thanks,
Alfie

-- >8 --

This adds a nullptr check to fix a regression where it is possible to call
`memcmp (NULL, NULL, 0)` which is UB.

This should fix the bootstrap-ubsan build.

I can't approve but LGTM.


gcc/ChangeLog:
         PR middle-end/121261
        * vec.h: Add null ptr check.
---
  gcc/vec.h | 4 ++++
  1 file changed, 4 insertions(+)

diff --git a/gcc/vec.h b/gcc/vec.h
index 9604edb1c3c..1277a881f1c 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -2514,6 +2514,10 @@ public:
        return false;
      if (lhs.size () != rhs.size ())
        return false;
+    /* Case where either is a NULL pointer and therefore, as both are valid,
+       both are empty slices with length 0.  */
+    if (lhs.begin () == NULL || rhs.begin () == NULL)
+      return true;
      return memcmp (lhs.begin (), rhs.begin (), lhs.size ()) == 0;
    }

Reply via email to