Bug 14551 - Switch w sign-extended byte and >16 labels causes error in tree.c
Summary: Switch w sign-extended byte and >16 labels causes error in tree.c
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 3.3.3
: P2 normal
Target Milestone: 4.0.0
Assignee: Andrew Haley
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2004-03-12 13:08 UTC by Erwin Bolwidt
Modified: 2004-04-12 12:58 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-03-12 16:01:37


Attachments
Minimized source file that still triggers the bug (628 bytes, text/plain)
2004-03-12 13:11 UTC, Erwin Bolwidt
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Erwin Bolwidt 2004-03-12 13:08:59 UTC
I found a bug in gcj-3.3. It looks like this from the command line:

$ gcj-3.3 -c GcjBug.java
GcjBug.java: In class `GcjBug':
GcjBug.java: In method `GcjBug.getPacketTypeName(int)':
GcjBug.java:62: internal compiler error: in tree_low_cst, at tree.c:3255
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.


I've included a test case as an attachment called GcjBug.java. It is derived
from a file in my application that caused this problem, but strips code that
isn't necessary to show the bug.

I've done some analyses in the Java source to find out what might trigger the
bug in particular, and also discovered a workaround.

The bug occurs when there is a switch statement, in which the expression is of
type 'int', and all case labels are constants of type 'byte'.

I've found two requirements to trigger the bug:
- there must be at least 17 case labels (I had plenty more in the original
source, but less than 17 labels doesn't trigger the bug)
- at least one of the case labels must have a negative value as a byte, such as
'(byte) 202'.

The workaround is: cast the expression of the switch statement to type byte,
i.e. change 'switch (type)' to 'switch ((byte)type)' in the GcjBug.java source code.


Hopefully this report is useful enough to fix the bug

P.s.

GCJ version information:

$ gcj-3.3 -v
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.3/specs
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.3/../../../libgcj.spec
rename spec lib to liborig
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib
--enable-nls --without-included-gettext --enable-__cxa_atexit
--enable-clocale=gnu --enable-debug --enable-java-gc=boehm
--enable-java-awt=xlib --enable-objc-gc i486-linux
Thread model: posix
gcc version 3.3.3 (Debian 20040306)
Comment 1 Erwin Bolwidt 2004-03-12 13:11:23 UTC
Created attachment 5905 [details]
Minimized source file that still triggers the bug

All code that could be removed while still triggering the bug has been removed;
the result is a valid Java source file that can (should) be compiled by itself.
Comment 2 Andrew Pinski 2004-03-12 16:01:36 UTC
Confirmed on the mainline.
(gdb) p debug_tree(t)
<integer_cst 0x40123050 type <integer_type 0x400503cc int> constant public static overflow 161>
Comment 3 GCC Commits 2004-03-15 14:15:16 UTC
Subject: Bug 14551

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	aph@gcc.gnu.org	2004-03-15 14:15:10

Modified files:
	gcc/java       : ChangeLog typeck.c 

Log message:
	2004-03-12  Andrew Haley  <aph@redhat.com>
	
	PR java/14551
	* typeck.c (convert): Clear TREE_OVERFLOW after an integer
	conversion.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&r1=1.1338&r2=1.1339
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/typeck.c.diff?cvsroot=gcc&r1=1.61&r2=1.62

Comment 4 Andrew Pinski 2004-04-12 12:58:13 UTC
Closing as fixed.