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
new file mode 100644
@@ -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" } } */
@@ -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