Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 141670 Details for
Bug 282768
[compiler] Dead code detection should ignore trivial case for ternary if operator
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix + updated regression test
patch_282768.txt (text/plain), 7.64 KB, created by
Olivier Thomann
on 2009-07-15 13:06:02 EDT
(
hide
)
Description:
Proposed fix + updated regression test
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2009-07-15 13:06:02 EDT
Size:
7.64 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java,v >retrieving revision 1.45 >diff -u -r1.45 CastTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java 24 Nov 2008 13:14:05 -0000 1.45 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java 15 Jul 2009 17:07:07 -0000 >@@ -1479,16 +1479,7 @@ > "}\n" > }, > // compiler results >- "----------\n" + >- "1. WARNING in X.java (at line 7)\n" + >- " null : new Base() {\n" + >- " public final String test() {\n" + >- " return (\"anonymous\");\n" + >- " }\n" + >- " };\n" + >- " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >- "Dead code\n" + >- "----------\n", /* expected compiler log */ >+ "", /* expected compiler log */ > // runtime results > "no base" /* expected output string */, > "" /* expected error string */, >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java,v >retrieving revision 1.45 >diff -u -r1.45 Statement.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java 7 Mar 2009 00:58:58 -0000 1.45 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java 15 Jul 2009 17:07:08 -0000 >@@ -17,6 +17,37 @@ > > public abstract class Statement extends ASTNode { > >+ /** >+ * Answers true if the if is identified as a known coding pattern which >+ * should be tolerated by dead code analysis. >+ * e.g. if (DEBUG) print(); // no complaint >+ * Only invoked when overall condition is known to be optimizeable into false. >+ */ >+ protected static boolean isKnowDeadCodePattern(Expression expression) { >+ // if (!DEBUG) print(); - tolerated >+ if (expression instanceof UnaryExpression) { >+ expression = ((UnaryExpression) expression).expression; >+ } >+ // if (DEBUG) print(); - tolerated >+ if (expression instanceof Reference) return true; >+ >+// if (expression instanceof BinaryExpression) { >+// BinaryExpression binary = (BinaryExpression) expression; >+// switch ((binary.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT/* operator */) { >+// case OperatorIds.AND_AND : >+// case OperatorIds.OR_OR : >+// break; >+// default: >+// // if (DEBUG_LEVEL > 0) print(); - tolerated >+// if ((binary.left instanceof Reference) && binary.right.constant != Constant.NotAConstant) >+// return true; >+// // if (0 < DEBUG_LEVEL) print(); - tolerated >+// if ((binary.right instanceof Reference) && binary.left.constant != Constant.NotAConstant) >+// return true; >+// } >+// } >+ return false; >+ } > public abstract FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo); > > public static final int NOT_COMPLAINED = 0; >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.64 >diff -u -r1.64 IfStatement.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java 7 Mar 2009 01:08:07 -0000 1.64 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java 15 Jul 2009 17:07:08 -0000 >@@ -205,37 +205,7 @@ > codeStream.recordPositionsFrom(pc, this.sourceStart); > } > >-/** >- * Answers true if the if is identified as a known coding pattern which >- * should be tolerated by dead code analysis. >- * e.g. if (DEBUG) print(); // no complaint >- * Only invoked when overall condition is known to be optimizeable into false. >- */ >-public static boolean isKnowDeadCodePattern(Expression expression) { >- // if (!DEBUG) print(); - tolerated >- if (expression instanceof UnaryExpression) { >- expression = ((UnaryExpression) expression).expression; >- } >- // if (DEBUG) print(); - tolerated >- if (expression instanceof Reference) return true; > >-// if (expression instanceof BinaryExpression) { >-// BinaryExpression binary = (BinaryExpression) expression; >-// switch ((binary.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT/* operator */) { >-// case OperatorIds.AND_AND : >-// case OperatorIds.OR_OR : >-// break; >-// default: >-// // if (DEBUG_LEVEL > 0) print(); - tolerated >-// if ((binary.left instanceof Reference) && binary.right.constant != Constant.NotAConstant) >-// return true; >-// // if (0 < DEBUG_LEVEL) print(); - tolerated >-// if ((binary.right instanceof Reference) && binary.left.constant != Constant.NotAConstant) >-// return true; >-// } >-// } >- return false; >-} > > public StringBuffer printStatement(int indent, StringBuffer output) { > printIndent(indent, output).append("if ("); //$NON-NLS-1$ >Index: compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java,v >retrieving revision 1.94 >diff -u -r1.94 ConditionalExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java 7 Mar 2009 01:08:07 -0000 1.94 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java 15 Jul 2009 17:07:08 -0000 >@@ -41,7 +41,8 @@ > } > > public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, >- FlowInfo flowInfo) { >+ FlowInfo flowInfo) { >+ int initialComplaintLevel = (flowInfo.reachMode() & FlowInfo.UNREACHABLE) != 0 ? Statement.COMPLAINED_FAKE_REACHABLE : Statement.NOT_COMPLAINED; > Constant cst = this.condition.optimizedBooleanConstant(); > boolean isConditionOptimizedTrue = cst != Constant.NotAConstant && cst.booleanValue() == true; > boolean isConditionOptimizedFalse = cst != Constant.NotAConstant && cst.booleanValue() == false; >@@ -53,9 +54,11 @@ > FlowInfo trueFlowInfo = flowInfo.initsWhenTrue().copy(); > if (isConditionOptimizedFalse) { > if ((mode & FlowInfo.UNREACHABLE) == 0) { >- currentScope.problemReporter().fakeReachable(this.valueIfTrue); > trueFlowInfo.setReachMode(FlowInfo.UNREACHABLE); > } >+ if (!isKnowDeadCodePattern(this.condition) || currentScope.compilerOptions().reportDeadCodeInTrivialIfStatement) { >+ this.valueIfTrue.complainIfUnreachable(trueFlowInfo, currentScope, initialComplaintLevel); >+ } > } > this.trueInitStateIndex = currentScope.methodScope().recordInitializationStates(trueFlowInfo); > trueFlowInfo = this.valueIfTrue.analyseCode(currentScope, flowContext, trueFlowInfo); >@@ -64,9 +67,11 @@ > FlowInfo falseFlowInfo = flowInfo.initsWhenFalse().copy(); > if (isConditionOptimizedTrue) { > if ((mode & FlowInfo.UNREACHABLE) == 0) { >- currentScope.problemReporter().fakeReachable(this.valueIfFalse); > falseFlowInfo.setReachMode(FlowInfo.UNREACHABLE); > } >+ if (!isKnowDeadCodePattern(this.condition) || currentScope.compilerOptions().reportDeadCodeInTrivialIfStatement) { >+ this.valueIfFalse.complainIfUnreachable(falseFlowInfo, currentScope, initialComplaintLevel); >+ } > } > this.falseInitStateIndex = currentScope.methodScope().recordInitializationStates(falseFlowInfo); > falseFlowInfo = this.valueIfFalse.analyseCode(currentScope, flowContext, falseFlowInfo);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 282768
:
141659
| 141670