This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Mauve - the remainder
- From: Mark Wielaard <mark at klomp dot org>
- To: java at gcc dot gnu dot org
- Date: 18 Apr 2002 01:07:00 +0200
- Subject: Re: Mauve - the remainder
- References: <1019080941.7866.133.camel@elsschot>
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