public inbox for java-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [gcjx] Patch: FYI: handle float->int conversions
@ 2005-10-11 18:08 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2005-10-11 18:08 UTC (permalink / raw)
  To: Java Patch List

I'm checking this in on the gcjx branch.

This fixes a gcjx bug when folding float->int conversions.
When converting to an integer type narrower than 'int', we must first
convert to 'int'.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* model/primitive.hh (model_int_primitive::convert): Perform
	intermediate conversions.

Index: model/primitive.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/model/Attic/primitive.hh,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 primitive.hh
--- model/primitive.hh 9 Oct 2005 20:08:03 -0000 1.1.2.3
+++ model/primitive.hh 11 Oct 2005 18:07:33 -0000
@@ -467,12 +467,25 @@
 
   jvalue convert (const model_type *from_type, const jvalue &from_val)
   {
-    if (from_type == primitive_float_type)
-      return convert_from_float<T, jfloat> (from_val, MIN, MAX);
-    else if (from_type == primitive_double_type)
-      return convert_from_float<T, jdouble> (from_val, MIN, MAX);
-    else
-      return model_primitive<T, sig_char>::convert (from_type, from_val);
+    if (from_type == primitive_float_type
+	|| from_type == primitive_double_type)
+      {
+	if (this != primitive_int_type && this != primitive_long_type)
+	  {
+	    // Must use an intermediate cast.
+	    model_primitive_base *mpb
+	      = assert_cast<model_primitive_base *> (primitive_int_type);
+	    jvalue inter = mpb->convert (from_type, from_val);
+	    return convert (mpb, inter);
+	  }
+
+	if (from_type == primitive_float_type)
+	  return convert_from_float<T, jfloat> (from_val, MIN, MAX);
+	else
+	  return convert_from_float<T, jdouble> (from_val, MIN, MAX);
+      }
+
+    return model_primitive<T, sig_char>::convert (from_type, from_val);
   }
 
   // This is out-of-line so we can specialize for jlong.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-10-11 18:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-11 18:08 [gcjx] Patch: FYI: handle float->int conversions Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).