Summary: | is this code reachable or not? | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Adam Kiezun <akiezun> |
Component: | Core | Assignee: | Philipe Mulet <philippe_mulet> |
Status: | RESOLVED FIXED | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | ||
Version: | 2.0 | ||
Target Milestone: | 2.0 M5 | ||
Hardware: | PC | ||
OS: | Windows 2000 | ||
Whiteboard: |
Description
Adam Kiezun
2002-03-20 11:58:42 EST
I would agree with you. Sounds like a codegen bug (where we would treat is as a for(;true;p()) Need to investigate With this test case: [public class A { public void m() { for(;false;p()); System.out.println("m"); } public void p() { System.out.println("p"); } public static void main(String[] args) { new A().m(); } }] javac 1.4 reports an unreachable statement. A.java:4: unreachable statement for(;false;p()); ^ 1 error javac 1.3 accepts it without any error. And the output is: 'm'. The code gen is quit awkwards. Method void m() 0 goto 7 3 aload_0 4 invokevirtual #2 <Method void p()> 7 getstatic #3 <Field java.io.PrintStream out> 10 ldc #4 <String "m"> 12 invokevirtual #5 <Method void println(java.lang.String)> 15 return It seems that the bytecodes from 3 to 4 included are unreachable. The code gen could simply be: Method void m() 0 getstatic #3 <Field java.io.PrintStream out> 3 ldc #4 <String "m"> 5 invokevirtual #5 <Method void println(java.lang.String)> 8 return We generate: Method void m() 0 aload_0 1 invokevirtual #17 <Method void p()> 4 goto 0 7 getstatic #23 <Field java.io.PrintStream out> 10 ldc #24 <String "m"> 12 invokevirtual #30 <Method void println(java.lang.String)> 15 return which explains the infinite loop. Fix post M4 build. We now generate no bytecode at all for such a for statement (javac does produce unreachable code). Fixed |