View | Details | Raw Unified | Return to bug 265962 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java (-1 / +4 lines)
Lines 1544-1550 Link Here
1544
}
1544
}
1545
1545
1546
public FlowInfo setReachMode(int reachMode) {
1546
public FlowInfo setReachMode(int reachMode) {
1547
	if (reachMode == REACHABLE && this != DEAD_END) { // cannot modify DEAD_END
1547
	if (this == DEAD_END) {
1548
		return this; // cannot modify DEAD_END
1549
	}
1550
	if (reachMode == REACHABLE) { 
1548
		this.tagBits &= ~UNREACHABLE;
1551
		this.tagBits &= ~UNREACHABLE;
1549
	}
1552
	}
1550
	else {
1553
	else {
(-)compiler/org/eclipse/jdt/internal/compiler/flow/FlowInfo.java (-1 / +1 lines)
Lines 58-64 Link Here
58
	}
58
	}
59
59
60
	public static FlowInfo conditional(FlowInfo initsWhenTrue, FlowInfo initsWhenFalse){
60
	public static FlowInfo conditional(FlowInfo initsWhenTrue, FlowInfo initsWhenFalse){
61
61
		if (initsWhenTrue == initsWhenFalse) return initsWhenTrue;
62
		// if (initsWhenTrue.equals(initsWhenFalse)) return initsWhenTrue; -- could optimize if #equals is defined
62
		// if (initsWhenTrue.equals(initsWhenFalse)) return initsWhenTrue; -- could optimize if #equals is defined
63
		return new ConditionalFlowInfo(initsWhenTrue, initsWhenFalse);
63
		return new ConditionalFlowInfo(initsWhenTrue, initsWhenFalse);
64
	}
64
	}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/DoStatement.java (-13 / +13 lines)
Lines 144-162 Link Here
144
	// continue label (135602)
144
	// continue label (135602)
145
	if (hasContinueLabel) {
145
	if (hasContinueLabel) {
146
		this.continueLabel.place();
146
		this.continueLabel.place();
147
	}
147
		// generate condition
148
	// generate condition
148
		Constant cst = this.condition.optimizedBooleanConstant();
149
	Constant cst = this.condition.optimizedBooleanConstant();
149
		boolean isConditionOptimizedFalse = cst != Constant.NotAConstant && cst.booleanValue() == false;		
150
	boolean isConditionOptimizedFalse = cst != Constant.NotAConstant && cst.booleanValue() == false;		
150
		if (isConditionOptimizedFalse){
151
	if (isConditionOptimizedFalse){
151
			this.condition.generateCode(currentScope, codeStream, false);
152
		this.condition.generateCode(currentScope, codeStream, false);
152
		} else {
153
	} else if (hasContinueLabel) {
153
			this.condition.generateOptimizedBoolean(
154
		this.condition.generateOptimizedBoolean(
154
				currentScope,
155
			currentScope,
155
				codeStream,
156
			codeStream,
156
				actionLabel,
157
			actionLabel,
157
				null,
158
			null,
158
				true);
159
			true);
159
		}
160
	}
160
	}
161
	// May loose some local variable initializations : affecting the local variable attributes
161
	// May loose some local variable initializations : affecting the local variable attributes
162
	if (this.mergedInitStateIndex != -1) {
162
	if (this.mergedInitStateIndex != -1) {
(-)src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java (+107 lines)
Lines 1506-1511 Link Here
1506
		}
1506
		}
1507
	);
1507
	);
1508
}
1508
}
1509
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=48399 - variation
1510
public void test060() {
1511
	runNegativeTest(
1512
		new String[] { /* test files */
1513
			"X.java",
1514
			"public class X {\n" + 
1515
			"	static final boolean DEBUG = false;\n" + 
1516
			"	static final int DEBUG_LEVEL = 0;\n" + 
1517
			"	boolean check() { return true; }\n" + 
1518
			"	void foo(boolean b) {\n" + 
1519
			"		if (DEBUG)\n" + 
1520
			"			System.out.println(\"fake reachable1\"); //$NON-NLS-1$\n" + 
1521
			"		if (DEBUG && b)\n" + 
1522
			"			System.out.println(\"fake reachable2\"); //$NON-NLS-1$\n" + 
1523
			"		if (DEBUG && check())\n" + 
1524
			"			System.out.println(\"fake reachable3\"); //$NON-NLS-1$\n" + 
1525
			"		if (b && DEBUG)\n" + 
1526
			"			System.out.println(\"fake reachable4\"); //$NON-NLS-1$\n" + 
1527
			"		if (check() && DEBUG)\n" + 
1528
			"			System.out.println(\"fake reachable5\"); //$NON-NLS-1$\n" + 
1529
			"		if (DEBUG_LEVEL > 1) \n" + 
1530
			"			System.out.println(\"fake reachable6\"); //$NON-NLS-1$\n" + 
1531
			"		return;\n" + 
1532
			"		return;\n" + 
1533
			"	}\n" + 
1534
			"}\n"
1535
		},
1536
		"----------\n" + 
1537
		"1. WARNING in X.java (at line 8)\n" + 
1538
		"	if (DEBUG && b)\n" + 
1539
		"	             ^\n" + 
1540
		"Dead code\n" + 
1541
		"----------\n" + 
1542
		"2. WARNING in X.java (at line 9)\n" + 
1543
		"	System.out.println(\"fake reachable2\"); //$NON-NLS-1$\n" + 
1544
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
1545
		"Dead code\n" + 
1546
		"----------\n" + 
1547
		"3. WARNING in X.java (at line 10)\n" + 
1548
		"	if (DEBUG && check())\n" + 
1549
		"	             ^^^^^^^\n" + 
1550
		"Dead code\n" + 
1551
		"----------\n" + 
1552
		"4. WARNING in X.java (at line 11)\n" + 
1553
		"	System.out.println(\"fake reachable3\"); //$NON-NLS-1$\n" + 
1554
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
1555
		"Dead code\n" + 
1556
		"----------\n" + 
1557
		"5. WARNING in X.java (at line 13)\n" + 
1558
		"	System.out.println(\"fake reachable4\"); //$NON-NLS-1$\n" + 
1559
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
1560
		"Dead code\n" + 
1561
		"----------\n" + 
1562
		"6. WARNING in X.java (at line 15)\n" + 
1563
		"	System.out.println(\"fake reachable5\"); //$NON-NLS-1$\n" + 
1564
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
1565
		"Dead code\n" + 
1566
		"----------\n" + 
1567
		"7. WARNING in X.java (at line 17)\n" + 
1568
		"	System.out.println(\"fake reachable6\"); //$NON-NLS-1$\n" + 
1569
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
1570
		"Dead code\n" + 
1571
		"----------\n" + 
1572
		"8. ERROR in X.java (at line 19)\n" + 
1573
		"	return;\n" + 
1574
		"	^^^^^^^\n" + 
1575
		"Unreachable code\n" + 
1576
		"----------\n");
1577
}
1578
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=265962
1579
public void test061() throws Exception {
1580
	this.runConformTest(
1581
		new String[] {
1582
			"X.java",
1583
			"public class X {\n" + 
1584
			"        private static final boolean isIS() {\n" + 
1585
			"                return System.currentTimeMillis()<0 ;\n" + 
1586
			"        }\n" + 
1587
			"        public static void main(String[] args) {\n" + 
1588
			"                do {\n" + 
1589
			"                        return;\n" + 
1590
			"                } while(isIS() && false);\n" + 
1591
			"        }\n" + 
1592
			"}\n", // =================
1593
		},
1594
		"");
1595
	// 	ensure optimized boolean codegen sequence
1596
	String expectedOutput =
1597
		"  public static void main(java.lang.String[] args);\n" + 
1598
		"    0  return\n" + 
1599
		"      Line numbers:\n" + 
1600
		"        [pc: 0, line: 7]\n" + 
1601
		"      Local variable table:\n" + 
1602
		"        [pc: 0, pc: 1] local: args index: 0 type: java.lang.String[]\n";
1603
1604
	File f = new File(OUTPUT_DIR + File.separator + "X.class");
1605
	byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
1606
	ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
1607
	String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
1608
	int index = result.indexOf(expectedOutput);
1609
	if (index == -1 || expectedOutput.length() == 0) {
1610
		System.out.println(Util.displayString(result, 3));
1611
	}
1612
	if (index == -1) {
1613
		assertEquals("Wrong contents", expectedOutput, result);
1614
	}
1615
}
1509
public static Class testClass() {
1616
public static Class testClass() {
1510
	return FlowAnalysisTest.class;
1617
	return FlowAnalysisTest.class;
1511
}
1618
}

Return to bug 265962