User account creation filtered due to spam.

Bug 23230 - Wrong "this" used when call made to superclass which is also superclass of enclosing class
Summary: Wrong "this" used when call made to superclass which is also superclass of en...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.0.2
Assignee: Robin Green
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: patch, wrong-code
: 23220 (view as bug list)
Depends on:
Blocks: 18131
  Show dependency treegraph
 
Reported: 2005-08-04 15:01 UTC by Robin Green
Modified: 2005-09-06 14:07 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-08-08 09:43:39


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robin Green 2005-08-04 15:01:11 UTC
The following file is miscompiled by gcj -C:

public class Outer extends Thread {

  public class Inner extends Thread {
    private Inner () {
      start ();
    }
  }

}

It uses the wrong "this" to call start():

Outer$Inner(Outer);
  Code:
   0:   aload_0
   1:   aload_1
   2:   putfield        #12; //Field this$0:LOuter;
   5:   aload_0
   6:   invokespecial   #15; //Method java/lang/Thread."<init>":()V
   9:   aload_1
   10:  invokevirtual   #18; //Method java/lang/Thread.start:()V
   13:  return

}

Sun's compiler outputs correct code:

private Outer$Inner(Outer);
  Code:
   0:   aload_0
   1:   aload_1
   2:   putfield        #1; //Field this$0:LOuter;
   5:   aload_0
   6:   invokespecial   #2; //Method java/lang/Thread."<init>":()V
   9:   aload_0
   10:  invokevirtual   #3; //Method start:()V
   13:  return

}

The difference is at 9.

Note: The bug does not occur if you just replace start() (which is declared in
java.lang.Thread) with notify() (which is declared in java.lang.Object).
Comment 1 Andrew Pinski 2005-08-04 15:23:33 UTC
Confirmed.
Comment 2 Robin Green 2005-08-04 15:26:47 UTC
The relevant part of the JLS is section 15.12.1 @
http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#20448
Comment 3 Robin Green 2005-08-04 22:03:06 UTC
I'm testing a patch.
Comment 4 Robin Green 2005-08-07 11:51:01 UTC
The patch is tested and is in the gcc patch queue @
http://www.dberlin.org/cgi-bin/patches.py
Comment 5 Ranjit Mathew 2005-08-08 09:43:39 UTC
Another testcase:
------------------------------- 8< -------------------------------
class Snafu
{
  public void whoami( )
  {
    System.out.println( this.getClass( ).getName( ));
  }
}

public class PR23230 extends Snafu
{
  class Foo extends Snafu
  {
    Foo( )
    {
      whoami( );
    }
  }

  void bar( )
  {
    new Foo( );
  }

  public static void main( String[] args)
  {
    new PR23230( ).bar( );
  }
}
------------------------------- 8< -------------------------------
Comment 6 Robin Green 2005-08-09 00:44:43 UTC
*** Bug 23220 has been marked as a duplicate of this bug. ***
Comment 7 CVS Commits 2005-08-11 11:49:33 UTC
Subject: Bug 23230

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	aph@gcc.gnu.org	2005-08-11 11:49:27

Modified files:
	gcc/java       : ChangeLog java-gimplify.c parse.y 

Log message:
	2005-08-10  Andrew Haley  <aph@redhat.com>
	
	* java-gimplify.c (java_gimplify_modify_expr): Fix any pointer
	type mismatches to make legal GIMPLE.
	
	2005-08-10  Robin Green <greenrd@greenrd.org>
	
	PR java/23230:
	* parse.y (maybe_use_access_method): Generalize check from
	java.lang.Object to any superclass of current_class

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&r1=1.1652&r2=1.1653
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/java-gimplify.c.diff?cvsroot=gcc&r1=1.20&r2=1.21
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/parse.y.diff?cvsroot=gcc&r1=1.550&r2=1.551

Comment 8 CVS Commits 2005-08-11 13:04:02 UTC
Subject: Bug 23230

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	aph@gcc.gnu.org	2005-08-11 13:03:51

Modified files:
	gcc/java       : ChangeLog parse.y 

Log message:
	2005-08-10  Robin Green <greenrd@greenrd.org>
	
	PR java/23230:
	* parse.y (maybe_use_access_method): Generalize check from
	java.lang.Object to any superclass of current_class

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.26&r2=1.1556.2.27
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/parse.y.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.528.6.1&r2=1.528.6.2

Comment 9 Andrew Pinski 2005-08-11 13:26:01 UTC
Fixed in 4.0.2.