Mauve - the remainder
Mark Wielaard
mark@klomp.org
Wed Apr 17 16:24:00 GMT 2002
Hi,
On Thu, 2002年04月18日 at 00:02, Mark Wielaard wrote:
>> FAIL: gnu.testlet.java.lang.StringBuffer.plus (number 1)
>> The following program returns false, but should return true:
>> public class SN
> {
> public static void main(String[] args)
> {
> System.out.println("null".equals(n(0) + ""));
> }
>> static String n(int i)
> {
> if (i==0) return null; else return "x";
> }
> }
>> The problem is that the String concatenation gets optimized away and
> since n(0) returns null it does not generate the string "null" but it
> generates the value null. The problem disappears when the return type of
> n() is changed to Object.
OK, the following optimization seems to be the problem:
diff -u -r1.353.2.17 parse.y
--- gcc/java/parse.y 15 Apr 2002 09:28:53 -0000 1.353.2.17
+++ gcc/java/parse.y 17 Apr 2002 22:50:38 -0000
@@ -13756,8 +13756,8 @@
op2 = patch_string_cst (op2);
/* If either one of the constant is null and the other non null
- operand is a String object, return it. */
- if (JSTRING_TYPE_P (TREE_TYPE (op1)) && !op2)
+ operand is a String constant, return it. */
+ if ((TREE_CODE (op1) == STRING_CST) && !op2)
return op1;
/* If OP1 isn't already a StringBuffer, create and
Or does this look to conservative?
Good night,
Mark
More information about the Java
mailing list