java/6382: Conversion of long constants to string uses bad format
Hans_Boehm@hp.com
Hans_Boehm@hp.com
Fri Apr 19 21:06:00 GMT 2002
>Number: 6382
>Category: java
>Synopsis: Conversion of long constants to string uses bad format
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Fri Apr 19 21:06:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Hans_Boehm@hp.com
>Release: GCC pre3.1
>Organization:
>Environment:
Linux/X86
>Description:
Java compiler folds conversion of long to string such that
the resulting string is in hexadecimal and unsigned. It
should be signed and decimal.
This occurs if either a class file or object code is
generated. It does not occur on IA64.
Discussion with Tom Tromey:
Hans> On X86, converting something like (long)1<<63 or (long)3 << 62
Hans> to a string results in an unsigned hexadecimal value, instead of
Hans> a negative decimal one, as required by the spec. This seems to
Hans> be a constant folding problem: The string appears literally in
Hans> the gcj -C output. Interestingly, gcj -C does the right thing
Hans> on IA64.
I tried:
"" + ((long) 1 << 63)
There's definitely a bug here.
And luckily the problem isn't in fold (fold is known to have problems
for java; fixing this is a bit involved).
I debugged a little. It looks like parse.y:print_int_node is
incorrect. As far as I can tell this should never decide to print a
number in hex (string conversion always uses decimal). This also
means we can't rely on sprintf to format the number.
Could you submit a PR for this? I doubt we'll fix this for 3.1 given
the age of the code (it predates the first public release of gcj).
>How-To-Repeat:
Compile the following with either
gcj -C lt.java, or
gcj --main=lt lt.java
and run it.
public class lt {
public static void main(String argv[]) {
System.out.println("" + ((long)1 << 63));
System.out.println("" + ((long)3 << 62));
}
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Java-prs
mailing list