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]

[PATCH] Fix wchar_t constant strings (take 2)


Hi!

lex_string should actually use charwidth, not width to compute bytemask, so
although my last patch did fix it, it was wrong.
This is what used to be in c-lex.c before Zack's lex_string creation, though
I'm not sure whether wide characters work at all on BITS_PER_UNIT > 8 (but
it would not work before either).
This patch also contains a fix so that
const wchar_t x[] = L"foo";

x[2] is not "optimized" into (wchar_t)((char *)x)[2].
All similar code in expand_expr only optimizes non-wide strings this way, it
should not be hard to handle wchar_t references, but I'm not sure it is
worth it.

2000-09-12  Jakub Jelinek  <jakub@redhat.com>

	* c-lex.c (lex_string): Use charwidth to compute bytemask.
	* expr.c (expand_expr): Don't optimize constant array references
	initialized with wide string constants.

--- gcc/c-lex.c.jj	Mon Sep 11 21:59:18 2000
+++ gcc/c-lex.c	Tue Sep 12 11:50:57 2000
@@ -2381,7 +2381,7 @@ lex_string (str, len, wide)
       if (wide)
 	{
 	  unsigned charwidth = TYPE_PRECISION (char_type_node);
-	  unsigned bytemask = (1 << width) - 1;
+	  unsigned bytemask = (1 << charwidth) - 1;
 	  int byte;
 
 	  for (byte = 0; byte < WCHAR_BYTES; ++byte)
--- gcc/expr.c.jj	Mon Sep 11 21:59:35 2000
+++ gcc/expr.c	Tue Sep 12 12:48:20 2000
@@ -6619,9 +6619,16 @@ expand_expr (exp, target, tmode, modifie
 		else if (TREE_CODE (init) == STRING_CST
 			 && 0 > compare_tree_int (index,
 						  TREE_STRING_LENGTH (init)))
-		  return (GEN_INT
-			  (TREE_STRING_POINTER
-			   (init)[TREE_INT_CST_LOW (index)]));
+		  {
+		    tree type = TREE_TYPE (TREE_TYPE (init));
+		    enum machine_mode mode = TYPE_MODE (type);
+
+		    if (GET_MODE_CLASS (mode) == MODE_INT
+			&& GET_MODE_SIZE (mode) == 1)
+		      return (GEN_INT
+			      (TREE_STRING_POINTER
+			       (init)[TREE_INT_CST_LOW (index)]));
+		  }
 	      }
 	  }
       }

	Jakub

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