Patch: fix string concatenation for gcj
Anthony Green
green@redhat.com
Sun Sep 29 15:10:00 GMT 2002
This patch fixes a bug in gcj's string literal concatenation code.
I've also submitted a new test case to the java-patches list.
http://gcc.gnu.org/ml/java-patches/2002-q3/msg00329.html
The problem shows up when you try to concatenate a string literal and
a character constant. Character constants need to be UTF-8 encoded before
concatenation, otherwise the java runtime won't be able to decode them
properly.
2002-09-29 Anthony Green <green@redhat.com>
* parse.y (merge_string_cste): Fix bug in string concatenation.
Index: gcc/java/parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.396
diff -c -r1.396 parse.y
*** gcc/java/parse.y 21 Sep 2002 02:19:44 -0000 1.396
--- gcc/java/parse.y 29 Sep 2002 22:02:49 -0000
***************
*** 13773,13780 ****
string = null_pointer;
else if (TREE_TYPE (op2) == char_type_node)
{
! ch[0] = (char )TREE_INT_CST_LOW (op2);
! ch[1] = '\0';
string = ch;
}
else
--- 13773,13791 ----
string = null_pointer;
else if (TREE_TYPE (op2) == char_type_node)
{
! /* Convert the character into UTF-8. */
! unsigned char c = (unsigned char) TREE_INT_CST_LOW (op2);
! unsigned char *p = (unsigned char *) ch;
! if (0x01 <= c
! && c <= 0x7f)
! *p++ = c;
! else
! {
! *p++ = c >> 6 | 0xc0;
! *p++ = c & 0x3f | 0x80;
! }
! *p = '\0';
!
string = ch;
}
else
More information about the Gcc-patches
mailing list