]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
forwprop: Add missing NULL check on vdef in optimize_aggr_zeroprop [PR124742]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Wed, 1 Apr 2026 02:56:00 +0000 (19:56 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Wed, 1 Apr 2026 11:11:17 +0000 (04:11 -0700)
When I converted optimize_aggr_zeroprop into a forward walk instead of
a backward walk, I missed that the vdef of a memset call could be NULL.
This only happens when there is "undefined" declaration of memset exists.
Anyways this fixes the ICE by adding the NULL check and an early out.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/124742

gcc/ChangeLog:

* tree-ssa-forwprop.cc (optimize_aggr_zeroprop): Exit
if the vdef on the stmt is NULL.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr124742-1.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/testsuite/gcc.dg/torture/pr124742-1.c [new file with mode: 0644]
gcc/tree-ssa-forwprop.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr124742-1.c b/gcc/testsuite/gcc.dg/torture/pr124742-1.c
new file mode 100644 (file)
index 0000000..41cbef6
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* PR tree-optimization/124742 */
+
+typedef __SIZE_TYPE__ size_t;
+struct S {
+    int v[4];
+} s;
+
+void *memset(void *p, int c, size_t n)
+{
+    return memset(p, c, n);
+}
+
+int main()
+{
+    memset(s.v, 0, sizeof(s.v));
+    return s.v[0];
+}
index b5544414ca6eb463d9a23735fa77364ecdfbc1dd..f060275d72d983381fe4e470f0fd917860b2707f 100644 (file)
@@ -1366,6 +1366,10 @@ optimize_aggr_zeroprop (gimple *stmt, bool full_walk)
       || !poly_int_tree_p (len))
     return;
 
+  /* Sometimes memset can have no vdef due to invalid declaration of memset (const, etc.).  */
+  if (!gimple_vdef (stmt))
+    return;
+
   /* This store needs to be on the byte boundary and pointing to an object.  */
   poly_int64 offset;
   tree dest_base = get_addr_base_and_unit_offset (dest, &offset);