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]
Other format: [Raw text]

Re: PR java/19907: Incorrect code generated for ManifestElement.java


This is a better patch.  When the new verifier was created, a special
case was added to handle PARM_DECLS, and this caused errors further
down the line.  

This new version copes with bytecode generators that re-use arg slots
in a different mode.

Andrew.

2005-02-14  Andrew Haley  <aph@redhat.com>

	PR java/19907
	* expr.c (expand_byte_code): Call promote_arguments().
	(promote_arguments): New function.
	* decl.c (check_local_unnamed_variable): Remve special case for
	new verifier.
	(find_local_variable): Promote all boolean types to int
	when searching for local variable decls.
	
Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/decl.c,v
retrieving revision 1.207
diff -c -2 -p -w -r1.207 decl.c
*** decl.c	24 Jan 2005 19:07:06 -0000	1.207
--- decl.c	14 Feb 2005 14:42:59 -0000
*************** check_local_unnamed_variable (tree best,
*** 271,285 ****
        || (TREE_CODE (decl_type) == POINTER_TYPE
  	  && TREE_CODE (decl) == PARM_DECL
! 	  && TREE_CODE (type) == POINTER_TYPE)
! 
!       /* The new verifier requires a similar treatment in the
! 	 situation where the parameter has an integral type which
! 	 promotes to `int'.  */
!       || (flag_new_verifier
! 	  && TREE_CODE (decl) == PARM_DECL
! 	  && INTEGRAL_TYPE_P (decl_type)
! 	  && TYPE_PRECISION (decl_type) <= 32
! 	  && INTEGRAL_TYPE_P (type)
! 	  && TYPE_PRECISION (type) <= 32))
      {
        if (best == NULL_TREE
--- 271,275 ----
        || (TREE_CODE (decl_type) == POINTER_TYPE
  	  && TREE_CODE (decl) == PARM_DECL
! 	  && TREE_CODE (type) == POINTER_TYPE))
      {
        if (best == NULL_TREE
*************** find_local_variable (int index, tree typ
*** 313,316 ****
--- 303,316 ----
      }
  
+   /* gcj has a function called promote_type(), which is used by both
+      the bytecode compiler and the source compiler.  Unfortunately,
+      the type systems for the Java VM and the Java language are not
+      the same: a boolean in the VM promotes to an int, not to a wide
+      boolean.  If our caller wants something to hold a boolean, that
+      had better be an int, because that slot might be re-used
+      later in integer context.  */
+   if (TREE_CODE (type) == BOOLEAN_TYPE)
+     type = integer_type_node;
+ 
    /* If we don't find a match, create one with the type passed in.
       The name of the variable is #n#m, which n is the variable index
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.216
diff -c -2 -p -w -r1.216 expr.c
*** expr.c	12 Jan 2005 17:28:05 -0000	1.216
--- expr.c	14 Feb 2005 14:43:00 -0000
*************** static tree build_java_throw_out_of_boun
*** 87,90 ****
--- 87,91 ----
  static tree build_java_check_indexed_type (tree, tree); 
  static unsigned char peek_opcode_at_pc (struct JCF *, int, int);
+ static void promote_arguments (void);
  
  static GTY(()) tree operand_type[59];
*************** expand_byte_code (JCF *jcf, tree method)
*** 2962,2965 ****
--- 2963,2968 ----
      }
  
+   promote_arguments ();
+ 
    /* Translate bytecodes.  */
    linenumber_pointer = linenumber_table;
*************** build_java_empty_stmt (void)
*** 3644,3646 ****
--- 3647,3673 ----
  }
  
+ /* Promote all args of integral type before generating any code.  */
+ 
+ static void
+ promote_arguments (void)
+ {
+   int i;
+   tree arg;
+   for (arg = DECL_ARGUMENTS (current_function_decl), i = 0;
+        arg != NULL_TREE;  arg = TREE_CHAIN (arg), i++)
+     {
+       tree arg_type = TREE_TYPE (arg);
+       if (INTEGRAL_TYPE_P (arg_type)
+ 	  && TYPE_PRECISION (arg_type) < 32)
+ 	{
+ 	  tree copy = find_local_variable (i, integer_type_node, -1);
+ 	  java_add_stmt (build2 (MODIFY_EXPR, integer_type_node,
+ 				 copy,
+ 				 fold_convert (integer_type_node, arg)));
+ 	}
+       if (TYPE_IS_WIDE (arg_type))
+ 	i++;
+     }
+ }
+ 
  #include "gt-java-expr.h"


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