Patchwork Fix PR50472

login
register
mail settings
Submitter Richard Guenther
Date Sept. 26, 2011, 12:54 p.m.
Message ID <alpine.LNX.2.00.1109261454250.2130@zhemvz.fhfr.qr>
Download mbox | patch
Permalink /patch/116418/
State New
Headers show

Comments

Richard Guenther - Sept. 26, 2011, 12:54 p.m.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2011-09-26  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/50472
	* gimple-fold.c (fold_const_aggregate_ref_1): Do not fold
	volatile references.

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

Patch

Index: gcc/gimple-fold.c
===================================================================
--- gcc/gimple-fold.c	(revision 179185)
+++ gcc/gimple-fold.c	(working copy)
@@ -2919,6 +2919,9 @@  fold_const_aggregate_ref_1 (tree t, tree
   HOST_WIDE_INT offset, size, max_size;
   tree tem;
 
+  if (TREE_THIS_VOLATILE (t))
+    return NULL_TREE;
+
   if (TREE_CODE_CLASS (TREE_CODE (t)) == tcc_declaration)
     return get_symbol_constant_value (t);
 
Index: gcc/testsuite/gcc.dg/torture/pr50472.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr50472.c	(revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr50472.c	(revision 0)
@@ -0,0 +1,12 @@ 
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-optimized" } */
+
+static const unsigned int foo = 1;
+unsigned int test( void )
+{
+  const volatile unsigned int *bar = &foo;
+  return ( *bar );
+}
+
+/* { dg-final { scan-tree-dump-not "return 1" "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */