diff mbox

Fix optimized out volatile MEM_REF (PR, tree-optimization/78810)

Message ID 69d5f3d0-9708-9b34-53a0-4e5853c6baa2@suse.cz
State New
Headers show

Commit Message

Martin Liška Dec. 15, 2016, 10:56 a.m. UTC
The patch adds TREE_THIS_VOLATILE check that was removed in r239778.
Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

Ready to be installed?
Martin

Comments

Richard Biener Dec. 16, 2016, 9:37 a.m. UTC | #1
On Thu, Dec 15, 2016 at 11:56 AM, Martin Liška <mliska@suse.cz> wrote:
> The patch adds TREE_THIS_VOLATILE check that was removed in r239778.

> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

>

> Ready to be installed?


I see nothing wrong with a volatile access to a non-volatile
auto-var/param being
removed.

So what's the actual issue here?  The bug says "can't compile" but I see no
error, warning or ICE.

Richard.

> Martin
diff mbox

Patch

From dc8ec6815fa51b352fe5f1a02d3510022053e0ad Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Wed, 14 Dec 2016 16:07:56 +0100
Subject: [PATCH] Fix optimized out volatile MEM_REF (PR
 tree-optimization/78810)

gcc/testsuite/ChangeLog:

2016-12-14  Martin Liska  <mliska@suse.cz>

	PR tree-optimization/78810
	* g++.dg/tree-ssa/pr78810.C: New test.

gcc/ChangeLog:

2016-12-14  Martin Liska  <mliska@suse.cz>

	PR tree-optimization/78810
	* tree-ssa.c (non_rewritable_mem_ref_base): Add TREE_THIS_VOLATILE
	check removed in r239778.
---
 gcc/testsuite/g++.dg/tree-ssa/pr78810.C | 26 ++++++++++++++++++++++++++
 gcc/tree-ssa.c                          |  3 ++-
 2 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/tree-ssa/pr78810.C

diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr78810.C b/gcc/testsuite/g++.dg/tree-ssa/pr78810.C
new file mode 100644
index 00000000000..1cda30c5bd8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tree-ssa/pr78810.C
@@ -0,0 +1,26 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+class NODE;
+typedef unsigned long VALUE;
+
+struct parser_params
+{
+};
+
+struct parser_params *get_parser();
+NODE *yycompile(parser_params *parser, VALUE a, VALUE b);
+
+NODE*
+rb_parser_compile_file_path(VALUE vparser, VALUE fname, VALUE file, int start)
+{
+    struct parser_params *parser;
+    parser = get_parser(); 
+
+    NODE *node = yycompile(parser, fname, start);
+    (*({volatile VALUE *rb_gc_guarded_ptr = (&(vparser)); rb_gc_guarded_ptr;}));
+
+    return node;
+}
+
+/* { dg-final { scan-tree-dump "MEM\\\[\\\(volatile\\\ VALUE\\\ \\\*\\\)" "optimized" } } */
diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c
index 62eea8bb8a4..b92513fcf23 100644
--- a/gcc/tree-ssa.c
+++ b/gcc/tree-ssa.c
@@ -1385,7 +1385,8 @@  non_rewritable_mem_ref_base (tree ref)
       if (! DECL_P (decl))
 	return NULL_TREE;
       if (! is_gimple_reg_type (TREE_TYPE (base))
-	  || VOID_TYPE_P (TREE_TYPE (base)))
+	  || VOID_TYPE_P (TREE_TYPE (base))
+	  || TREE_THIS_VOLATILE (decl) != TREE_THIS_VOLATILE (base))
 	return decl;
       if ((TREE_CODE (TREE_TYPE (decl)) == VECTOR_TYPE
 	   || TREE_CODE (TREE_TYPE (decl)) == COMPLEX_TYPE)
-- 
2.11.0