diff mbox series

Fix folding of volatile values (PR 86617)

Message ID AM5PR0701MB26572C26849C6088D86E2A19E4560@AM5PR0701MB2657.eurprd07.prod.outlook.com
State New
Headers show
Series Fix folding of volatile values (PR 86617) | expand

Commit Message

Bernd Edlinger July 23, 2018, 11:29 a.m. UTC
Hi!

This fixes PR c/86617, where volatile values are folded
incorrectly, because LHS and RHS of PLUS_EXPR and
MINUS_EXPR are the same pointer.


Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
Is it OK for trunk (and active branches, 8.2 in particular)?


Thanks
Bernd.

Comments

Richard Biener July 23, 2018, 12:12 p.m. UTC | #1
On Mon, 23 Jul 2018, Bernd Edlinger wrote:

> Hi!
> 
> This fixes PR c/86617, where volatile values are folded
> incorrectly, because LHS and RHS of PLUS_EXPR and
> MINUS_EXPR are the same pointer.
> 
> 
> Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
> Is it OK for trunk (and active branches, 8.2 in particular)?

OK for trunk and for branches (for the 8 branch after the 8.2 release
given the issue is already old).

Thanks,
Richard.
diff mbox series

Patch

gcc:
2018-07-23  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	PR c/86617
	* genmatch.c (dt_operand::gen_match_op): Avoid folding volatile values.

testsuite:
2018-07-23  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	PR c/86617
	* gcc.dg/pr86617.c: New test.

Index: gcc/genmatch.c
===================================================================
--- gcc/genmatch.c	(revision 262904)
+++ gcc/genmatch.c	(working copy)
@@ -2748,12 +2748,14 @@  dt_operand::gen_match_op (FILE *f, int indent, con
   char match_opname[20];
   match_dop->get_name (match_opname);
   if (value_match)
-    fprintf_indent (f, indent, "if (%s == %s || operand_equal_p (%s, %s, 0))\n",
-		    opname, match_opname, opname, match_opname);
+    fprintf_indent (f, indent, "if ((%s == %s && ! TREE_SIDE_EFFECTS (%s)) "
+		    "|| operand_equal_p (%s, %s, 0))\n",
+		    opname, match_opname, opname, opname, match_opname);
   else
-    fprintf_indent (f, indent, "if (%s == %s || (operand_equal_p (%s, %s, 0) "
+    fprintf_indent (f, indent, "if ((%s == %s && ! TREE_SIDE_EFFECTS (%s)) "
+		    "|| (operand_equal_p (%s, %s, 0) "
 		    "&& types_match (%s, %s)))\n",
-		    opname, match_opname, opname, match_opname,
+		    opname, match_opname, opname, opname, match_opname,
 		    opname, match_opname);
   fprintf_indent (f, indent + 2, "{\n");
   return 1;
Index: gcc/testsuite/gcc.dg/pr86617.c
===================================================================
--- gcc/testsuite/gcc.dg/pr86617.c	(revision 0)
+++ gcc/testsuite/gcc.dg/pr86617.c	(working copy)
@@ -0,0 +1,11 @@ 
+/* { dg-options "-Os -fdump-rtl-final" } */
+
+volatile unsigned char u8;
+
+void test (void)
+{
+  u8 = u8 + u8;
+  u8 = u8 - u8;
+}
+
+/* { dg-final { scan-rtl-dump-times "mem/v" 6 "final" } } */