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]

Re: [PATCH] Fix PR c/5354


On Thu, Feb 14, 2002 at 09:28:50PM +0100, Eric Botcazou wrote:
>  PR c/5354:
>  *c-common.c (c_expand_expr): preserve result
>  of a statement expression if needed

I'm committing a slight variant of this.  When possible, I force
the value into a register so that we do not keep the stack slot
live across the entire function.  I expanded the test case to
check for both situations.


r~



Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.294.2.1
diff -c -p -d -r1.294.2.1 c-common.c
*** c-common.c	2002/03/16 01:07:51	1.294.2.1
--- c-common.c	2002/03/21 02:00:14
*************** c_expand_expr (exp, target, tmode, modif
*** 3566,3571 ****
--- 3566,3572 ----
        {
  	tree rtl_expr;
  	rtx result;
+ 	bool preserve_result = false;
  
  	/* Since expand_expr_stmt calls free_temp_slots after every
  	   expression statement, we must call push_temp_slots here.
*************** c_expand_expr (exp, target, tmode, modif
*** 3592,3603 ****
  
  	    if (TREE_CODE (last) == SCOPE_STMT
  		&& TREE_CODE (expr) == EXPR_STMT)
! 	      TREE_ADDRESSABLE (expr) = 1;
  	  }
  
  	expand_stmt (STMT_EXPR_STMT (exp));
  	expand_end_stmt_expr (rtl_expr);
  	result = expand_expr (rtl_expr, target, tmode, modifier);
  	pop_temp_slots ();
  	return result;
        }
--- 3593,3616 ----
  
  	    if (TREE_CODE (last) == SCOPE_STMT
  		&& TREE_CODE (expr) == EXPR_STMT)
! 	      {
! 	        TREE_ADDRESSABLE (expr) = 1;
! 		preserve_result = true;
! 	      }
  	  }
  
  	expand_stmt (STMT_EXPR_STMT (exp));
  	expand_end_stmt_expr (rtl_expr);
+ 
  	result = expand_expr (rtl_expr, target, tmode, modifier);
+ 	if (preserve_result && GET_CODE (result) == MEM)
+ 	  {
+ 	    if (GET_MODE (result) != BLKmode)
+ 	      result = copy_to_reg (result);
+ 	    else
+ 	      preserve_temp_slots (result);
+ 	  }
+ 
  	pop_temp_slots ();
  	return result;
        }
Index: testsuite/gcc.c-torture/execute/20020320-1.c
===================================================================
RCS file: 20020320-1.c
diff -N 20020320-1.c
*** /dev/null	Tue May  5 13:32:27 1998
--- 20020320-1.c	Wed Mar 20 18:02:24 2002
***************
*** 0 ****
--- 1,23 ----
+ /* PR c/5354 */
+ /* Verify that GCC preserves relevant stack slots.  */
+ 
+ extern void abort(void);
+ extern void exit(int);
+ 
+ struct large { int x, y[9]; };
+ 
+ int main()
+ {
+   int fixed;
+ 
+   fixed = ({ int temp1 = 2; temp1; }) - ({ int temp2 = 1; temp2; });
+   if (fixed != 1)
+     abort();
+ 
+   fixed = ({ struct large temp3; temp3.x = 2; temp3; }).x
+ 	  - ({ struct large temp4; temp4.x = 1; temp4; }).x;
+   if (fixed != 1)
+     abort();
+ 
+   exit(0);
+ }


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