This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR45704


This fixes PR45704 - we need to preserve volatileness when
doing indirect-ref folding from gimplification.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk,
4.5 variant in testing.

Richard.

2010-09-20  Richard Guenther  <rguenther@suse.de>

	PR middle-end/45704
	* gimplify.c (gimplify_modify_expr_rhs): Preserve volatileness.

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

Index: gcc/gimplify.c
===================================================================
*** gcc/gimplify.c	(revision 164433)
--- gcc/gimplify.c	(working copy)
*************** gimplify_modify_expr_rhs (tree *expr_p,
*** 4197,4205 ****
--- 4197,4214 ----
  	     This kind of code arises in C++ when an object is bound
  	     to a const reference, and if "x" is a TARGET_EXPR we want
  	     to take advantage of the optimization below.  */
+ 	    bool volatile_p = TREE_THIS_VOLATILE (*from_p);
  	    tree t = gimple_fold_indirect_ref_rhs (TREE_OPERAND (*from_p, 0));
  	    if (t)
  	      {
+ 		if (TREE_THIS_VOLATILE (t) != volatile_p)
+ 		  {
+ 		    if (TREE_CODE_CLASS (TREE_CODE (t)) == tcc_declaration)
+ 		      t = build_simple_mem_ref_loc (EXPR_LOCATION (*from_p),
+ 						    build_fold_addr_expr (t));
+ 		    if (REFERENCE_CLASS_P (t))
+ 		      TREE_THIS_VOLATILE (t) = volatile_p;
+ 		  }
  		*from_p = t;
  		ret = GS_OK;
  		changed = true;
Index: gcc/testsuite/gcc.dg/torture/pr45704.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr45704.c	(revision 0)
--- gcc/testsuite/gcc.dg/torture/pr45704.c	(revision 0)
***************
*** 0 ****
--- 1,15 ----
+ /* { dg-do compile } */
+ /* { dg-options "-fdump-tree-optimized" } */
+ 
+ struct st {
+     int ptr;
+ };
+ 
+ int foo(struct st *st)
+ {
+   int v = *(volatile int *)&st->ptr;
+   return v & 0xff;
+ }
+ 
+ /* { dg-final { scan-tree-dump-times "={v}" 1 "optimized" } } */
+ /* { dg-final { cleanup-tree-dump "optimized" } } */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]