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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java (-1 / +1 lines)
Lines 38-44 Link Here
38
38
39
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
39
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
40
	// record variable initialization if any
40
	// record variable initialization if any
41
	if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0) {
41
	if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) {
42
		this.bits |= ASTNode.IsLocalDeclarationReachable; // only set if actually reached
42
		this.bits |= ASTNode.IsLocalDeclarationReachable; // only set if actually reached
43
	}
43
	}
44
	if (this.binding != null && this.type.resolvedType instanceof TypeVariableBinding) {
44
	if (this.binding != null && this.type.resolvedType instanceof TypeVariableBinding) {
(-)compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java (-2 / +2 lines)
Lines 159-165 Link Here
159
						catchInfo);
159
						catchInfo);
160
				this.catchExitInitStateIndexes[i] = currentScope.methodScope().recordInitializationStates(catchInfo);
160
				this.catchExitInitStateIndexes[i] = currentScope.methodScope().recordInitializationStates(catchInfo);
161
				this.catchExits[i] =
161
				this.catchExits[i] =
162
					(catchInfo.tagBits & FlowInfo.UNREACHABLE) != 0;
162
					(catchInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) != 0;
163
				tryInfo = tryInfo.mergedWith(catchInfo.unconditionalInits());
163
				tryInfo = tryInfo.mergedWith(catchInfo.unconditionalInits());
164
			}
164
			}
165
		}
165
		}
Lines 268-274 Link Here
268
						catchInfo);
268
						catchInfo);
269
				this.catchExitInitStateIndexes[i] = currentScope.methodScope().recordInitializationStates(catchInfo);
269
				this.catchExitInitStateIndexes[i] = currentScope.methodScope().recordInitializationStates(catchInfo);
270
				this.catchExits[i] =
270
				this.catchExits[i] =
271
					(catchInfo.tagBits & FlowInfo.UNREACHABLE) != 0;
271
					(catchInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) != 0;
272
				tryInfo = tryInfo.mergedWith(catchInfo.unconditionalInits());
272
				tryInfo = tryInfo.mergedWith(catchInfo.unconditionalInits());
273
			}
273
			}
274
		}
274
		}
(-)compiler/org/eclipse/jdt/internal/compiler/flow/ExceptionHandlingFlowContext.java (-3 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 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 227-234 Link Here
227
}
227
}
228
228
229
public void recordReturnFrom(UnconditionalFlowInfo flowInfo) {
229
public void recordReturnFrom(UnconditionalFlowInfo flowInfo) {
230
	if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0) {
230
	if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) {
231
		if ((this.initsOnReturn.tagBits & FlowInfo.UNREACHABLE) == 0) {
231
		if ((this.initsOnReturn.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) {
232
			this.initsOnReturn = this.initsOnReturn.mergedWith(flowInfo);
232
			this.initsOnReturn = this.initsOnReturn.mergedWith(flowInfo);
233
		}
233
		}
234
		else {
234
		else {
(-)compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java (-1 / +1 lines)
Lines 530-536 Link Here
530
}
530
}
531
531
532
public void recordSettingFinal(VariableBinding variable, Reference finalReference, FlowInfo flowInfo) {
532
public void recordSettingFinal(VariableBinding variable, Reference finalReference, FlowInfo flowInfo) {
533
	if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0)	{
533
	if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0)	{
534
	// for initialization inside looping statement that effectively loops
534
	// for initialization inside looping statement that effectively loops
535
	FlowContext context = this;
535
	FlowContext context = this;
536
	while (context != null) {
536
	while (context != null) {
(-)compiler/org/eclipse/jdt/internal/compiler/flow/InsideSubRoutineFlowContext.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 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 43-49 Link Here
43
}
43
}
44
44
45
public void recordReturnFrom(UnconditionalFlowInfo flowInfo) {
45
public void recordReturnFrom(UnconditionalFlowInfo flowInfo) {
46
	if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0)	{
46
	if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0)	{
47
	if (this.initsOnReturn == FlowInfo.DEAD_END) {
47
	if (this.initsOnReturn == FlowInfo.DEAD_END) {
48
		this.initsOnReturn = (UnconditionalFlowInfo) flowInfo.copy();
48
		this.initsOnReturn = (UnconditionalFlowInfo) flowInfo.copy();
49
	} else {
49
	} else {
(-)compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java (-2 / +2 lines)
Lines 385-392 Link Here
385
}
385
}
386
386
387
public void recordContinueFrom(FlowContext innerFlowContext, FlowInfo flowInfo) {
387
public void recordContinueFrom(FlowContext innerFlowContext, FlowInfo flowInfo) {
388
	if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0)	{
388
	if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0)	{
389
		if ((this.initsOnContinue.tagBits & FlowInfo.UNREACHABLE) == 0) {
389
		if ((this.initsOnContinue.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) {
390
			this.initsOnContinue = this.initsOnContinue.
390
			this.initsOnContinue = this.initsOnContinue.
391
					mergedWith(flowInfo.unconditionalInitsWithoutSideEffect());
391
					mergedWith(flowInfo.unconditionalInitsWithoutSideEffect());
392
		}
392
		}
(-)compiler/org/eclipse/jdt/internal/compiler/flow/SwitchFlowContext.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 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 42-48 Link Here
42
}
42
}
43
43
44
public void recordBreakFrom(FlowInfo flowInfo) {
44
public void recordBreakFrom(FlowInfo flowInfo) {
45
	if ((this.initsOnBreak.tagBits & FlowInfo.UNREACHABLE) == 0) {
45
	if ((this.initsOnBreak.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) {
46
		this.initsOnBreak = this.initsOnBreak.mergedWith(flowInfo.unconditionalInits());
46
		this.initsOnBreak = this.initsOnBreak.mergedWith(flowInfo.unconditionalInits());
47
	}
47
	}
48
	else {
48
	else {
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java (-2 / +2 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 409-415 Link Here
409
}
409
}
410
410
411
public final int recordInitializationStates(FlowInfo flowInfo) {
411
public final int recordInitializationStates(FlowInfo flowInfo) {
412
	if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) != 0) return -1;
412
	if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) != 0) return -1;
413
	UnconditionalFlowInfo unconditionalFlowInfo = flowInfo.unconditionalInitsWithoutSideEffect();
413
	UnconditionalFlowInfo unconditionalFlowInfo = flowInfo.unconditionalInitsWithoutSideEffect();
414
	long[] extraInits = unconditionalFlowInfo.extra == null ?
414
	long[] extraInits = unconditionalFlowInfo.extra == null ?
415
			null : unconditionalFlowInfo.extra[0];
415
			null : unconditionalFlowInfo.extra[0];
(-)Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/ConformTest.java (-7 / +45 lines)
Lines 6688-6702 Link Here
6688
			"        [pc: 0, pc: 96] local: delete index: 1 type: boolean\n" + 
6688
			"        [pc: 0, pc: 96] local: delete index: 1 type: boolean\n" + 
6689
			"        [pc: 5, pc: 96] local: s index: 2 type: java.lang.String\n" + 
6689
			"        [pc: 5, pc: 96] local: s index: 2 type: java.lang.String\n" + 
6690
			"        [pc: 13, pc: 96] local: buffer index: 3 type: java.lang.StringBuffer\n" + 
6690
			"        [pc: 13, pc: 96] local: buffer index: 3 type: java.lang.StringBuffer\n" + 
6691
			"        [pc: 24, pc: 59] local: datas index: 4 type: java.lang.String[]\n" + 
6691
			"        [pc: 24, pc: 79] local: datas index: 4 type: java.lang.String[]\n" + 
6692
			"        [pc: 62, pc: 79] local: datas index: 4 type: java.lang.String[]\n" + 
6692
			"        [pc: 34, pc: 79] local: data index: 5 type: java.lang.Object[]\n" + 
6693
			"        [pc: 34, pc: 59] local: data index: 5 type: java.lang.Object[]\n" + 
6693
			"        [pc: 51, pc: 62] local: e index: 6 type: java.lang.Exception\n" + 
6694
			"        [pc: 62, pc: 79] local: data index: 5 type: java.lang.Object[]\n" + 
6695
			"        [pc: 51, pc: 59] local: e index: 6 type: java.lang.Exception\n" + 
6696
			"      Stack map table: number of frames 8\n" + 
6694
			"      Stack map table: number of frames 8\n" + 
6697
			"        [pc: 49, full, stack: {java.lang.Exception}, locals: {X, int, java.lang.String, java.lang.StringBuffer, java.lang.String[], java.lang.Object[]}]\n" + 
6695
			"        [pc: 49, full, stack: {java.lang.Exception}, locals: {X, int, java.lang.String, java.lang.StringBuffer, java.lang.String[], java.lang.Object[]}]\n" + 
6698
			"        [pc: 59, chop 2 local(s)]\n" + 
6696
			"        [pc: 59, append: {java.lang.Exception}]\n" + 
6699
			"        [pc: 62, append: {java.lang.String[], java.lang.Object[]}]\n" + 
6697
			"        [pc: 62, chop 1 local(s)]\n" + 
6700
			"        [pc: 76, same]\n" + 
6698
			"        [pc: 76, same]\n" + 
6701
			"        [pc: 79, full, stack: {java.lang.Exception}, locals: {X, int, java.lang.String, java.lang.StringBuffer}]\n" + 
6699
			"        [pc: 79, full, stack: {java.lang.Exception}, locals: {X, int, java.lang.String, java.lang.StringBuffer}]\n" + 
6702
			"        [pc: 86, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + 
6700
			"        [pc: 86, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + 
Lines 7569-7574 Link Here
7569
	}
7567
	}
7570
}
7568
}
7571
7569
7570
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448
7571
//To check that code gen is not optimized for an if statement
7572
//where a local variable's definite nullness or otherwise is known because of
7573
//an earlier assert expression (inside finally context)
7574
public void testBug339139() throws Exception {
7575
	this.runConformTest(
7576
		new String[] {
7577
			"X.java",
7578
			"public abstract class X {\n" +
7579
			"	 private static Object[] bar() {\n" +
7580
			"		return null;\n" +
7581
			"	}\n" +
7582
			"	protected final Object foo() {\n" +
7583
			"		Object[] tab = null;\n" +
7584
			"		if(tab != null) {\n" +
7585
			"			Object[] v = bar(); \n" +
7586
			"			int length = tab.length;\n" +
7587
			"			loop : for (int i = 0, max = v.length; i < max; i++) {\n" +
7588
			"				Object o = v[i];\n" +
7589
			"				if (o == null)  continue loop;\n" +
7590
			"				if(0 == length) {\n" +
7591
			"					loop2 : for (int j = 0; j < length; j++) {\n" +
7592
			"						Object o2 = null;\n" +
7593
			"						for (int k = 0; k < length; k++) {\n" +
7594
			"							if (o2 == tab[k]) {\n" +
7595
			"								continue loop2;\n" +
7596
			"							}\n" +
7597
			"						}\n" +
7598
			"						continue loop;\n" +
7599
			"					}\n" +
7600
			"					return o;\n" +
7601
			"				}\n" +
7602
			"			}\n" +
7603
			"		}\n" +
7604
			"		return null;\n" +
7605
			"	}\n" +
7606
			"}\n",
7607
		}); // custom requestor
7608
}
7609
7572
public static Class testClass() {
7610
public static Class testClass() {
7573
	return ConformTest.class;
7611
	return ConformTest.class;
7574
}
7612
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java (-1 / +39 lines)
Lines 36-42 Link Here
36
  	// Only the highest compliance level is run; add the VM argument
36
  	// Only the highest compliance level is run; add the VM argument
37
  	// -Dcompliance=1.4 (for example) to lower it if needed
37
  	// -Dcompliance=1.4 (for example) to lower it if needed
38
  	static {
38
  	static {
39
//    	TESTS_NAMES = new String[] { "test0055" };
39
    	TESTS_NAMES = new String[] { "test0059" };
40
//		TESTS_NUMBERS = new int[] { 56 };
40
//		TESTS_NUMBERS = new int[] { 56 };
41
//  	TESTS_RANGE = new int[] { 1, -1 };
41
//  	TESTS_RANGE = new int[] { 1, -1 };
42
  	}
42
  	}
Lines 2309-2312 Link Here
2309
			true/*shouldFlushOutputDirectory*/,
2309
			true/*shouldFlushOutputDirectory*/,
2310
			customOptions);
2310
			customOptions);
2311
}
2311
}
2312
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=339139
2313
// Issue local variable not used warning inside deadcode
2314
public void test0059() throws Exception {
2315
	Map customOptions = getCompilerOptions();
2316
	customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING);
2317
	customOptions.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.WARNING);
2318
	this.runNegativeTest(
2319
		new String[] {
2320
			"X.java",
2321
			"public class X {\n" + 
2322
			"    public static void main(String[] args) {\n" + 
2323
			"    	Object a = null;\n" + 
2324
			"    	if (a != null){\n" + 
2325
			"        	int j = 3;\n" + 
2326
			"        	j++;\n" + 	// value is not used
2327
			"    	}\n" +
2328
			"    	System.out.println(\"OK\");\n" + 
2329
			"    }\n" + 
2330
			"}"
2331
		},
2332
		"----------\n" + 
2333
		"1. WARNING in X.java (at line 4)\n" + 
2334
		"	if (a != null){\n" + 
2335
		"        	int j = 3;\n" + 
2336
		"        	j++;\n" + 
2337
		"    	}\n" + 
2338
		"	              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
2339
		"Dead code\n" + 
2340
		"----------\n" + 
2341
		"2. WARNING in X.java (at line 5)\n" + 
2342
		"	int j = 3;\n" + 
2343
		"	    ^\n" + 
2344
		"The value of the local variable j is not used\n" + 
2345
		"----------\n",
2346
		null/*classLibraries*/,
2347
		true/*shouldFlushOutputDirectory*/,
2348
		customOptions);
2349
}
2312
}
2350
}

Return to bug 339139