diff mbox series

Fix PR84607

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

Commit Message

Richard Biener Feb. 28, 2018, 12:09 p.m. UTC
genmatch was fooled by singelton expression leafs so it omitted
the required TREE_SIDE_EFFECTS check and building a COMPOUND_EXPR
for the side-effects.

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

Richard.

2018-02-28  Richard Biener  <rguenther@suse.de>

	PR middle-end/84607
	* genmatch.c (capture_info::walk_match): Do not mark
	captured expressions without operands as expr_p given
	they act more like predicates and should be subject to
	"lost tail" side-effect preserving.

	* gcc.dg/pr84607.c: New testcase.
diff mbox series

Patch

Index: gcc/genmatch.c
===================================================================
--- gcc/genmatch.c	(revision 258056)
+++ gcc/genmatch.c	(working copy)
@@ -2104,7 +2104,11 @@  capture_info::walk_match (operand *o, un
       if (c->what
 	  && (e = dyn_cast <expr *> (c->what)))
 	{
-	  info[where].expr_p = true;
+	  /* Zero-operand expression captures like ADDR_EXPR@0 are
+	     similar as predicates -- if they are not mentioned in
+	     the result we have to force them to have no side-effects.  */
+	  if (e->ops.length () != 0)
+	    info[where].expr_p = true;
 	  info[where].force_single_use |= e->force_single_use;
 	}
     }
Index: gcc/testsuite/gcc.dg/pr84607.c
===================================================================
--- gcc/testsuite/gcc.dg/pr84607.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/pr84607.c	(working copy)
@@ -0,0 +1,16 @@ 
+/* { dg-do run } */
+
+extern void exit(int);
+extern void abort(void);
+int a[10];
+int foo()
+{
+  exit (0);
+  return 0;
+}
+int main()
+{
+  if (&a[foo()])
+    abort ();
+  return 0;
+}