-
Enhancement
-
Resolution: Won't Fix
-
P5
-
None
-
1.1.3
-
sparc
-
solaris_2.5.1
In the following program, the subexpression "i < 0" is side-effect-free and
appears in a context in which its value is not required.
public class Bug {
public static void main(String args[]) {
int i = 1;
boolean b = i < 0 || true;
}
}
When compiled with javac (1.1.3), the following code results:
public class Bug {
// Compiled from Bug.java
// Compiler version 3.45;
public static Method main:"([Ljava/lang/String;)V"
stack 1 locals 2
{
iconst_1;
istore_1;
iload_1;
iflt L9;
goto L9;
L9: iconst_1;
pop;
return;
}
public Method <init>:"()V"
stack 1 locals 1
{
aload_0;
invokespecial Method java/lang/Object.<init>:"()V";
return;
}
} // end Class Bug
Examination of the compiler code, e.g, Expression.simplify, Expression.inline,
and Expression.inlineValue, reveals that expressions are not always re-examined
for further simplifications enabled by previous simplifications. In the
case illustrated, the CommaExpression introduced during the simplification
of 'i < 0 || true' to '(i < 0, true)' is not further simplified, which would
allow the expression 'i < 0' to be discarded.
While the only observed effects are on code quality, it is possible that
the correctness of the compiler may be impacted, as the compile-time
simplification machinery is also used to evaluate constant expressions as
defined in the JLS. Such expressions must simplify to a literal constant.
appears in a context in which its value is not required.
public class Bug {
public static void main(String args[]) {
int i = 1;
boolean b = i < 0 || true;
}
}
When compiled with javac (1.1.3), the following code results:
public class Bug {
// Compiled from Bug.java
// Compiler version 3.45;
public static Method main:"([Ljava/lang/String;)V"
stack 1 locals 2
{
iconst_1;
istore_1;
iload_1;
iflt L9;
goto L9;
L9: iconst_1;
pop;
return;
}
public Method <init>:"()V"
stack 1 locals 1
{
aload_0;
invokespecial Method java/lang/Object.<init>:"()V";
return;
}
} // end Class Bug
Examination of the compiler code, e.g, Expression.simplify, Expression.inline,
and Expression.inlineValue, reveals that expressions are not always re-examined
for further simplifications enabled by previous simplifications. In the
case illustrated, the CommaExpression introduced during the simplification
of 'i < 0 || true' to '(i < 0, true)' is not further simplified, which would
allow the expression 'i < 0' to be discarded.
While the only observed effects are on code quality, it is possible that
the correctness of the compiler may be impacted, as the compile-time
simplification machinery is also used to evaluate constant expressions as
defined in the JLS. Such expressions must simplify to a literal constant.