[PATCH] Fix PR27236

Richard Guenther rguenther@suse.de
Sun Apr 23 11:21:00 GMT 2006


Bootstrapped and tested on x86_64-unknonw-linux-gnu.

Ok for mainline/4.1?

Thanks,
Richard.

:ADDPATCH middle-end:

2006-04-23  Andrew Pinski  <pinskia@gcc.gnu.org>
	Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/27236
	* tree-inline.c (copy_body_r): Make sure to copy
	TREE_THIS_VOLATILE flag.

	* gcc.dg/tree-ssa/pr27236.c: New testcase.

Index: tree-inline.c
===================================================================
*** tree-inline.c	(revision 113168)
--- tree-inline.c	(working copy)
*************** copy_body_r (tree *tp, int *walk_subtree
*** 590,595 ****
--- 590,596 ----
  	  if (n)
  	    {
  	      tree new;
+ 	      tree old;
  	      /* If we happen to get an ADDR_EXPR in n->value, strip
  	         it manually here as we'll eventually get ADDR_EXPRs
  		 which lie about their types pointed to.  In this case
*************** copy_body_r (tree *tp, int *walk_subtree
*** 598,610 ****
  	         does other useful transformations, try that first, though.  */
  	      tree type = TREE_TYPE (TREE_TYPE ((tree)n->value));
  	      new = unshare_expr ((tree)n->value);
  	      *tp = fold_indirect_ref_1 (type, new);
  	      if (! *tp)
  	        {
  		  if (TREE_CODE (new) == ADDR_EXPR)
  		    *tp = TREE_OPERAND (new, 0);
  	          else
! 	            *tp = build1 (INDIRECT_REF, type, new);
  		}
  	      *walk_subtrees = 0;
  	      return NULL;
--- 599,615 ----
  	         does other useful transformations, try that first, though.  */
  	      tree type = TREE_TYPE (TREE_TYPE ((tree)n->value));
  	      new = unshare_expr ((tree)n->value);
+ 	      old = *tp;
  	      *tp = fold_indirect_ref_1 (type, new);
  	      if (! *tp)
  	        {
  		  if (TREE_CODE (new) == ADDR_EXPR)
  		    *tp = TREE_OPERAND (new, 0);
  	          else
! 		    {
! 	              *tp = build1 (INDIRECT_REF, type, new);
! 		      TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old);
! 		    }
  		}
  	      *walk_subtrees = 0;
  	      return NULL;

/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-optimized" } */

static inline int inline_read(volatile int *mem)
{
        return *mem;
}
int foo_read(volatile int *mem)
{
        return inline_read(mem);
}
unsigned int foo(volatile int *mem)
{
        foo_read(mem);
        return foo_read(mem);
}

/* { dg-final { scan-tree-dump-times "foo_read" 2 "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */



More information about the Gcc-patches mailing list