### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java,v retrieving revision 1.69 diff -u -r1.69 IfStatement.java --- compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java 12 Aug 2010 16:58:28 -0000 1.69 +++ compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java 25 Feb 2011 15:07:58 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -89,7 +89,13 @@ this.thenInitStateIndex = currentScope.methodScope().recordInitializationStates(thenFlowInfo); if (isConditionOptimizedFalse || ((this.bits & ASTNode.IsThenStatementUnreachable) != 0)) { if (!isKnowDeadCodePattern(this.condition) || currentScope.compilerOptions().reportDeadCodeInTrivialIfStatement) { - this.thenStatement.complainIfUnreachable(thenFlowInfo, currentScope, initialComplaintLevel); + int complained = this.thenStatement.complainIfUnreachable(thenFlowInfo, currentScope, initialComplaintLevel); + if (complained == COMPLAINED_FAKE_REACHABLE && + ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0)) { + // The If-Else construct is reachable but the then branch is dead code. + // So don't optimize it away during code gen. + this.thenStatement.bits |= ASTNode.IsReachable; + } } else { // its a known coding pattern which should be tolerated by dead code analysis // according to isKnowDeadCodePattern() @@ -115,7 +121,13 @@ this.elseInitStateIndex = currentScope.methodScope().recordInitializationStates(elseFlowInfo); if (isConditionOptimizedTrue || ((this.bits & ASTNode.IsElseStatementUnreachable) != 0)) { if (!isKnowDeadCodePattern(this.condition) || currentScope.compilerOptions().reportDeadCodeInTrivialIfStatement) { - this.elseStatement.complainIfUnreachable(elseFlowInfo, currentScope, initialComplaintLevel); + int complained = this.elseStatement.complainIfUnreachable(elseFlowInfo, currentScope, initialComplaintLevel); + if (complained == COMPLAINED_FAKE_REACHABLE && + ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0)) { + // The If-Else construct is reachable but the else branch is dead code. + // So don't optimize it away during code gen. + this.elseStatement.bits |= ASTNode.IsReachable; + } } else { // its a known coding pattern which should be tolerated by dead code analysis // according to isKnowDeadCodePattern() @@ -164,10 +176,7 @@ if (hasThenPart) { BranchLabel falseLabel = null; // generate boolean condition only if needed - if (((this.bits & ASTNode.IsElseStatementUnreachable) != 0) || - (cst != Constant.NotAConstant && cst.booleanValue() == true)) { - // No need to generate if condition statement when we know that only the then action - // will be executed + if (cst != Constant.NotAConstant && cst.booleanValue() == true) { this.condition.generateCode(currentScope, codeStream, false); } else { this.condition.generateOptimizedBoolean( @@ -206,10 +215,7 @@ } } else if (hasElsePart) { // generate boolean condition only if needed - if (((this.bits & ASTNode.IsThenStatementUnreachable) != 0) || - (cst != Constant.NotAConstant && cst.booleanValue() == false)) { - // No need to generate if condition statement when we know that only the else action - // will be executed + if (cst != Constant.NotAConstant && cst.booleanValue() == false) { this.condition.generateCode(currentScope, codeStream, false); } else { this.condition.generateOptimizedBoolean(