This is the mail archive of the 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]

Patch: FYI: narrowing primitive conversion in gcj

I'm checking this in.

This patch fixes a bug in gcj.  In some cases gcj incorrectly decided
against allowing narrowing primitive conversion.  This patch brings
gcj in line with what JLS 2nd Ed section 5.2 says on the subject.

Tested by rebuilding libgcj on x86 Red Hat Linux 7.3 and running the
test suite.  I've already checked in a test case for this bug.


Index: ChangeLog
from  Tom Tromey  <>

	* parse.y (try_builtin_assignconv): Allow narrowing primitive
	conversion if RHS_TYPE is byte, short, or char.

Index: parse.y
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.392
diff -u -r1.392 parse.y
--- parse.y 16 Aug 2002 10:32:30 -0000 1.392
+++ parse.y 26 Aug 2002 22:15:34 -0000
@@ -12915,11 +12915,14 @@
     new_rhs = convert (lhs_type, rhs);
   /* Try a narrowing primitive conversion (5.1.3):
-       - expression is a constant expression of type int AND
+       - expression is a constant expression of type byte, short, char,
+         or int, AND
        - variable is byte, short or char AND
        - The value of the expression is representable in the type of the
          variable */
-  else if (rhs_type == int_type_node && TREE_CONSTANT (rhs)
+  else if ((rhs_type == byte_type_node || rhs_type == short_type_node
+	    || rhs_type == char_type_node || rhs_type == int_type_node)
+	    && TREE_CONSTANT (rhs)
 	   && (lhs_type == byte_type_node || lhs_type == char_type_node
 	       || lhs_type == short_type_node))

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