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 (was Re: wchar_t constant not possible)


Hi!

The following patch restores the old gcc behaviour where the string is
stored properly (e.g. on ia32 as .string "f"; .string ""; .string ""; .string ""
etc.), but still fails (this test seems to fail with e.g. 0731 snapshot as
well), I'll track that other bug soonish.

The issue is that if width is width is equal to HOST_BITS_PER_INT, then
(1 << width) - 1 has undefined value and may as well result in 0 as opposed
to ~0.
Ok to commit?

> 2000-09-12  Andreas Jaeger  <aj@suse.de>
> 
> 	* gcc.c-torture/execute/widechar-2.c: Test for wchar_t constant by
> 	Ulrich Drepper <drepper@redhat.com>.
> 
> ============================================================
> Index: gcc/testsuite/gcc.c-torture/execute/widechar-2.c
> --- gcc/testsuite/gcc.c-torture/execute/widechar-2.c	created
> +++ gcc/testsuite/gcc.c-torture/execute/widechar-2.c	Tue Sep 12 09:20:21 2000	1.1
> @@ -0,0 +1,9 @@
> +#include <wchar.h>
> +
> +const wchar_t ws[] = L"foo";
> +
> +int
> +main (void)
> +{
> +  return ws[0] != L'f' || ws[1] != L'o' || ws[2] != L'o' || ws[3] != L'\0';
> +}

BTW: You might want to change this to:
  if (ws[0] != L'f' || ws[1] != L'o' || ws[2] != L'o' || ws[3] != L'\0')
    abort();
  exit(0);

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

	* c-lex.c (lex_string): If width == HOST_BITS_PER_INT,
	use ~0 as bytemask.

--- gcc/c-lex.c.jj	Mon Sep 11 21:59:18 2000
+++ gcc/c-lex.c	Tue Sep 12 10:45:36 2000
@@ -2381,7 +2381,8 @@ lex_string (str, len, wide)
       if (wide)
 	{
 	  unsigned charwidth = TYPE_PRECISION (char_type_node);
-	  unsigned bytemask = (1 << width) - 1;
+	  unsigned bytemask = width < HOST_BITS_PER_INT
+			      ? (1 << width) - 1 : ~0;
 	  int byte;
 
 	  for (byte = 0; byte < WCHAR_BYTES; ++byte)

	Jakub

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