Bug 135602 - [compiler] Codegen bug for continue statement
Summary: [compiler] Codegen bug for continue statement
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 critical (vote)
Target Milestone: 3.2 RC1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-07 12:57 EDT by Tim Hanson CLA
Modified: 2006-04-13 15:55 EDT (History)
1 user (show)

See Also:


Attachments
Decompiled class file (4.90 KB, text/plain)
2006-04-07 13:05 EDT, Tim Hanson CLA
no flags Details
Proposed fix (1.74 KB, patch)
2006-04-07 13:30 EDT, Olivier Thomann CLA
no flags Details | Diff
Regression test (1.41 KB, patch)
2006-04-07 13:35 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.