OSDN Git Service

* toplev.c (flag_evaluation_order): New global variable.
authorsayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 28 Sep 2003 04:56:35 +0000 (04:56 +0000)
committersayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 28 Sep 2003 04:56:35 +0000 (04:56 +0000)
* flags.h (flag_evaluation_order): Prototype here.
* expr.c (expand_operands): If we need to preserve observable
evaluation order, protect exp1 from clobbering exp0's result.

* java/lang.c (java_init_options): Set flag_evaluation_order.
* java/expr.c (force_evaluation_order): Don't attempt to force
evaluation order of binary operations using save_expr.
* java/parse.y (java_complete_lhs): No longer need to call
force_evaluation_order when constructing binary operators.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@71873 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/expr.c
gcc/flags.h
gcc/java/ChangeLog
gcc/java/expr.c
gcc/java/lang.c
gcc/java/parse.y
gcc/toplev.c

index 4b1a9bf..dccdbda 100644 (file)
@@ -1,3 +1,10 @@
+2003-09-27  Roger Sayle  <roger@eyesopen.com>
+
+       * toplev.c (flag_evaluation_order): New global variable.
+       * flags.h (flag_evaluation_order): Prototype here.
+       * expr.c (expand_operands): If we need to preserve observable
+       evaluation order, protect exp1 from clobbering exp0's result.
+
 2003-09-28  Andreas Jaeger  <aj@suse.de>
 
        * c-decl.c (finish_function): Convert definition to ISO C90.
index 6ad93c5..26eaab0 100644 (file)
@@ -6553,6 +6553,10 @@ expand_operands (tree exp0, tree exp1, rtx target, rtx *op0, rtx *op1,
     }
   else
     {
+      /* If we need to preserve evaluation order, copy exp0 into its own
+        temporary variable so that it can't be clobbered by exp1.  */
+      if (flag_evaluation_order && TREE_SIDE_EFFECTS (exp1))
+       exp0 = save_expr (exp0);
       *op0 = expand_expr (exp0, target, VOIDmode, modifier);
       *op1 = expand_expr (exp1, NULL_RTX, VOIDmode, modifier);
     }
index 823aaef..4d6ea07 100644 (file)
@@ -604,6 +604,9 @@ extern int flag_trapv;
 /* Nonzero if the signed arithmetic overflow should wrap around.  */
 extern int flag_wrapv;
 
+/* Nonzero if subexpressions must be evaluated from left-to-right.  */
+extern int flag_evaluation_order;
+
 /* Value of the -G xx switch, and whether it was passed or not.  */
 extern unsigned HOST_WIDE_INT g_switch_value;
 extern bool g_switch_set;
index a79d73a..514c097 100644 (file)
@@ -1,3 +1,11 @@
+2003-09-27  Roger Sayle  <roger@eyesopen.com>
+
+       * lang.c (java_init_options): Set flag_evaluation_order.
+       * expr.c (force_evaluation_order): Don't attempt to force
+       evaluation order of binary operations using save_expr.
+       * parse.y (java_complete_lhs): No longer need to call
+       force_evaluation_order when constructing binary operators.
+
 2003-09-27  Alexandre Petit-Bianco  <apbianco@redhat.com>
            Bryce McKinlay  <bryce@mckinlay.net.nz>
 
index 803c2de..272cb35 100644 (file)
@@ -3324,16 +3324,11 @@ force_evaluation_order (tree node)
 {
   if (flag_syntax_only)
     return node;
-  if (TREE_CODE_CLASS (TREE_CODE (node)) == '2')
-    {
-      if (TREE_SIDE_EFFECTS (TREE_OPERAND (node, 1)))
-       TREE_OPERAND (node, 0) = save_expr (TREE_OPERAND (node, 0));
-    }
-  else if (TREE_CODE (node) == CALL_EXPR
-           || TREE_CODE (node) == NEW_CLASS_EXPR
-           || (TREE_CODE (node) == COMPOUND_EXPR
-               && TREE_CODE (TREE_OPERAND (node, 0)) == CALL_EXPR
-               && TREE_CODE (TREE_OPERAND (node, 1)) == SAVE_EXPR)) 
+  if (TREE_CODE (node) == CALL_EXPR
+      || TREE_CODE (node) == NEW_CLASS_EXPR
+      || (TREE_CODE (node) == COMPOUND_EXPR
+         && TREE_CODE (TREE_OPERAND (node, 0)) == CALL_EXPR
+         && TREE_CODE (TREE_OPERAND (node, 1)) == SAVE_EXPR)) 
     {
       tree arg, cmp;
 
index 5ade4c0..a3ed327 100644 (file)
@@ -685,6 +685,9 @@ java_init_options (unsigned int argc ATTRIBUTE_UNUSED,
   /* In Java arithmetic overflow always wraps around.  */
   flag_wrapv = 1;
 
+  /* Java requires left-to-right evaluation of subexpressions.  */
+  flag_evaluation_order = 1;
+
   jcf_path_init ();
 
   return CL_Java;
index e409719..ebcf680 100644 (file)
@@ -12265,7 +12265,7 @@ java_complete_lhs (tree node)
 
           TREE_OPERAND (node, 1) = nn;
         }
-      return force_evaluation_order (patch_binop (node, wfl_op1, wfl_op2));
+      return patch_binop (node, wfl_op1, wfl_op2);
 
     case INSTANCEOF_EXPR:
       wfl_op1 = TREE_OPERAND (node, 0);
index 03485bc..425a025 100644 (file)
@@ -988,6 +988,9 @@ int flag_trapv = 0;
 /* Nonzero if signed arithmetic overflow should wrap around.  */
 int flag_wrapv = 0;
 
+/* Nonzero if subexpressions must be evaluated from left-to-right.  */
+int flag_evaluation_order = 0;
+
 /* Add or remove a leading underscore from user symbols.  */
 int flag_leading_underscore = -1;