The following fixes a stack corruption and a missed optimization.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Richard.

2019-07-24  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/91236
        * tree-ssa-sccvn.c (vn_walk_cb_data::push_partial_def): Fix
        size of CONSTRUCTOR write.  Fix buffer size we pass to
        native_encode_expr.

Index: gcc/tree-ssa-sccvn.c
===================================================================
--- gcc/tree-ssa-sccvn.c        (revision 273758)
+++ gcc/tree-ssa-sccvn.c        (working copy)
@@ -1818,7 +1870,7 @@ vn_walk_cb_data::push_partial_def (const
       if (TREE_CODE (pd.rhs) == CONSTRUCTOR)
        /* Empty CONSTRUCTOR.  */
        memset (buffer + MAX (0, pd.offset),
-               0, MIN ((HOST_WIDE_INT)sizeof (buffer),
+               0, MIN ((HOST_WIDE_INT)sizeof (buffer) - MAX (0, pd.offset),
                        pd.size + MIN (0, pd.offset)));
       else
        {
@@ -1833,7 +1885,7 @@ vn_walk_cb_data::push_partial_def (const
              pad = GET_MODE_SIZE (mode) - pd.size;
            }
          len = native_encode_expr (pd.rhs, buffer + MAX (0, pd.offset),
-                                   sizeof (buffer - MAX (0, pd.offset)),
+                                   sizeof (buffer) - MAX (0, pd.offset),
                                    MAX (0, -pd.offset) + pad);
          if (len <= 0 || len < (pd.size - MAX (0, -pd.offset)))
            {

Reply via email to