Bug 19921 - wrong argument count for invokeInterface with new multidimensional array
Summary: wrong argument count for invokeInterface with new multidimensional array
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Tom Tromey
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-02-12 07:55 UTC by Kalle Olavi Niemitalo
Modified: 2005-02-16 19:46 UTC (History)
2 users (show)

See Also:
Host: i386-pc-linux-gnu
Target: i386-pc-linux-gnu
Build: i386-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2005-02-13 00:20:03


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kalle Olavi Niemitalo 2005-02-12 07:55:09 UTC
A GCC checked out on 2005-02-12 compiles the following Java
source to invalid bytecode.  This is a variation of code that
occurs in gnu.classpath.tools.gjdoc.Main.startDoclet.

interface I {
    void f(Object x);
}

class C {
    static void g(I i) {
        i.f(new Object[1][1]);
    }
}

$ gcj -C -v array.java
Using built-in specs.
Target: i386-pc-linux-gnu
Configured with: /home/kalle/src/FOREIGN-CVS/gcc/configure --prefix=/home/kalle
--exec-prefix=/home/kalle/i386-pc-linux-gnu --host=i386-pc-linux-gnu
--build=i386-pc-linux-gnu --with-x-toolkit=gtk
Thread model: posix
gcc version 4.0.0 20050212 (experimental)

/home/kalle/stow/gcc/i386-pc-linux-gnu/bin/../libexec/gcc/i386-pc-linux-gnu/4.0.0/jc1 array.java -quiet -dumpbase array.java -auxbase-strip NONE -g1 -version
-fsyntax-only -femit-class-files -o /dev/null
GNU Java version 4.0.0 20050212 (experimental) (i386-pc-linux-gnu)
	compiled by GNU C version 4.0.0 20050129 (experimental).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Class path starts here:
    ./
   
/home/kalle/stow/gcc/i386-pc-linux-gnu/bin/../lib/gcc/../../../share/java/libgcj-4.0.0.jar/ (system) (zip)
$ ls -l
yhteensÃEUR 12
-rw-rw-r--  1 kalle kalle 113 2005-02-12 09:45 array.java
-rw-rw-r--  1 kalle kalle 303 2005-02-12 09:45 C.class
-rw-rw-r--  1 kalle kalle 123 2005-02-12 09:45 I.class
$ gij C
Exception in thread "main" java.lang.VerifyError: verification failed at PC 7
in C:g((LI;)V): wrong argument count for invokeinterface
   at _Jv_BytecodeVerifier.verify_fail(byte, int)
(/home/kalle/stow/gcc/i386-pc-linux-gnu/lib/libgcj.so.6.0.0)
   at _Jv_BytecodeVerifier.verify_instructions_0()
(/home/kalle/stow/gcc/i386-pc-linux-gnu/lib/libgcj.so.6.0.0)
   at _Jv_VerifyMethod(_Jv_InterpMethod)
(/home/kalle/stow/gcc/i386-pc-linux-gnu/lib/libgcj.so.6.0.0)
   at _Jv_InterpreterEngine.do_verify(java.lang.Class)
(/home/kalle/stow/gcc/i386-pc-linux-gnu/lib/libgcj.so.6.0.0)
   at _Jv_Linker.verify_class(java.lang.Class)
(/home/kalle/stow/gcc/i386-pc-linux-gnu/lib/libgcj.so.6.0.0)
   at _Jv_Linker.wait_for_state(java.lang.Class, int)
(/home/kalle/stow/gcc/i386-pc-linux-gnu/lib/libgcj.so.6.0.0)
   at java.lang.VMClassLoader.resolveClass(java.lang.Class)
(/home/kalle/stow/gcc/i386-pc-linux-gnu/lib/libgcj.so.6.0.0)
   at java.lang.Class.initializeClass()
(/home/kalle/stow/gcc/i386-pc-linux-gnu/lib/libgcj.so.6.0.0)
   at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader)
(/home/kalle/stow/gcc/i386-pc-linux-gnu/lib/libgcj.so.6.0.0)
   at java.lang.Class.forName(java.lang.String)
(/home/kalle/stow/gcc/i386-pc-linux-gnu/lib/libgcj.so.6.0.0)
   at gnu.java.lang.MainThread.run()
(/home/kalle/stow/gcc/i386-pc-linux-gnu/lib/libgcj.so.6.0.0)
   at _Jv_ThreadRun(java.lang.Thread)
(/home/kalle/stow/gcc/i386-pc-linux-gnu/lib/libgcj.so.6.0.0)
   at _Jv_RunMain(java.lang.Class, byte const, int, byte const, boolean)
(/home/kalle/stow/gcc/i386-pc-linux-gnu/lib/libgcj.so.6.0.0)
   at main (/home/kalle/stow/gcc/i386-pc-linux-gnu/lib/libgij.so.6.0.0)
   at __libc_start_main (/lib/libc-2.3.2.so)
   at _start
(/home/kalle/svn/y2004/lentoasema/trunk/bugit/GCC/x/../sysdeps/i386/elf/start.S:105)
$ jcf-dump -c C.class | grep invokeinterface
  7: invokeinterface <InterfaceMethod I.f (java.lang.Object)void> nargs:3
$ 

If I add more dimensions to the array, then gcj generates even more
extra arguments.
Comment 1 Tom Tromey 2005-02-13 00:20:03 UTC
I'm testing a patch.
Comment 2 GCC Commits 2005-02-14 20:04:49 UTC
Subject: Bug 19921

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	tromey@gcc.gnu.org	2005-02-14 20:04:36

Modified files:
	libjava        : ChangeLog 
	gcc/java       : ChangeLog jcf-write.c 
Added files:
	libjava/testsuite/libjava.lang: PR19929.java PR19929.out 

Log message:
	gcc/java:
	PR java/19921:
	* jcf-write.c (generate_bytecode_insns) <CALL_EXPR>: Note the
	stack effect of multianewarray.
	
	libjava:
	For PR java/19929:
	* testsuite/libjava.lang/PR19929.out: New file.
	* testsuite/libjava.lang/PR19929.java: New file.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&r1=1.3320&r2=1.3321
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/testsuite/libjava.lang/PR19929.java.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/testsuite/libjava.lang/PR19929.out.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&r1=1.1551&r2=1.1552
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/jcf-write.c.diff?cvsroot=gcc&r1=1.161&r2=1.162

Comment 3 Tom Tromey 2005-02-14 20:05:25 UTC
I checked in a fix for this.