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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java (-11 / +17 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 89-95 Link Here
89
		this.thenInitStateIndex = currentScope.methodScope().recordInitializationStates(thenFlowInfo);
89
		this.thenInitStateIndex = currentScope.methodScope().recordInitializationStates(thenFlowInfo);
90
		if (isConditionOptimizedFalse || ((this.bits & ASTNode.IsThenStatementUnreachable) != 0)) {
90
		if (isConditionOptimizedFalse || ((this.bits & ASTNode.IsThenStatementUnreachable) != 0)) {
91
			if (!isKnowDeadCodePattern(this.condition) || currentScope.compilerOptions().reportDeadCodeInTrivialIfStatement) {
91
			if (!isKnowDeadCodePattern(this.condition) || currentScope.compilerOptions().reportDeadCodeInTrivialIfStatement) {
92
				this.thenStatement.complainIfUnreachable(thenFlowInfo, currentScope, initialComplaintLevel);
92
				int complained = this.thenStatement.complainIfUnreachable(thenFlowInfo, currentScope, initialComplaintLevel);
93
				if (complained == COMPLAINED_FAKE_REACHABLE &&
94
						((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0)) {
95
					// The If-Else construct is reachable but the then branch is dead code.
96
					// So don't optimize it away during code gen.
97
					this.thenStatement.bits |= ASTNode.IsReachable;
98
				}
93
			} else {
99
			} else {
94
				// its a known coding pattern which should be tolerated by dead code analysis
100
				// its a known coding pattern which should be tolerated by dead code analysis
95
				// according to isKnowDeadCodePattern()
101
				// according to isKnowDeadCodePattern()
Lines 115-121 Link Here
115
		this.elseInitStateIndex = currentScope.methodScope().recordInitializationStates(elseFlowInfo);
121
		this.elseInitStateIndex = currentScope.methodScope().recordInitializationStates(elseFlowInfo);
116
		if (isConditionOptimizedTrue || ((this.bits & ASTNode.IsElseStatementUnreachable) != 0)) {
122
		if (isConditionOptimizedTrue || ((this.bits & ASTNode.IsElseStatementUnreachable) != 0)) {
117
			if (!isKnowDeadCodePattern(this.condition) || currentScope.compilerOptions().reportDeadCodeInTrivialIfStatement) {
123
			if (!isKnowDeadCodePattern(this.condition) || currentScope.compilerOptions().reportDeadCodeInTrivialIfStatement) {
118
				this.elseStatement.complainIfUnreachable(elseFlowInfo, currentScope, initialComplaintLevel);
124
				int complained = this.elseStatement.complainIfUnreachable(elseFlowInfo, currentScope, initialComplaintLevel);
125
				if (complained == COMPLAINED_FAKE_REACHABLE &&
126
						((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0)) {
127
					// The If-Else construct is reachable but the else branch is dead code.
128
					// So don't optimize it away during code gen.
129
					this.elseStatement.bits |= ASTNode.IsReachable;
130
				}
119
			} else {
131
			} else {
120
				// its a known coding pattern which should be tolerated by dead code analysis
132
				// its a known coding pattern which should be tolerated by dead code analysis
121
				// according to isKnowDeadCodePattern()
133
				// according to isKnowDeadCodePattern()
Lines 164-173 Link Here
164
	if (hasThenPart) {
176
	if (hasThenPart) {
165
		BranchLabel falseLabel = null;
177
		BranchLabel falseLabel = null;
166
		// generate boolean condition only if needed
178
		// generate boolean condition only if needed
167
		if (((this.bits & ASTNode.IsElseStatementUnreachable) != 0) ||
179
		if (cst != Constant.NotAConstant && cst.booleanValue() == true) {
168
				(cst != Constant.NotAConstant && cst.booleanValue() == true)) {
169
			// No need to generate if condition statement when we know that only the then action
170
			// will be executed
171
			this.condition.generateCode(currentScope, codeStream, false);
180
			this.condition.generateCode(currentScope, codeStream, false);
172
		} else {
181
		} else {
173
			this.condition.generateOptimizedBoolean(
182
			this.condition.generateOptimizedBoolean(
Lines 206-215 Link Here
206
		}
215
		}
207
	} else if (hasElsePart) {
216
	} else if (hasElsePart) {
208
		// generate boolean condition only if needed
217
		// generate boolean condition only if needed
209
		if (((this.bits & ASTNode.IsThenStatementUnreachable) != 0) ||
218
		if (cst != Constant.NotAConstant && cst.booleanValue() == false) {
210
				(cst != Constant.NotAConstant && cst.booleanValue() == false)) {
211
			// No need to generate if condition statement when we know that only the else action
212
			// will be executed
213
			this.condition.generateCode(currentScope, codeStream, false);
219
			this.condition.generateCode(currentScope, codeStream, false);
214
		} else {
220
		} else {
215
			this.condition.generateOptimizedBoolean(
221
			this.condition.generateOptimizedBoolean(

Return to bug 326950