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]

[tree-ssa] More prep work for CFG EH cleanups


As has already been discussed, if the RHS of a MODIFY_EXPR might throw,
then the LHS really needs to be a temporary variable.  Otherwise it is,
err, difficult for the optimizers to know if the user variable is
modified or not.

It was an earlier version of this patch which exposed the edge splitting
bug I just fixed in tree-cfg.c earlier tonight.


	* gimplify.c (gimplify_modify_expr): If the RHS of an MODIFY_EXPR
	might throw, then make sure its result goes into a temporary.

Index: gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/gimplify.c,v
retrieving revision 1.1.2.57
diff -c -3 -p -r1.1.2.57 gimplify.c
*** gimplify.c	13 Jun 2003 19:00:17 -0000	1.1.2.57
--- gimplify.c	20 Jun 2003 05:54:02 -0000
*************** gimplify_modify_expr (expr_p, pre_p, pos
*** 1840,1845 ****
--- 1840,1864 ----
  
    gimplify_expr (from_p, pre_p, post_p, is_gimple_rhs, fb_rvalue);
  
+   /* If the RHS of the MODIFY_EXPR may throw and the LHS is a user
+      variable, then we need to introduce a temporary.
+      ie temp = RHS; LHS = temp.
+ 
+      This way the optimizers can determine that the user variable is
+      only modified if evaluation of the RHS does not throw.
+ 
+      FIXME.  What to do about cases where the LHS can throw?  */
+   if (flag_exceptions
+       && ! (DECL_P (*to_p) && DECL_ARTIFICIAL (*to_p))
+       && ((TREE_CODE (*from_p) == CALL_EXPR
+ 	   && ! (call_expr_flags (*from_p) & ECF_NOTHROW))
+ 	  || (flag_non_call_exceptions && could_trap_p (*from_p))))
+     {
+       tree tmp = get_initialized_tmp_var (*from_p, pre_p);
+       *expr_p = build (MODIFY_EXPR, TREE_TYPE (TREE_OPERAND (*expr_p, 0)),
+ 		       TREE_OPERAND (*expr_p, 0), tmp);
+     }
+ 
    if (want_value)
      {
        add_tree (*expr_p, pre_p);
 



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