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]

[JAVA PATCH] PR 19295: Support useless NOP_EXPRs in jcf-write.c


The following patch is the first (and critical) of two patches for
resolving PR java/19295.  The issue is that generate_bytecode_insns
doesn't handle the possibility of conversions between two integer types
of the same precision.  Rather than emit erroneous insns that fail to
verify, the patch below treats these conversions as no-ops.

The following patch has been tested on i686-pc-linux-gnu with a full
"make bootstrap", including java, and regression tested with a top-level
"make -k check" with no new failures in libjava.  The new test case
passes with patch but fails without it.

Ok for mainline?



2005-01-23  Roger Sayle  <roger@eyesopen.com>

	PR java/19295
	* jcf-write.c (generate_bytecode_insns): Conversions between
	integer types of the same precision shouldn't generate widening
	or narrowing conversion bytecodes.

	* testsuite/libjava.compile/PR19295.java: New test case.


Index: jcf-write.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-write.c,v
retrieving revision 1.158
diff -c -3 -p -r1.158 jcf-write.c
*** jcf-write.c	24 Nov 2004 11:41:38 -0000	1.158
--- jcf-write.c	23 Jan 2005 15:48:37 -0000
*************** generate_bytecode_insns (tree exp, int t
*** 2260,2299 ****
  	  }
  	else /* Convert numeric types. */
  	  {
! 	    int wide_src = TYPE_PRECISION (src_type) > 32;
! 	    int wide_dst = TYPE_PRECISION (dst_type) > 32;
! 	    NOTE_POP (1 + wide_src);
! 	    RESERVE (1);
  	    if (TREE_CODE (dst_type) == REAL_TYPE)
  	      {
  		if (TREE_CODE (src_type) == REAL_TYPE)
  		  OP1 (wide_dst ? OPCODE_f2d : OPCODE_d2f);
! 		else if (TYPE_PRECISION (src_type) == 64)
  		  OP1 (OPCODE_l2f + wide_dst);
  		else
  		  OP1 (OPCODE_i2f + wide_dst);
  	      }
! 	    else /* Convert to integral type. */
  	      {
  		if (TREE_CODE (src_type) == REAL_TYPE)
  		  OP1 (OPCODE_f2i + wide_dst + 3 * wide_src);
  		else if (wide_dst)
  		  OP1 (OPCODE_i2l);
  		else if (wide_src)
  		  OP1 (OPCODE_l2i);
! 		if (TYPE_PRECISION (dst_type) < 32)
  		  {
  		    RESERVE (1);
  		    /* Already converted to int, if needed. */
! 		    if (TYPE_PRECISION (dst_type) <= 8)
  		      OP1 (OPCODE_i2b);
  		    else if (TYPE_UNSIGNED (dst_type))
  		      OP1 (OPCODE_i2c);
  		    else
  		      OP1 (OPCODE_i2s);
  		  }
  	      }
- 	    NOTE_PUSH (1 + wide_dst);
  	  }
        }
        break;
--- 2260,2307 ----
  	  }
  	else /* Convert numeric types. */
  	  {
! 	    int src_prec = TYPE_PRECISION (src_type);
! 	    int dst_prec = TYPE_PRECISION (dst_type);
! 	    int wide_src = src_prec > 32;
! 	    int wide_dst = dst_prec > 32;
  	    if (TREE_CODE (dst_type) == REAL_TYPE)
  	      {
+ 		NOTE_POP (1 + wide_src);
+ 		RESERVE (1);
  		if (TREE_CODE (src_type) == REAL_TYPE)
  		  OP1 (wide_dst ? OPCODE_f2d : OPCODE_d2f);
! 		else if (src_prec == 64)
  		  OP1 (OPCODE_l2f + wide_dst);
  		else
  		  OP1 (OPCODE_i2f + wide_dst);
+ 		NOTE_PUSH (1 + wide_dst);
  	      }
! 	    /* Convert to integral type (but ignore non-widening
! 	       and non-narrowing integer type conversions).  */
! 	    else if (TREE_CODE (src_type) == REAL_TYPE
! 		     || src_prec != dst_prec)
  	      {
+ 		NOTE_POP (1 + wide_src);
+ 		RESERVE (1);
  		if (TREE_CODE (src_type) == REAL_TYPE)
  		  OP1 (OPCODE_f2i + wide_dst + 3 * wide_src);
  		else if (wide_dst)
  		  OP1 (OPCODE_i2l);
  		else if (wide_src)
  		  OP1 (OPCODE_l2i);
! 		if (dst_prec < 32)
  		  {
  		    RESERVE (1);
  		    /* Already converted to int, if needed. */
! 		    if (dst_prec <= 8)
  		      OP1 (OPCODE_i2b);
  		    else if (TYPE_UNSIGNED (dst_type))
  		      OP1 (OPCODE_i2c);
  		    else
  		      OP1 (OPCODE_i2s);
  		  }
+ 		NOTE_PUSH (1 + wide_dst);
  	      }
  	  }
        }
        break;


public class PR19295 implements myInterface {
        public long tagBits = 0;

        public final boolean isArrayType() {
            return (tagBits & IsArrayType) != 0;
        }
}

abstract class blah {
	public final static int Bit1 = 0x2;
}

interface myInterface {
        long IsArrayType = blah.Bit1;
}


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


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