public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug java/42892]  New: Incorrect code generated for enhanced for loop.
@ 2010-01-28  6:51 suckfish at ihug dot co dot nz
  2010-01-28  6:51 ` [Bug java/42892] " suckfish at ihug dot co dot nz
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: suckfish at ihug dot co dot nz @ 2010-01-28  6:51 UTC (permalink / raw)
  To: java-prs

The following code (to be attached) contains two loops, one of which is
miscompiled.

The first is an enhanced for loop, the second is the same loop, but manually
desugared accorded to the JLS (JLS 3, section 14.14.2
http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.14.2).

The two loops should therefore behave identically.  They do not; the first loop
[incorrectly] finishes normally, the second loop [correctly] throws a class
cast exception.

The issue is that according to the JLS,

   for (String s:u) ...

gets desugarred to

   for (Type i = u.iterator(); i.hasNext(); ) { String s = i.next(); ... }

where Type is the type of u.iterator().

However, after erasing generics, the initialisation of the loop variable i
potentially requires a cast (after erase, in this case, u.iterator() has
compile-time type Iterator, while the variable has type MyIterator).

It appears that gcj does not insert the required cast.

(Both Sun javac and eclipse get this wrong also, in an identical manner.  It is
possible that Sun will decide to change the JLS to match the compiler
behaviour?)


-- 
           Summary: Incorrect code generated for enhanced for loop.
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: java
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: suckfish at ihug dot co dot nz
  GCC host triplet: x86_64-redhat-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42892


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug java/42892] Incorrect code generated for enhanced for loop.
  2010-01-28  6:51 [Bug java/42892] New: Incorrect code generated for enhanced for loop suckfish at ihug dot co dot nz
@ 2010-01-28  6:51 ` suckfish at ihug dot co dot nz
  2010-01-28  6:53 ` pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: suckfish at ihug dot co dot nz @ 2010-01-28  6:51 UTC (permalink / raw)
  To: java-prs



------- Comment #1 from suckfish at ihug dot co dot nz  2010-01-28 06:51 -------
Created an attachment (id=19736)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=19736&action=view)
Test case


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42892


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug java/42892] Incorrect code generated for enhanced for loop.
  2010-01-28  6:51 [Bug java/42892] New: Incorrect code generated for enhanced for loop suckfish at ihug dot co dot nz
  2010-01-28  6:51 ` [Bug java/42892] " suckfish at ihug dot co dot nz
@ 2010-01-28  6:53 ` pinskia at gcc dot gnu dot org
  2010-01-28  7:02 ` suckfish at ihug dot co dot nz
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-01-28  6:53 UTC (permalink / raw)
  To: java-prs



------- Comment #2 from pinskia at gcc dot gnu dot org  2010-01-28 06:53 -------
>Both Sun javac and eclipse 

Well gcj uses eclipse source to byte code compiler to compile to byte code so
it might not be a bug in gcj's byte code compiler.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42892


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug java/42892] Incorrect code generated for enhanced for loop.
  2010-01-28  6:51 [Bug java/42892] New: Incorrect code generated for enhanced for loop suckfish at ihug dot co dot nz
  2010-01-28  6:51 ` [Bug java/42892] " suckfish at ihug dot co dot nz
  2010-01-28  6:53 ` pinskia at gcc dot gnu dot org
@ 2010-01-28  7:02 ` suckfish at ihug dot co dot nz
  2010-01-28  7:07 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: suckfish at ihug dot co dot nz @ 2010-01-28  7:02 UTC (permalink / raw)
  To: java-prs



------- Comment #3 from suckfish at ihug dot co dot nz  2010-01-28 07:02 -------
So java front end bugs shouldn't be logged here?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42892


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug java/42892] Incorrect code generated for enhanced for loop.
  2010-01-28  6:51 [Bug java/42892] New: Incorrect code generated for enhanced for loop suckfish at ihug dot co dot nz
                   ` (2 preceding siblings ...)
  2010-01-28  7:02 ` suckfish at ihug dot co dot nz
@ 2010-01-28  7:07 ` pinskia at gcc dot gnu dot org
  2010-01-28  7:26 ` suckfish at ihug dot co dot nz
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-01-28  7:07 UTC (permalink / raw)
  To: java-prs



------- Comment #4 from pinskia at gcc dot gnu dot org  2010-01-28 07:07 -------
(In reply to comment #3)
> So java front end bugs shouldn't be logged here?

No they should be.  Just I was trying to point out gcj uses ecj as the source
front-end.  It might be the bytecode compiler which is broke and not the source
to byte code part (which is ecj).  If it is ecj which is getting it incorrect
as you had suggested in comment #0, then it should be reported upsteam and this
bug should be suspended until that is fixed.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42892


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug java/42892] Incorrect code generated for enhanced for loop.
  2010-01-28  6:51 [Bug java/42892] New: Incorrect code generated for enhanced for loop suckfish at ihug dot co dot nz
                   ` (3 preceding siblings ...)
  2010-01-28  7:07 ` pinskia at gcc dot gnu dot org
@ 2010-01-28  7:26 ` suckfish at ihug dot co dot nz
  2010-02-07 20:25 ` pinskia at gcc dot gnu dot org
  2010-02-07 20:26 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: suckfish at ihug dot co dot nz @ 2010-01-28  7:26 UTC (permalink / raw)
  To: java-prs



------- Comment #5 from suckfish at ihug dot co dot nz  2010-01-28 07:26 -------
Ok, it is an ecj bug.  I'll report upstream as soon as their bugzilla stops
hanging...


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42892


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug java/42892] Incorrect code generated for enhanced for loop.
  2010-01-28  6:51 [Bug java/42892] New: Incorrect code generated for enhanced for loop suckfish at ihug dot co dot nz
                   ` (4 preceding siblings ...)
  2010-01-28  7:26 ` suckfish at ihug dot co dot nz
@ 2010-02-07 20:25 ` pinskia at gcc dot gnu dot org
  2010-02-07 20:26 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-02-07 20:25 UTC (permalink / raw)
  To: java-prs



------- Comment #6 from pinskia at gcc dot gnu dot org  2010-02-07 20:25 -------
Confirmed to ...


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2010-02-07 20:25:51
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42892


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug java/42892] Incorrect code generated for enhanced for loop.
  2010-01-28  6:51 [Bug java/42892] New: Incorrect code generated for enhanced for loop suckfish at ihug dot co dot nz
                   ` (5 preceding siblings ...)
  2010-02-07 20:25 ` pinskia at gcc dot gnu dot org
@ 2010-02-07 20:26 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-02-07 20:26 UTC (permalink / raw)
  To: java-prs



------- Comment #7 from pinskia at gcc dot gnu dot org  2010-02-07 20:26 -------
Suspend.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |SUSPENDED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42892


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-02-07 20:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-28  6:51 [Bug java/42892] New: Incorrect code generated for enhanced for loop suckfish at ihug dot co dot nz
2010-01-28  6:51 ` [Bug java/42892] " suckfish at ihug dot co dot nz
2010-01-28  6:53 ` pinskia at gcc dot gnu dot org
2010-01-28  7:02 ` suckfish at ihug dot co dot nz
2010-01-28  7:07 ` pinskia at gcc dot gnu dot org
2010-01-28  7:26 ` suckfish at ihug dot co dot nz
2010-02-07 20:25 ` pinskia at gcc dot gnu dot org
2010-02-07 20:26 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).