This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


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

Re: Arguments to constructor evaluated in wrong order.



Mark J. Roberts writes:

> I'm running a build of the 3.0 branch from a couple days
> ago. Methods don't have this problem, it's only constructors,
> afaict.

And you see the problem when the evaluation order of arguments
matters. I have a patch that doesn't trigger regression in all my
tests. I'm going to check this in the trunk and the 3.0 branch:

./A

2001-06-04  Alexandre Petit-Bianco  <apbianco@redhat.com>

	* expr.c (force_evaluation_order): Match wrapped ctor calls, locate
	arguments accordingly.

Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.102.2.6
diff -u -p -r1.102.2.6 expr.c
--- expr.c      2001/05/16 06:42:23     1.102.2.6
+++ expr.c      2001/06/04 23:04:29
@@ -3268,16 +3268,31 @@ force_evaluation_order (node)
       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)
+  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)) 
     {
       tree arg, cmp;
 
       if (!TREE_OPERAND (node, 1))
        return node;
 
+      arg = node;
+
+      /* Position arg properly, account for wrapped around ctors. */
+      if (TREE_CODE (node) == COMPOUND_EXPR)
+       arg = TREE_OPERAND (node, 0);
+
+      arg = TREE_OPERAND (arg, 1);
+
+      /* Not having a list of argument here is an error. */ 
+      if (TREE_CODE (arg) != TREE_LIST)
+       abort ();
+
       /* This reverses the evaluation order. This is a desired effect. */
-      for (cmp = NULL_TREE, arg = TREE_OPERAND (node, 1); 
-          arg; arg = TREE_CHAIN (arg))
+      for (cmp = NULL_TREE; arg; arg = TREE_CHAIN (arg))
        {
          tree saved = save_expr (force_evaluation_order (TREE_VALUE (arg)));
          cmp = (cmp == NULL_TREE ? saved :


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