On Wed, Apr 1, 2026 at 8:57 AM Andrew Pinski <[email protected]> wrote: > > 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.
OK. > 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 <[email protected]> > --- > gcc/testsuite/gcc.dg/torture/pr124742-1.c | 18 ++++++++++++++++++ > gcc/tree-ssa-forwprop.cc | 4 ++++ > 2 files changed, 22 insertions(+) > create mode 100644 gcc/testsuite/gcc.dg/torture/pr124742-1.c > > diff --git a/gcc/testsuite/gcc.dg/torture/pr124742-1.c > b/gcc/testsuite/gcc.dg/torture/pr124742-1.c > new file mode 100644 > index 00000000000..41cbef64378 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/torture/pr124742-1.c > @@ -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]; > +} > diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc > index b5544414ca6..f060275d72d 100644 > --- a/gcc/tree-ssa-forwprop.cc > +++ b/gcc/tree-ssa-forwprop.cc > @@ -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); > -- > 2.43.0 >
