Bug 135602

Summary: [compiler] Codegen bug for continue statement
Product: [Eclipse Project] JDT Reporter: Tim Hanson <thanson>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: eclipse
Version: 3.2   
Target Milestone: 3.2 RC1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Decompiled class file
none
Proposed fix
none
Regression test none

Description Tim Hanson CLA 2006-04-07 12:57:39 EDT
Compile the following code:

package com.example;

public class Loop {
	public static void main(String[] args) {
		System.out.println("starting");
		Loop l = new Loop();
		l.testLoop();
		System.out.println("finished");
	}
	
	public void testLoop() {
		int loops = 0;
		
		do {
			System.out.println("Loop " + loops);
        	if (loops > 2) {
        		return;
        	}
    		
    		if (loops < 4) {
    			++loops;
    			continue;
    		}
		} while (false);
	}

}

The code does not terminate as expected. When looking at the bytecode for method testLoop(), the goto instruction at offset 38, just does a goto 38.

In a more complex example inside our code, the goto was a completely invalid offset, causing a verifier error.
Comment 1 Tim Hanson CLA 2006-04-07 13:05:43 EDT
Created attachment 38020 [details]
Decompiled class file
Comment 2 Olivier Thomann CLA 2006-04-07 13:24:07 EDT
The bug comes from the while(false) and the usage of a continue statement. In this case we never placed the corresponding label.
Philippe,

we could either place the label even if the condition is false or nullify the continue label in this case.
Comment 3 Olivier Thomann CLA 2006-04-07 13:30:29 EDT
Created attachment 38021 [details]
Proposed fix

This patch places the continueLabel even if the condition is the constant false.
This is in case the continueLabel has not been nullify in the data flow analysis.
The test case runs ok with this fix.
I'll run all tests to validate it.
Comment 4 Olivier Thomann CLA 2006-04-07 13:31:03 EDT
Philippe,

Candidate for RC1.
Comment 5 Olivier Thomann CLA 2006-04-07 13:35:21 EDT
Created attachment 38022 [details]
Regression test

Add test in org.eclipse.jdt.core.tests.compiler.regression.FlowAnalysisTest
Comment 6 Philipe Mulet CLA 2006-04-09 07:31:13 EDT
Definitely RC1 candidate.
Will look into it.
Comment 7 Philipe Mulet CLA 2006-04-10 04:47:33 EDT
Came up with same fix. Added FlowAnalysisTest#test024.
Fixed
Comment 8 Maxime Daniel CLA 2006-04-13 15:55:00 EDT
Test got renumbered to FlowAnalysisTest#test025 indeed.

Verified for 3.2 RC1 using Build id: I20060413-0010.