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]

Java PATCH: Fix increments of floats/doubles



We were generating invalid class files for expressions of the form
`d++' where `d' had type double.

In particular, we generated the sequence:

  dload
  lconst_1
  dadd

which is wrong because there should be a double in the top stack slot
before executing the `dadd'.  We caught this when converting the
class file to native code.

Fixed with the attached patch.  I was not sophisticated enough to use
fconst_1/dconst_1 where that was possible, if it matters.

OK to install?  

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2001-08-28  Mark Mitchell  <mark@codesourcery.com>

	* jcf-write.c (generate_bytecode_insns): Generate an integer to
	real conversion for increments and decrements of reals.

*** jcf-write.c~	Sun May 13 01:17:31 2001
--- jcf-write.c	Tue Aug 28 00:00:42 2001
***************
*** 1960,1967 ****
        /* Stack, if ARRAY_REF:  ..., [result, ] array, index, oldvalue. */
        /* Stack, if COMPONENT_REF:  ..., [result, ] objectref, oldvalue. */
        /* Stack, otherwise:  ..., [result, ] oldvalue. */
!       if (size == 1)
! 	push_int_const (value, state);
        else
  	push_long_const (value, (HOST_WIDE_INT)(value >= 0 ? 0 : -1), state);
        NOTE_PUSH (size);
--- 1960,1974 ----
        /* Stack, if ARRAY_REF:  ..., [result, ] array, index, oldvalue. */
        /* Stack, if COMPONENT_REF:  ..., [result, ] objectref, oldvalue. */
        /* Stack, otherwise:  ..., [result, ] oldvalue. */
!       if (size == 1 || TREE_CODE (type) == REAL_TYPE)
! 	{
! 	  push_int_const (value, state);
! 	  if (TREE_CODE (type) == REAL_TYPE)
! 	    {
! 	      RESERVE (1);
! 	      OP1 (TYPE_PRECISION (type) == 32 ? OPCODE_i2f : OPCODE_i2d);
! 	    }
! 	}
        else
  	push_long_const (value, (HOST_WIDE_INT)(value >= 0 ? 0 : -1), state);
        NOTE_PUSH (size);


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