Bug 162965 - [compiler] dead bytecodes are generated inside conditional expressions
Summary: [compiler] dead bytecodes are generated inside conditional expressions
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.3 RC1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-31 13:22 EST by Olivier Thomann CLA
Modified: 2007-05-15 05:43 EDT (History)
0 users

See Also:
Olivier_Thomann: review+


Attachments
Proposed patch (12.71 KB, patch)
2007-05-04 10:02 EDT, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2006-10-31 13:22:19 EST
Using latest, the following code generates dead bytecodes:
Compile this example:
public class X {
	public static void main(String[] args) {
		boolean a = true, b;
		if (a ? false : (b = true))
			a = b;
		System.out.println("SUCCESS");
	}
}

We generate:
  public static void main(java.lang.String[] args);
     0  iconst_1
     1  istore_1 [a]
     2  iload_1 [a]
     3  ifeq 12
     6  goto 20
     9  goto 18 <=== THIS IS UNREACHABLE
    12  iconst_1
    13  dup
    14  istore_2 [b]
    15  ifeq 20
    18  iload_2 [b]
    19  istore_1 [a]
    20  getstatic java.lang.System.out : java.io.PrintStream [16]
    23  ldc <String "SUCCESS"> [22]
    25  invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]
    28  return

This leads to other issues with stack maps frames.

Once the dead bytecodes are removed, I'll revisit it to see how the stack map frames are generated.
Comment 1 Philipe Mulet CLA 2007-05-04 08:21:21 EDT
Variation on same issue:
        public static void main(String[] args) {
                boolean a = true, b = false;
                if (!(a ? true : (b = true)))
                        a = b;
                System.out.println("SUCCESS");
        }
Comment 2 Philipe Mulet CLA 2007-05-04 10:02:34 EDT
Created attachment 65924 [details]
Proposed patch
Comment 3 Philipe Mulet CLA 2007-05-04 10:03:16 EDT
Olivier - pls review the patch, and cast your vote
Comment 4 Philipe Mulet CLA 2007-05-04 10:04:16 EDT
Added BooleanTest#test039-042
Comment 5 Olivier Thomann CLA 2007-05-07 10:03:39 EDT
+1
Comment 6 Philipe Mulet CLA 2007-05-07 10:23:45 EDT
Released for 3.3RC1.
Fixed
Comment 7 Olivier Thomann CLA 2007-05-07 10:53:39 EDT
Enabled regression test org.eclipse.jdt.core.tests.compiler.regression.StackMapAttributeTest#test023.
This test now passes.
Comment 8 Eric Jodet CLA 2007-05-15 05:26:37 EDT
Verified for 3.3 RC1 using I20070515-0010