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 44913 Details for
Bug 147024
[compiler] Compiler bug when accessing static final attribute in a non-static way
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch
143684.txt (text/plain), 15.79 KB, created by
Philipe Mulet
on 2006-06-20 09:03:20 EDT
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Philipe Mulet
Created:
2006-06-20 09:03:20 EDT
Size:
15.79 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/BooleanTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BooleanTest.java,v >retrieving revision 1.9 >diff -u -r1.9 BooleanTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/BooleanTest.java 29 Mar 2006 03:50:22 -0000 1.9 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/BooleanTest.java 20 Jun 2006 13:03:49 -0000 >@@ -1570,6 +1570,321 @@ > assertTrue(false); > } > } >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=143684 >+public void test037() { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ " public class X {\n" + >+ " public static final boolean T = true;\n" + >+ " public static final boolean F = false;\n" + >+ " \n" + >+ " public boolean getFlagBT() {\n" + >+ " boolean b = this.T;\n" + >+ " if (this.T)\n" + >+ " return true;\n" + >+ " else\n" + >+ " return false;\n" + >+ " }\n" + >+ "\n" + >+ " public int getFlagIT() {\n" + >+ " boolean b = this.T;\n" + >+ " if (this.T)\n" + >+ " return 0;\n" + >+ " else\n" + >+ " return 1;\n" + >+ " }\n" + >+ "\n" + >+ " public boolean getFlagBF() {\n" + >+ " boolean b = this.F;\n" + >+ " if (this.F)\n" + >+ " return true;\n" + >+ " else\n" + >+ " return false;\n" + >+ " }\n" + >+ "\n" + >+ " public int getFlagIF() {\n" + >+ " boolean b = this.F;\n" + >+ " if (this.F)\n" + >+ " return 0;\n" + >+ " else\n" + >+ " return 1;\n" + >+ " }\n" + >+ " public boolean getFlagBT2() {\n" + >+ " boolean b = T;\n" + >+ " if (T)\n" + >+ " return true;\n" + >+ " else\n" + >+ " return false;\n" + >+ " }\n" + >+ "\n" + >+ " public int getFlagIT2() {\n" + >+ " boolean b = T;\n" + >+ " if (T)\n" + >+ " return 0;\n" + >+ " else\n" + >+ " return 1;\n" + >+ " }\n" + >+ "\n" + >+ " public boolean getFlagBF2() {\n" + >+ " boolean b = F;\n" + >+ " if (F)\n" + >+ " return true;\n" + >+ " else\n" + >+ " return false;\n" + >+ " }\n" + >+ "\n" + >+ " public int getFlagIF2() {\n" + >+ " boolean b = F;\n" + >+ " if (F)\n" + >+ " return 0;\n" + >+ " else\n" + >+ " return 1;\n" + >+ " }\n" + >+ " public boolean getFlagBT3() {\n" + >+ " X self = this;\n" + >+ " boolean b = self.T;\n" + >+ " if (self.T)\n" + >+ " return true;\n" + >+ " else\n" + >+ " return false;\n" + >+ " }\n" + >+ "\n" + >+ " public int getFlagIT3() {\n" + >+ " X self = this;\n" + >+ " boolean b = self.T;\n" + >+ " if (self.T)\n" + >+ " return 0;\n" + >+ " else\n" + >+ " return 1;\n" + >+ " }\n" + >+ "\n" + >+ " public boolean getFlagBF3() {\n" + >+ " X self = this;\n" + >+ " boolean b = self.F;\n" + >+ " if (self.F)\n" + >+ " return true;\n" + >+ " else\n" + >+ " return false;\n" + >+ " }\n" + >+ " public int getFlagIF3() {\n" + >+ " X self = this;\n" + >+ " boolean b = self.F;\n" + >+ " if (self.F)\n" + >+ " return 0;\n" + >+ " else\n" + >+ " return 1;\n" + >+ " }\n" + >+ " public static void main(String[] args) {\n" + >+ " System.out.println(\"It worked.\");\n" + >+ " }\n" + >+ "}", // ================= >+ }, >+ "It worked."); >+ // ensure optimized boolean codegen sequence >+ String expectedOutput = >+ " // Method descriptor #21 ()Z\n" + >+ " // Stack: 1, Locals: 2\n" + >+ " public boolean getFlagBT();\n" + >+ " 0 iconst_1\n" + >+ " 1 istore_1 [b]\n" + >+ " 2 iconst_1\n" + >+ " 3 ireturn\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 6]\n" + >+ " [pc: 2, line: 8]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 4] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + >+ " \n" + >+ " // Method descriptor #24 ()I\n" + >+ " // Stack: 1, Locals: 2\n" + >+ " public int getFlagIT();\n" + >+ " 0 iconst_1\n" + >+ " 1 istore_1 [b]\n" + >+ " 2 iconst_0\n" + >+ " 3 ireturn\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 14]\n" + >+ " [pc: 2, line: 16]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 4] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + >+ " \n" + >+ " // Method descriptor #21 ()Z\n" + >+ " // Stack: 1, Locals: 2\n" + >+ " public boolean getFlagBF();\n" + >+ " 0 iconst_0\n" + >+ " 1 istore_1 [b]\n" + >+ " 2 iconst_0\n" + >+ " 3 ireturn\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 22]\n" + >+ " [pc: 2, line: 26]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 4] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + >+ " \n" + >+ " // Method descriptor #24 ()I\n" + >+ " // Stack: 1, Locals: 2\n" + >+ " public int getFlagIF();\n" + >+ " 0 iconst_0\n" + >+ " 1 istore_1 [b]\n" + >+ " 2 iconst_1\n" + >+ " 3 ireturn\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 30]\n" + >+ " [pc: 2, line: 34]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 4] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + >+ " \n" + >+ " // Method descriptor #21 ()Z\n" + >+ " // Stack: 1, Locals: 2\n" + >+ " public boolean getFlagBT2();\n" + >+ " 0 iconst_1\n" + >+ " 1 istore_1 [b]\n" + >+ " 2 iconst_1\n" + >+ " 3 ireturn\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 37]\n" + >+ " [pc: 2, line: 39]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 4] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + >+ " \n" + >+ " // Method descriptor #24 ()I\n" + >+ " // Stack: 1, Locals: 2\n" + >+ " public int getFlagIT2();\n" + >+ " 0 iconst_1\n" + >+ " 1 istore_1 [b]\n" + >+ " 2 iconst_0\n" + >+ " 3 ireturn\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 45]\n" + >+ " [pc: 2, line: 47]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 4] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + >+ " \n" + >+ " // Method descriptor #21 ()Z\n" + >+ " // Stack: 1, Locals: 2\n" + >+ " public boolean getFlagBF2();\n" + >+ " 0 iconst_0\n" + >+ " 1 istore_1 [b]\n" + >+ " 2 iconst_0\n" + >+ " 3 ireturn\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 53]\n" + >+ " [pc: 2, line: 57]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 4] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + >+ " \n" + >+ " // Method descriptor #24 ()I\n" + >+ " // Stack: 1, Locals: 2\n" + >+ " public int getFlagIF2();\n" + >+ " 0 iconst_0\n" + >+ " 1 istore_1 [b]\n" + >+ " 2 iconst_1\n" + >+ " 3 ireturn\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 61]\n" + >+ " [pc: 2, line: 65]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 4] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + >+ " \n" + >+ " // Method descriptor #21 ()Z\n" + >+ " // Stack: 1, Locals: 3\n" + >+ " public boolean getFlagBT3();\n" + >+ " 0 aload_0 [this]\n" + >+ " 1 astore_1 [self]\n" + >+ " 2 iconst_1\n" + >+ " 3 istore_2 [b]\n" + >+ " 4 iconst_1\n" + >+ " 5 ireturn\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 68]\n" + >+ " [pc: 2, line: 69]\n" + >+ " [pc: 4, line: 71]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 6] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 6] local: self index: 1 type: X\n" + >+ " [pc: 4, pc: 6] local: b index: 2 type: boolean\n" + >+ " \n" + >+ " // Method descriptor #24 ()I\n" + >+ " // Stack: 1, Locals: 3\n" + >+ " public int getFlagIT3();\n" + >+ " 0 aload_0 [this]\n" + >+ " 1 astore_1 [self]\n" + >+ " 2 iconst_1\n" + >+ " 3 istore_2 [b]\n" + >+ " 4 iconst_0\n" + >+ " 5 ireturn\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 77]\n" + >+ " [pc: 2, line: 78]\n" + >+ " [pc: 4, line: 80]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 6] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 6] local: self index: 1 type: X\n" + >+ " [pc: 4, pc: 6] local: b index: 2 type: boolean\n" + >+ " \n" + >+ " // Method descriptor #21 ()Z\n" + >+ " // Stack: 1, Locals: 3\n" + >+ " public boolean getFlagBF3();\n" + >+ " 0 aload_0 [this]\n" + >+ " 1 astore_1 [self]\n" + >+ " 2 iconst_0\n" + >+ " 3 istore_2 [b]\n" + >+ " 4 iconst_0\n" + >+ " 5 ireturn\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 86]\n" + >+ " [pc: 2, line: 87]\n" + >+ " [pc: 4, line: 91]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 6] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 6] local: self index: 1 type: X\n" + >+ " [pc: 4, pc: 6] local: b index: 2 type: boolean\n" + >+ " \n" + >+ " // Method descriptor #24 ()I\n" + >+ " // Stack: 1, Locals: 3\n" + >+ " public int getFlagIF3();\n" + >+ " 0 aload_0 [this]\n" + >+ " 1 astore_1 [self]\n" + >+ " 2 iconst_0\n" + >+ " 3 istore_2 [b]\n" + >+ " 4 iconst_1\n" + >+ " 5 ireturn\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 94]\n" + >+ " [pc: 2, line: 95]\n" + >+ " [pc: 4, line: 99]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 6] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 6] local: self index: 1 type: X\n" + >+ " [pc: 4, pc: 6] local: b index: 2 type: boolean\n"; >+ >+ try { >+ File f = new File(OUTPUT_DIR + File.separator + "X.class"); >+ byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); >+ ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); >+ String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); >+ int index = result.indexOf(expectedOutput); >+ if (index == -1 || expectedOutput.length() == 0) { >+ System.out.println(Util.displayString(result, 3)); >+ } >+ if (index == -1) { >+ assertEquals("Wrong contents", expectedOutput, result); >+ } >+ } catch (org.eclipse.jdt.core.util.ClassFormatException e) { >+ assertTrue(false); >+ } catch (IOException e) { >+ assertTrue(false); >+ } >+} > > public static Class testClass() { > return BooleanTest.class; >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java,v >retrieving revision 1.103 >diff -u -r1.103 Expression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java 20 Jun 2006 11:47:39 -0000 1.103 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java 20 Jun 2006 13:03:51 -0000 >@@ -621,9 +621,11 @@ > // a label valued to nil means: by default we fall through the case... > // both nil means we leave the value on the stack > >- if ((constant != Constant.NotAConstant) && (constant.typeID() == T_boolean)) { >+ Constant cst = this.optimizedBooleanConstant(); >+ generateCode(currentScope, codeStream, valueRequired && cst == Constant.NotAConstant); >+ if ((cst != Constant.NotAConstant) && (cst.typeID() == T_boolean)) { > int pc = codeStream.position; >- if (constant.booleanValue() == true) { >+ if (cst.booleanValue() == true) { > // constant == true > if (valueRequired) { > if (falseLabel == null) { >@@ -646,7 +648,6 @@ > codeStream.recordPositionsFrom(pc, this.sourceStart); > return; > } >- generateCode(currentScope, codeStream, valueRequired); > // branching > int position = codeStream.position; > if (valueRequired) { >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.56 >diff -u -r1.56 IfStatement.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java 28 Mar 2006 20:29:56 -0000 1.56 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java 20 Jun 2006 13:03:51 -0000 >@@ -142,7 +142,6 @@ > !((cst != Constant.NotAConstant && cst.booleanValue() == true) > || this.elseStatement == null > || this.elseStatement.isEmptyBlock()); >- > if (hasThenPart) { > BranchLabel falseLabel = null; > // generate boolean condition >@@ -151,7 +150,7 @@ > codeStream, > null, > hasElsePart ? (falseLabel = new BranchLabel(codeStream)) : endifLabel, >- true); >+ true/*cst == Constant.NotAConstant*/); > // May loose some local variable initializations : affecting the local variable attributes > if (thenInitStateIndex != -1) { > codeStream.removeNotDefinitelyAssignedVariables(currentScope, thenInitStateIndex); >@@ -186,7 +185,7 @@ > codeStream, > endifLabel, > null, >- true); >+ true/*cst == Constant.NotAConstant*/); > // generate else statement > // May loose some local variable initializations : affecting the local variable attributes > if (elseInitStateIndex != -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.83 >diff -u -r1.83 ConditionalExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java 15 Jun 2006 10:33:04 -0000 1.83 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java 20 Jun 2006 13:03:50 -0000 >@@ -121,18 +121,12 @@ > codeStream.recordPositionsFrom(pc, this.sourceStart); > return; > } >- Constant cst = condition.constant; >- Constant condCst = condition.optimizedBooleanConstant(); >- boolean needTruePart = >- !(((cst != Constant.NotAConstant) && (cst.booleanValue() == false)) >- || ((condCst != Constant.NotAConstant) && (condCst.booleanValue() == false))); >- boolean needFalsePart = >- !(((cst != Constant.NotAConstant) && (cst.booleanValue() == true)) >- || ((condCst != Constant.NotAConstant) && (condCst.booleanValue() == true))); >+ Constant cst = condition.optimizedBooleanConstant(); >+ boolean needTruePart = !(cst != Constant.NotAConstant && cst.booleanValue() == false); >+ boolean needFalsePart = !(cst != Constant.NotAConstant && cst.booleanValue() == true); > endifLabel = new BranchLabel(codeStream); > > // Generate code for the condition >- boolean needConditionValue = (cst == Constant.NotAConstant) && (condCst == Constant.NotAConstant); > falseLabel = new BranchLabel(codeStream); > falseLabel.tagBits |= BranchLabel.USED; > condition.generateOptimizedBoolean( >@@ -140,7 +134,7 @@ > codeStream, > null, > falseLabel, >- needConditionValue); >+ cst == Constant.NotAConstant); > > if (trueInitStateIndex != -1) { > codeStream.removeNotDefinitelyAssignedVariables(
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 147024
: 44913