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: Fix floating point to integral conversion


This patch fixes conversions from floats and doubles to integral types.
We had special code for conversions to chars, but java has specific rules
for all narrowing type conversions (section 5.1.3 of the spec).

Tested on i686-pc-linux-gnu, with no regressions.

These two mauve tests used to fail, but now pass:

gnu.testlet.java.lang.Double.DoubleTest: Error: test_shortbyteValue failed - 5 (number 1)
gnu.testlet.java.lang.Float.FloatTest: Error: test_shortbyteValue failed - 5 (number 1)

I also get an unexpected pass...

gnu.testlet.java.text.SimpleDateFormat.Test: equals() (number 1)

The calendar code does contain conversions so perhaps this is just 
a happy side effect.

Ok to commit?



2003-06-07  Anthony Green  <green@redhat.com>

	* parse.y (patch_cast): Fix conversions from floating-point to
	integral types.

  
Index: gcc/java/parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.433
diff -2 -c -p -r1.433 parse.y
*** gcc/java/parse.y	17 May 2003 01:40:45 -0000	1.433
--- gcc/java/parse.y	7 Jun 2003 22:56:34 -0000
*************** patch_cast (tree node, tree wfl_op)
*** 14225,14236 ****
  	return node;
  
!       /* float and double type are converted to the original type main
! 	 variant and then to the target type. */
!       if (JFLOAT_TYPE_P (op_type) && TREE_CODE (cast_type) == CHAR_TYPE)
! 	op = convert (integer_type_node, op);
  
!       /* Try widening/narowwing convertion. Potentially, things need
  	 to be worked out in gcc so we implement the extreme cases
! 	 correctly. fold_convert() needs to be fixed. */
        return convert (cast_type, op);
      }
--- 14225,14237 ----
  	return node;
  
!       /* A narrowing conversion from a floating-point number to an
! 	 integral type requires special handling (5.1.3).  */
!       if (JFLOAT_TYPE_P (op_type) && JINTEGRAL_TYPE_P (cast_type))
! 	if (cast_type != long_type_node)
! 	  op = convert (integer_type_node, op);
  
!       /* Try widening/narrowing convertion.  Potentially, things need
  	 to be worked out in gcc so we implement the extreme cases
! 	 correctly.  fold_convert() needs to be fixed.  */
        return convert (cast_type, op);
      }


-- 
Anthony Green <green@redhat.com>
Red Hat, Inc.



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