### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java,v retrieving revision 1.60 diff -u -r1.60 UnconditionalFlowInfo.java --- compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java 5 Dec 2006 11:46:08 -0000 1.60 +++ compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java 4 Mar 2009 16:56:17 -0000 @@ -1544,7 +1544,10 @@ } public FlowInfo setReachMode(int reachMode) { - if (reachMode == REACHABLE && this != DEAD_END) { // cannot modify DEAD_END + if (this == DEAD_END) { + return this; // cannot modify DEAD_END + } + if (reachMode == REACHABLE) { this.tagBits &= ~UNREACHABLE; } else { Index: compiler/org/eclipse/jdt/internal/compiler/flow/FlowInfo.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FlowInfo.java,v retrieving revision 1.35 diff -u -r1.35 FlowInfo.java --- compiler/org/eclipse/jdt/internal/compiler/flow/FlowInfo.java 26 Sep 2006 12:04:03 -0000 1.35 +++ compiler/org/eclipse/jdt/internal/compiler/flow/FlowInfo.java 4 Mar 2009 16:56:16 -0000 @@ -58,7 +58,7 @@ } public static FlowInfo conditional(FlowInfo initsWhenTrue, FlowInfo initsWhenFalse){ - + if (initsWhenTrue == initsWhenFalse) return initsWhenTrue; // if (initsWhenTrue.equals(initsWhenFalse)) return initsWhenTrue; -- could optimize if #equals is defined return new ConditionalFlowInfo(initsWhenTrue, initsWhenFalse); } Index: compiler/org/eclipse/jdt/internal/compiler/ast/DoStatement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/DoStatement.java,v retrieving revision 1.56 diff -u -r1.56 DoStatement.java --- compiler/org/eclipse/jdt/internal/compiler/ast/DoStatement.java 6 Mar 2007 02:38:48 -0000 1.56 +++ compiler/org/eclipse/jdt/internal/compiler/ast/DoStatement.java 4 Mar 2009 16:56:16 -0000 @@ -144,19 +144,19 @@ // continue label (135602) if (hasContinueLabel) { this.continueLabel.place(); - } - // generate condition - Constant cst = this.condition.optimizedBooleanConstant(); - boolean isConditionOptimizedFalse = cst != Constant.NotAConstant && cst.booleanValue() == false; - if (isConditionOptimizedFalse){ - this.condition.generateCode(currentScope, codeStream, false); - } else if (hasContinueLabel) { - this.condition.generateOptimizedBoolean( - currentScope, - codeStream, - actionLabel, - null, - true); + // generate condition + Constant cst = this.condition.optimizedBooleanConstant(); + boolean isConditionOptimizedFalse = cst != Constant.NotAConstant && cst.booleanValue() == false; + if (isConditionOptimizedFalse){ + this.condition.generateCode(currentScope, codeStream, false); + } else { + this.condition.generateOptimizedBoolean( + currentScope, + codeStream, + actionLabel, + null, + true); + } } // May loose some local variable initializations : affecting the local variable attributes if (this.mergedInitStateIndex != -1) { #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java,v retrieving revision 1.30 diff -u -r1.30 FlowAnalysisTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java 5 Jun 2008 09:53:23 -0000 1.30 +++ src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java 4 Mar 2009 16:56:18 -0000 @@ -1506,6 +1506,113 @@ } ); } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=48399 - variation +public void test060() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " static final boolean DEBUG = false;\n" + + " static final int DEBUG_LEVEL = 0;\n" + + " boolean check() { return true; }\n" + + " void foo(boolean b) {\n" + + " if (DEBUG)\n" + + " System.out.println(\"fake reachable1\"); //$NON-NLS-1$\n" + + " if (DEBUG && b)\n" + + " System.out.println(\"fake reachable2\"); //$NON-NLS-1$\n" + + " if (DEBUG && check())\n" + + " System.out.println(\"fake reachable3\"); //$NON-NLS-1$\n" + + " if (b && DEBUG)\n" + + " System.out.println(\"fake reachable4\"); //$NON-NLS-1$\n" + + " if (check() && DEBUG)\n" + + " System.out.println(\"fake reachable5\"); //$NON-NLS-1$\n" + + " if (DEBUG_LEVEL > 1) \n" + + " System.out.println(\"fake reachable6\"); //$NON-NLS-1$\n" + + " return;\n" + + " return;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " if (DEBUG && b)\n" + + " ^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " System.out.println(\"fake reachable2\"); //$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " if (DEBUG && check())\n" + + " ^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "4. WARNING in X.java (at line 11)\n" + + " System.out.println(\"fake reachable3\"); //$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "5. WARNING in X.java (at line 13)\n" + + " System.out.println(\"fake reachable4\"); //$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "6. WARNING in X.java (at line 15)\n" + + " System.out.println(\"fake reachable5\"); //$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "7. WARNING in X.java (at line 17)\n" + + " System.out.println(\"fake reachable6\"); //$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "8. ERROR in X.java (at line 19)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=265962 +public void test061() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private static final boolean isIS() {\n" + + " return System.currentTimeMillis()<0 ;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " do {\n" + + " return;\n" + + " } while(isIS() && false);\n" + + " }\n" + + "}\n", // ================= + }, + ""); + // ensure optimized boolean codegen sequence + String expectedOutput = + " public static void main(java.lang.String[] args);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: args index: 0 type: java.lang.String[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} public static Class testClass() { return FlowAnalysisTest.class; }