This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch: PR java/10253 (string concatenation with integer 0 constant)


Hmm, I was also working on this yesterday, and I think my solution below is a bit more elegant (less special casing). It also corrects a bug with appending unicode characters greater than 0x7ff, as in ""+'\uffff'.

The only reason I didn't report it yesterday is that it takes me so long to test on my slow i386-pc-cygwin (testing is still in progress).

And, since this is a front-end patch, you should have cc'd gcc-patches.

Mohan Embar wrote:
Hi Patch People,

This fixes PR java/10253 which Lars first reported here:

http://gcc.gnu.org/ml/java/2003-03/msg00376.html

Although this isn't platform-specific, I nevertheless tested
it with the i686-pc-linux-gnu and i386-pc-mingw32 native
compilers as well as the i686-pc-linux-gnu > i386-pc-mingw32
cross compiler.

I've attached my test case.

Off topic: I'll put out a new MingW build tonight which
incorporates this.

--
This signature intentionally left boring.

Eric Blake             ebb9 at email dot byu dot edu
  BYU student, free software programmer

2003-04-09 Eric Blake <ebb9 at email dot byu dot edu>

	PR java/10253:
	* parse.y (string_convert_int_cst): Always use at least one digit
	in string conversion. Remove ASCII dependence.
	(merge_string_cste): Fix merging of 3-byte UTF-8 characters.

Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.427
diff -u -r1.427 parse.y
--- parse.y	25 Mar 2003 17:00:47 -0000	1.427
+++ parse.y	9 Apr 2003 14:39:25 -0000
@@ -12489,7 +12489,8 @@
 static char *
 string_convert_int_cst (tree node)
 {
-  static char buffer[80];
+  /* Long.MIN_VALUE is -9223372036854775808, 20 characters.  */
+  static char buffer[21];
 
   unsigned HOST_WIDE_INT lo = TREE_INT_CST_LOW (node);
   unsigned HOST_WIDE_INT hi = TREE_INT_CST_HIGH (node);
@@ -12512,7 +12513,7 @@
     }
 
   /* Divide by 10 until there are no bits left.  */
-  while (hi || lo)
+  do
     {
       unsigned HOST_WIDE_INT acc = 0;
       unsigned HOST_WIDE_INT outhi = 0, outlo = 0;
@@ -12544,12 +12545,12 @@
 	    }
 	}
 
-      /* FIXME: ASCII assumption.  */
-      *p-- = '0' + acc;
+      *p-- = "0123456789"[acc];
 
       hi = outhi;
       lo = outlo;
     }
+  while (hi || lo);
 
   if (neg)
     *p-- = '-';
@@ -13678,23 +13679,23 @@
 }
 
 /* Tries to merge OP1 (a STRING_CST) and OP2 (if suitable). Return a
-   new STRING_CST on success, NULL_TREE on failure */
+   new STRING_CST on success, NULL_TREE on failure.  */
 
 static tree
 merge_string_cste (tree op1, tree op2, int after)
 {
-  /* Handle two string constants right away */
+  /* Handle two string constants right away.  */
   if (TREE_CODE (op2) == STRING_CST)
     return do_merge_string_cste (op1, TREE_STRING_POINTER (op2),
 				 TREE_STRING_LENGTH (op2), after);
 
-  /* Reasonable integer constant can be treated right away */
+  /* Reasonable integer constant can be treated right away.  */
   if (TREE_CODE (op2) == INTEGER_CST && !TREE_CONSTANT_OVERFLOW (op2))
     {
       static const char *const boolean_true = "true";
       static const char *const boolean_false = "false";
       static const char *const null_pointer = "null";
-      char ch[3];
+      char ch[4];
       const char *string;
 
       if (op2 == boolean_true_node)
@@ -13702,6 +13703,9 @@
       else if (op2 == boolean_false_node)
 	string = boolean_false;
       else if (op2 == null_pointer_node)
+	/* FIXME: null is not a compile-time constant, so it only safe to
+	   merge if the overall expression is non-constant. However, this
+	   code always merges without checking the overall expression.  */
 	string = null_pointer;
       else if (TREE_TYPE (op2) == char_type_node)
 	{
@@ -13711,9 +13715,15 @@
 	  if (0x01 <= c
 	      && c <= 0x7f)
 	    *p++ = c;
-	  else
+	  else if (c < 0x7ff)
 	    {
 	      *p++ = c >> 6 | 0xc0;
+	      *p++ = (c & 0x3f) | 0x80;
+	    }
+	  else
+	    {
+	      *p++ = c >> 12 | 0xe0;
+	      *p++ = ((c >> 6) & 0x3f) | 0x80;
 	      *p++ = (c & 0x3f) | 0x80;
 	    }
 	  *p = '\0';

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]