diff mbox series

Fix PR82129

Message ID alpine.LSU.2.20.1709121603340.26836@zhemvz.fhfr.qr
State New
Headers show
Series Fix PR82129 | expand

Commit Message

Richard Biener Sept. 12, 2017, 2:09 p.m. UTC
The following "fixes" PR82129 (hides the issue).  It folds
writes from uninitialized data to CLOBBERs:

-  *h5_26(D) = tv_24(D);
+  *h5_26(D) ={v} {CLOBBER};

Bootstrap & regtest running on x86_64-unknown-linux-gnu.

Richard.

2017-09-12  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/82129
	* gimple-fold.c (fold_gimple_assign): Fold stores from undefined
	values to clobbers.

	* gcc.dg/torture/pr82129.c: New testcase.

Comments

Jakub Jelinek Sept. 12, 2017, 2:16 p.m. UTC | #1
On Tue, Sep 12, 2017 at 04:09:41PM +0200, Richard Biener wrote:
> 
> The following "fixes" PR82129 (hides the issue).  It folds
> writes from uninitialized data to CLOBBERs:
> 
> -  *h5_26(D) = tv_24(D);
> +  *h5_26(D) ={v} {CLOBBER};
> 
> Bootstrap & regtest running on x86_64-unknown-linux-gnu.

Won't that affect -W{,maybe-}unitialized a lot?

> 2017-09-12  Richard Biener  <rguenther@suse.de>
> 
> 	PR tree-optimization/82129
> 	* gimple-fold.c (fold_gimple_assign): Fold stores from undefined
> 	values to clobbers.
> 
> 	* gcc.dg/torture/pr82129.c: New testcase.

	Jakub
Richard Biener Sept. 12, 2017, 2:46 p.m. UTC | #2
On Tue, 12 Sep 2017, Jakub Jelinek wrote:

> On Tue, Sep 12, 2017 at 04:09:41PM +0200, Richard Biener wrote:
> > 
> > The following "fixes" PR82129 (hides the issue).  It folds
> > writes from uninitialized data to CLOBBERs:
> > 
> > -  *h5_26(D) = tv_24(D);
> > +  *h5_26(D) ={v} {CLOBBER};
> > 
> > Bootstrap & regtest running on x86_64-unknown-linux-gnu.
> 
> Won't that affect -W{,maybe-}unitialized a lot?

Not sure - as current it fails bootstrap because I need to guard
against not folding things like foo.bar = x_2(D) (we assert to
have clobbers only on full objects).

Richard.

> > 2017-09-12  Richard Biener  <rguenther@suse.de>
> > 
> > 	PR tree-optimization/82129
> > 	* gimple-fold.c (fold_gimple_assign): Fold stores from undefined
> > 	values to clobbers.
> > 
> > 	* gcc.dg/torture/pr82129.c: New testcase.
diff mbox series

Patch

Index: gcc/gimple-fold.c
===================================================================
--- gcc/gimple-fold.c	(revision 252002)
+++ gcc/gimple-fold.c	(working copy)
@@ -410,6 +410,20 @@  fold_gimple_assign (gimple_stmt_iterator
 
 	else if (DECL_P (rhs))
 	  return get_symbol_constant_value (rhs);
+
+	else if (TREE_CODE (rhs) == SSA_NAME
+		 && SSA_NAME_IS_DEFAULT_DEF (rhs)
+		 && ! ssa_defined_default_def_p (rhs)
+		 && gimple_store_p (stmt)
+		 && ! gimple_has_volatile_ops (stmt))
+	  {
+	    /* Replace a store from an undefined value with a clobber
+	       which will not generate code, thus avoid doing this when
+	       the store is volatile.  */
+	    tree clobber = build_constructor (TREE_TYPE (rhs), NULL);
+	    TREE_THIS_VOLATILE (clobber) = true;
+	    return clobber;
+	  }
       }
       break;
 
Index: gcc/testsuite/gcc.dg/torture/pr82129.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr82129.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/torture/pr82129.c	(working copy)
@@ -0,0 +1,51 @@ 
+/* { dg-do compile } */
+
+int pj;
+
+void
+g4 (unsigned long int *bc, unsigned long int *h5)
+{
+  if (pj != 0)
+    {
+      int ib = 0;
+
+      while (bc != 0)
+	{
+m6:
+	  for (pj = 0; pj < 2; ++pj)
+	    pj = 0;
+
+	  while (pj != 0)
+	    {
+	      for (;;)
+		{
+		}
+
+	      while (ib != 0)
+		{
+		  unsigned long int tv = *bc;
+		  unsigned long int n7;
+
+		  *bc = 1;
+		  while (*bc != 0)
+		    {
+		    }
+
+ut:
+		  if (pj == 0)
+		    n7 = *h5 > 0;
+		  else
+		    {
+		      *h5 = tv;
+		      n7 = *h5;
+		    }
+		  ib += n7;
+		}
+	    }
+	}
+
+      goto ut;
+    }
+
+  goto m6;
+}