Note on a fix to java/3096, 3803, 3965.

Alexandre Petit-Bianco apbianco@cygnus.com
Mon Oct 8 11:26:00 GMT 2001


Sorry about being so late addressing this issue.
java/3096, 3803 and 3965 are pressing issues to be fixed. Several
people looked at it, notably Tang and Hans. Hans came up with the
smallest patch which worked at the expense of shunting gcj's ability
to verify that the ++/-- operator can be used on its target (for
instance, one would have been able to write 'String s[] = ...;
++s[x];')
Tang's patch works around the problem the middle end has with certain
arrangements of SAVE_EXPRs:
 http://gcc.gnu.org/ml/java/2001-09/msg00169.html
Tang is doing all the necessary paperwork so we can check his patch
in. In the meantime, I would encourage people to use this patch if
they're likely to build code that contains pre increments/decrements
of an array element indexed by a variable.
I'll put all three PRs in feedback, documenting the existence of a
patch; and hopefully within a few weeks this patch will go in.
Thanks to you all for the help you offered.
./A
2001年09月27日 Tang Ching-Hui <nicholas@cs.nthu.edu.tw>
	 Alexandre Petit-Bianco <apbianco@redhat.com>
	* expr.c: call save_expr on array for correct evaluation order, 
	modified comment, fixed indentation.
	* parse.y: (patch_assignment): Correctly extract the array base
	from the tree generate by build_java_arrayaccess, added comments.
	(patch_array_ref): Remove SAVE_EXPR on ARRAY_REF.
	Fixes java/3096. Fixes java/3803. Fixes java/3965.
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.117
diff -u -p -r1.117 expr.c
--- expr.c	2001年09月21日 16:58:21	1.117
+++ expr.c	2001年10月04日 23:31:45
@@ -798,14 +798,21 @@ build_java_arrayaccess (array, type, ind
 	 TREE_SIDE_EFFECTS( throw ) = 1;
 	}
 }
- 
+
+ /* The SAVE_EXPR is for correct evaluation order. It would be
+ cleaner to use force_evaluation_order (see comment there), but
+ that is difficult when we also have to deal with bounds
+ checking. The SAVE_EXPR is not necessary to do that when we're
+ not checking for array bounds. */
+ if (TREE_SIDE_EFFECTS (index) && throw)
+ throw = build (COMPOUND_EXPR, int_type_node, save_expr (array), throw);
+
 node = build1 (INDIRECT_REF, type, 
 		 fold (build (PLUS_EXPR, ptr_type_node, 
-			 java_check_reference (array, flag_check_references), 
+			 java_check_reference (array,
+						 flag_check_references), 
 			 (throw ? build (COMPOUND_EXPR, int_type_node, 
-					 throw, arith )
-			 : arith))));
- 
+					 throw, arith ) : arith))));
 return node;
 }
 
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.316
diff -u -p -r1.316 parse.y
--- parse.y	2001年10月04日 02:58:38	1.316
+++ parse.y	2001年10月04日 23:31:54
@@ -12952,10 +12952,13 @@ patch_assignment (node, wfl_op1, wfl_op2
 /* We can have a SAVE_EXPR here when doing String +=. */
 if (TREE_CODE (op) == SAVE_EXPR)
 op = TREE_OPERAND (op, 0);
- if (flag_bounds_check)
- base = TREE_OPERAND (TREE_OPERAND (op, 1), 0);
- else
- base = TREE_OPERAND (op, 0);
+	 /* We can have a COMPOUND_EXPR here when doing bounds check. */
+	 if (TREE_CODE (op) == COMPOUND_EXPR)
+	 op = TREE_OPERAND (op, 1);
+	 base = TREE_OPERAND (op, 0);
+	 /* Strip the last PLUS_EXPR to obtain the base. */
+	 if (TREE_CODE (base) == PLUS_EXPR)
+	 base = TREE_OPERAND (base, 0);
 	}
 
 /* Build the invocation of _Jv_CheckArrayStore */
@@ -14599,16 +14602,7 @@ patch_array_ref (node)
 TREE_OPERAND (node, 1) = index;
 }
 else
- {
- /* The save_expr is for correct evaluation order. It would be cleaner
-	 to use force_evaluation_order (see comment there), but that is
-	 difficult when we also have to deal with bounds checking. */
- if (TREE_SIDE_EFFECTS (index))
-	array = save_expr (array);
- node = build_java_arrayaccess (array, array_type, index);
- if (TREE_SIDE_EFFECTS (index))
-	node = build (COMPOUND_EXPR, array_type, array, node);
- }
+ node = build_java_arrayaccess (array, array_type, index);
 TREE_TYPE (node) = array_type;
 return node;
 }


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /