Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard.
2011-09-26 Richard Guenther <rguent...@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. 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" } } */