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>
--- /dev/null
+/* { 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];
+}
|| !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);