This is the mail archive of the java-patches@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]
Other format: [Raw text]

[gcjx] Patch: FYI: evaluation order and new[]


I'm checking this in on the gcjx branch.

This fixes evaluation order when creating a multi-dimensional array.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* tree.cc (visit_new_array): Fix evaluation order.

Index: tree.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/tree.cc,v
retrieving revision 1.1.2.64
diff -u -r1.1.2.64 tree.cc
--- tree.cc 11 Oct 2005 22:54:01 -0000 1.1.2.64
+++ tree.cc 11 Oct 2005 23:03:34 -0000
@@ -2277,18 +2277,9 @@
     }
   else if (indices.size () != 0)
     {
-      int num = 0;
-      tree args = NULL_TREE;
-      for (std::list<ref_expression>::const_iterator i = indices.begin ();
-	   i != indices.end ();
-	   ++i)
-	{
-	  (*i)->visit (this);
-	  args = tree_cons (NULL_TREE, current, args);
-	  ++num;
-	}
-      // We constructed the dimension arguments in reverse order.
-      args = nreverse (args);
+      int num = indices.size ();
+      tree compound;
+      tree args = build_arguments (indices, compound);
 
       args = tree_cons (NULL_TREE, build_int (num), args);
       args = tree_cons (NULL_TREE,
@@ -2300,6 +2291,11 @@
 			 build3 (CALL_EXPR, ptr_type_node,
 				 builtin_Jv_NewMultiArray,
 				 args, NULL_TREE));
+
+      // This is to force evaluation order to be correct.
+      if (compound != NULL_TREE)
+	current = build2 (COMPOUND_EXPR, TREE_TYPE (current), compound,
+			  current);
       annotate (current, new_elt);
     }
   else


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