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]

java patch: shift bytecode generation



When shifting a long value, gcj would emit bytecode with a long shift
amount.  The shift amount is supposed to be an int value. 

I'm not going to check this in until it has been reviewed.  Once it is
applied, you'll find that the libgcj class files built with `gcj -C'
all verify correctly with Kresten's bytecode verifier.

2000-01-09  Anthony Green  <green@cygnus.com>

	* parse.y (patch_binop): Only mask shift operand when compiling to
	native code.
	(shift_expression): When compiling to bytecode, use CONVERT_EXPR
	to force second operand to int.

Index: gcc/java/parse.y
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/parse.y,v
retrieving revision 1.128
diff -u -r1.128 parse.y
--- parse.y	2000/01/07 20:28:11	1.128
+++ parse.y	2000/01/10 03:39:25
@@ -2165,17 +2165,29 @@
 |	shift_expression LS_TK additive_expression
 		{
 		  $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
-				    $1, $3); 
+				    $1, 
+				    flag_emit_class_files 
+				    ? build1 (CONVERT_EXPR, 
+					      integer_type_node, $3)
+				    : $3);
 		}
 |	shift_expression SRS_TK additive_expression
 		{
 		  $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
-				    $1, $3); 
+				    $1, 
+				    flag_emit_class_files 
+				    ? build1 (CONVERT_EXPR, 
+					      integer_type_node, $3)
+				    : $3);
 		}
 |	shift_expression ZRS_TK additive_expression
 		{
 		  $$ = build_binop (BINOP_LOOKUP ($2.token), $2.location,
-				    $1, $3); 
+				    $1,
+				    flag_emit_class_files 
+				    ? build1 (CONVERT_EXPR, 
+					      integer_type_node, $3)
+				    : $3);
 		}
 |	shift_expression LS_TK error
 		{yyerror ("Missing term"); RECOVER;}
@@ -9850,11 +9862,12 @@
          type of the left-hand operand */
       prom_type = TREE_TYPE (op1);
 
-      /* Shift int only up to 0x1f and long up to 0x3f. The bytecode
-	 generator should take care of removing this operation. FIXME */
-      op2 = fold (build (BIT_AND_EXPR, prom_type, convert (prom_type, op2), 
-			 (prom_type == int_type_node ? build_int_2 (0x1f, 0) :
-			  convert (prom_type, build_int_2 (0x3f, 0)))));
+      /* Shift int only up to 0x1f and long up to 0x3f.  */
+      if (! flag_emit_class_files)
+	op2 = fold (build (BIT_AND_EXPR, prom_type, convert (prom_type, op2), 
+			   (prom_type == int_type_node 
+			    ? build_int_2 (0x1f, 0) :
+			    convert (prom_type, build_int_2 (0x3f, 0)))));
 
       /* The >>> operator is a >> operating on unsigned quantities */
       if (code == URSHIFT_EXPR && ! flag_emit_class_files)


-- 
Anthony Green                                               Cygnus Solutions
                                                       Sunnyvale, California

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