Bug 18931

Summary: Java bytecode ICE in except.c remove_unreachable_regions
Product: gcc Reporter: Andrew Overholt <overholt>
Component: javaAssignee: Andrew Haley <aph>
Status: RESOLVED FIXED    
Severity: critical CC: gcc-bugs, java-prs
Priority: P1 Keywords: EH, ice-on-valid-code
Version: 4.0.0   
Target Milestone: 4.0.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2004-12-16 14:59:15
Attachments: .class file to reproduce failure

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.adjustTrailingSlash(java.net.URL,boolean)':
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: 
http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/org.eclipse.releng.basebuilder/

$ 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
reproduce.
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 GCC 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
	BOOLEAN_TYPE or CHAR_TYPE.
	(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.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&r1=1.1522&r2=1.1523
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/convert.h.diff?cvsroot=gcc&r1=1.6&r2=1.7
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/expr.c.diff?cvsroot=gcc&r1=1.214&r2=1.215
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/typeck.c.diff?cvsroot=gcc&r1=1.73&r2=1.74

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 \
jsch-0.1.17.jar

com/jcraft/jsch/ChannelSftp.java: In method
'com.jcraft.jsch.ChannelSftp.ls(java.lang.String)':
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

File:
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.team.cvs.ssh2/jsch-0.1.17.jar

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{
    try{
      p.toString();

      int type=getByte();

      if(type!=100){
	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.