Bug 23620 - [4.0/4.1 Regression] Segfault compiling inner interfaces
Summary: [4.0/4.1 Regression] Segfault compiling inner interfaces
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 4.0.1
: P2 normal
Target Milestone: 4.0.3
Assignee: Nathan Sidwell
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: 18131
  Show dependency treegraph
 
Reported: 2005-08-29 09:44 UTC by Wil Mahan
Modified: 2005-10-14 12:09 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.4.0
Known to fail:
Last reconfirmed: 2005-09-02 07:13:06


Attachments
Superficial fix (237 bytes, patch)
2005-08-31 16:25 UTC, Wil Mahan
Details | Diff
Proposed solution (221 bytes, patch)
2005-09-01 19:23 UTC, Wil Mahan
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Wil Mahan 2005-08-29 09:44:13 UTC
I'm getting an ICE with gcc 4.0.1 that I've reduced to the following test case
with three classes, in A.java, B.java, and C.java, respectively:

public class A  {
    public interface AInt { void methA(); }
}
public class B implements A.AInt {
    void methA() { }
    public interface BInt { void methB(); }
}
public class C implements B.BInt {
    void methB() { }
}

$ gcj -C A.java
$ gcj -C B.java
$ gcj -C C.java
C.java:0: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
For Debian GNU/Linux specific bug reporting instructions,
see <URL:file:///usr/share/doc/gcc-4.0/README.Bugs>.

However, doing

$ gcj -C A.java B.java C.java

gives no error.

Sorry if this is already known, but I couldn't find a similar bug already reported.

$ gcc-4.0 -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib --enable-nls
--without-included-gettext --enable-threads=posix --program-suffix=-4.0
--enable-__cxa_atexit --enable-libstdcxx-allocator=mt --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr
--disable-werror --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.0.1 (Debian 4.0.1-2)
Comment 1 Andrew Pinski 2005-08-31 15:26:05 UTC
Confirmed, this is a regression from 3.4.0 where this worked just fine.
before 3.4.0, we rejected this with:
C.java:2: error: Class `C' must override `C.methB()' with a public method in order to implement 
interface `B$BInt'.
       void methB() { }
            ^
1 error

Actually that is correct, we should error out, even fixing that bug I still get an ICE.
I will report a bug for that one soon too.



Back trace:
#0  0x0805991c in check_inner_circular_reference (source=0xb7d35b80, target=0xb7d32b80) at 
parse.y:5375
#1  0x08059a15 in check_inner_circular_reference (source=0xb7d32e04, target=0xb7d32b80) at 
parse.y:5397
#2  0x08059a15 in check_inner_circular_reference (source=0xb7d32b80, target=0xb7d32b80) at 
parse.y:5397
#3  0x08066d99 in java_check_circular_reference () at parse.y:5445
#4  0x080cce1f in parse_source_file_3 () at /home/peshtigo/pinskia/src/gnu/gcc/src/gcc/java/jcf-
parse.c:1020
#5  0x080d0a3d in java_parse_file (set_yydebug=0) at /home/peshtigo/pinskia/src/gnu/gcc/src/gcc/
java/jcf-parse.c:1286
Comment 2 Wil Mahan 2005-08-31 16:23:53 UTC
I guess that is a bug in my test case. I didn't notice because it compiles fine
with gcc 4.0.1 when A.class and A$AInt.class are not present.

The problem seems to be that when check_inner_circular_reference() is looking
for circular references, it segfaults when it gets to the tree for A, which has
->type.binfo == NULL. I'm not sure if that's supposed to happen.

Here's a patch that fixes the bug for me, but it may just fix the symptom rather
than the real problem.
Comment 3 Wil Mahan 2005-08-31 16:25:05 UTC
Created attachment 9634 [details]
Superficial fix
Comment 4 Wil Mahan 2005-09-01 19:18:42 UTC
I think I found the root of the problem. In 3.4.x, make_class() in java/class.c
looks like this:

  type = make_node (RECORD_TYPE);
  TYPE_BINFO (type) = make_tree_vec (BINFO_ELTS);
  MAYBE_CREATE_TYPE_TYPE_LANG_SPECIFIC (type);

but in 4.0.1 it becomes this:

  type = make_node (RECORD_TYPE);
  MAYBE_CREATE_TYPE_TYPE_LANG_SPECIFIC (type);

The crash was caused by TYPE_BINFO not being set for a certain type. I added the
line 

  TYPE_BINFO (type) = make_tree_binfo (0);

to make_class(). This seems consistent with the changes made in 4.0, and it
fixes the problem for me.
Comment 5 Wil Mahan 2005-09-01 19:23:32 UTC
Created attachment 9641 [details]
Proposed solution
Comment 6 Andrew Pinski 2005-09-01 21:37:54 UTC
Then this was caused by:
        * class.c (make_class): Do not create binfo here.
        (set_super_info): Create it here.
        * java-tree.h (CLASS_HAS_SUPER): Cope with lack of a binfo.

Nathan?
Comment 7 Tom Tromey 2005-09-21 14:29:18 UTC
I had to make the methods in B and C public in order
to compile.
Comment 8 CVS Commits 2005-10-14 08:46:58 UTC
Subject: Bug 23620

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	nathan@gcc.gnu.org	2005-10-14 08:46:55

Modified files:
	gcc/java       : ChangeLog class.c 

Log message:
	PR java/23620
	* class.c (make_class): Create empty binfo here.
	(set_super_info): Only create binfo if we have superclasses.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&r1=1.1668&r2=1.1669
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/class.c.diff?cvsroot=gcc&r1=1.241&r2=1.242

Comment 9 Nathan Sidwell 2005-10-14 08:48:00 UTC
fixed mainline and 4.0
2005-10-14  Nathan Sidwell  <nathan@codesourcery.com>
	    Wil Mahan <wmahan@gmail.com>

	PR java/23620
	* class.c (make_class): Create empty binfo here.
	(set_super_info): Only create binfo if we have superclasses.
Comment 10 CVS Commits 2005-10-14 08:48:11 UTC
Subject: Bug 23620

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	nathan@gcc.gnu.org	2005-10-14 08:48:02

Modified files:
	gcc/java       : ChangeLog class.c 

Log message:
	PR java/23620
	* class.c (make_class): Create empty binfo here.
	(set_super_info): Only create binfo if we have superclasses.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1556.2.37&r2=1.1556.2.38
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/class.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.220.8.7&r2=1.220.8.8