Bug 18931 - Java bytecode ICE in except.c remove_unreachable_regions
Summary: Java bytecode ICE in except.c remove_unreachable_regions
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 4.0.0
: P1 critical
Target Milestone: 4.0.0
Assignee: Andrew Haley
Keywords: EH, ice-on-valid-code
Depends on:
Reported: 2004-12-10 19:18 UTC by Andrew Overholt
Modified: 2005-04-20 02:01 UTC (History)
2 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2004-12-16 14:59:15

.class file to reproduce failure (382 bytes, application/octet-stream)
2005-01-05 23:54 UTC, Bryce McKinlay

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Overholt 2004-12-10 19:18:53 UTC
When natively compiling Eclipse jars with -O2, I get a compiler error:

$ gcj -fnew-verifier -fPIC -fjni -findirect-dispatch -shared -O2 -o
eclipse/startup.jar.so eclipse/startup.jar
org/eclipse/core/launcher/Main.java: In class 'org.eclipse.core.launcher.Main':
org/eclipse/core/launcher/Main.java: In method
org/eclipse/core/launcher/Main.java:0: internal compiler error: in
copy_to_mode_reg, at explow.c:635

Compiling without -O2 (exact same other arguments) gives no errors.

startup.jar can be found here: 

$ gcj --version
gcj (GCC) 4.0.0 20041130 (experimental)
Comment 1 Andrew Pinski 2004-12-10 19:41:49 UTC
What target is this on? i686-pc-linux?
I cannot reproduce this on 20041204 on powerpc-darwin.
Comment 2 Andrew Overholt 2004-12-10 19:43:46 UTC
Yes, this is i686-linux.  I'll update to a more recent snapshot and see if I can
Comment 3 Tom Tromey 2004-12-14 20:16:10 UTC
I got this to fail with yesterday's cvs head.
Removing the "-O2" is a workaround.
Comment 4 Andrew Haley 2004-12-16 15:00:16 UTC
Bumping priority because this is possibly a front end bug that breaks many programs/
Comment 5 CVS Commits 2004-12-17 15:09:50 UTC
Subject: Bug 18931

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	aph@gcc.gnu.org	2004-12-17 15:09:12

Modified files:
	gcc/java       : ChangeLog convert.h expr.c typeck.c 

Log message:
	2004-12-17  Andrew Haley  <aph@redhat.com>
	PR java/18931
	* typeck.c (convert): Use a CONVERT_EXPR when converting to
	(convert_to_boolean, convert_to_char) : Remove.
	* convert.h (convert_to_boolean, convert_to_char) : Remove.
	* expr.c (expand_load_internal): Do type conversion if type is not
	as required.


Comment 6 Andrew Pinski 2004-12-17 17:24:41 UTC
Fixed on the mainline.
Comment 7 Andrew Overholt 2005-01-05 21:49:43 UTC
Using Jakub's gcc4 RPMs from Fedora rawhide (on Fedora Core 3), I'm getting:

gcj4 -O2 -fPIC -fjni -findirect-dispatch -shared -o jsch-0.1.17.so \

com/jcraft/jsch/ChannelSftp.java: In method
com/jcraft/jsch/ChannelSftp.java:0: internal compiler error: in
remove_unreachable_regions, at except.c:694

This does not happen with no -O flag.

gcj4 --version:
gcj4 (GCC) 4.0.0 20041228 (Red Hat 4.0.0-0.17)
target:  i686-pc-linux


A similar error happens with jsch-0.1.16.jar.
Comment 8 Bryce McKinlay 2005-01-05 23:53:30 UTC
I narrowed this down to a small test case. The following code will cause the
crash when compiled to bytecode using Sun's javac 1.5.0 (but not when
byte-compiled with gcj or ecj).

public class PR18931 {

  public int getByte() 
    return 1;

  public void ls(String p) throws Exception{

      int type=getByte();

	throw new Exception("");
      if(type==100) return;
      throw new Error();
    catch(Exception e){
      throw new Exception("");

It occurs to me that we don't have any way to do regression tests for bytecode
compilation failures with bytecode produced by other compilers.
Comment 9 Bryce McKinlay 2005-01-05 23:54:48 UTC
Created attachment 7880 [details]
.class file to reproduce failure
Comment 10 Tom Tromey 2005-01-05 23:57:21 UTC
I suppose we could check in .class files.
That is mildly painful, if we ever want to change things.
I've occasionally wished we distributed our own jasmin-like
program for these situations.  This sort of thing would be
helpful for testing the verifier as well.

There is at least one test case that includes a binary blob
that it uses to make a new class on the fly.  That's probably
worse than committing a .class file though.
Comment 11 Andrew Pinski 2005-01-06 01:02:57 UTC
Hmm, again this works for me on ppc-darwin, I don't know why.
Comment 12 Andrew Haley 2005-01-18 12:05:46 UTC
It looks like my patch of 2004-12-17 fixes the original bug, but there is a
separate bug triggered by a different test case.  It shouldn't be attached to
this PR.

Please check that my patch really did fix the original bug and close this PR. 
Please open another PR against the new test case.
Comment 13 Andrew Overholt 2005-01-18 14:50:39 UTC
Original bug verified fixed.  New PR filed as requested:  PR19505.