cpplex.c (cpp_interpret_charconst): Get signedness or otherwise of wide character...
authorNeil Booth <neil@daikokuya.demon.co.uk>
Sun, 24 Feb 2002 12:52:30 +0000 (12:52 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Sun, 24 Feb 2002 12:52:30 +0000 (12:52 +0000)
* cpplex.c (cpp_interpret_charconst): Get signedness or
otherwise of wide character constants correct.
* cppexp.c (lex): Get signedness of wide charconsts correct.
* testsuite/gcc.dg/cpp/wchar-1.c: New test.

From-SVN: r50005

gcc/ChangeLog
gcc/cppexp.c
gcc/cpplex.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/wchar-1.c [new file with mode: 0644]

index 3280349b6ec90ba118cb81f1fa4700a7bd4ff4a3..06217541fc0a14f1691d0f6c75edc3373ed40cfc 100644 (file)
@@ -1,3 +1,9 @@
+2002-02-24  Neil Booth  <neil@daikokuya.demon.co.uk>
+
+       * cpplex.c (cpp_interpret_charconst): Get signedness or
+       otherwise of wide character constants correct.
+       * cppexp.c (lex): Get signedness of wide charconsts correct.
+
 Sun Feb 24 07:41:31 2002  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>
 
        * optabs.c (widen_operand): Only call convert_modes for
index 1f225c373073f14888bed8ebb86c697cf6a0660a..1d4ceccde956462398139e0ff779d17a7e344c59 100644 (file)
@@ -293,8 +293,10 @@ lex (pfile, skip_evaluation)
       {
        unsigned int chars_seen;
 
-       /* This is always a signed type.  */
-       op.unsignedp = 0;
+       if (token->type == CPP_CHAR)
+         op.unsignedp = 0;
+       else
+         op.unsignedp = WCHAR_UNSIGNED;
        op.op = CPP_NUMBER;
        op.value = cpp_interpret_charconst (pfile, token, 1, 0, &chars_seen);
        return op;
index 70e62806c248858844d0dba328a85fe46a49db94..eea6a9e1c53a426eb24d698ceacbcc22ac19e96a 100644 (file)
@@ -1837,6 +1837,7 @@ cpp_interpret_charconst (pfile, token, warn_multi, traditional, pchars_seen)
   unsigned int width, max_chars, c;
   unsigned HOST_WIDE_INT mask;
   HOST_WIDE_INT result = 0;
+  bool unsigned_p;
 
 #ifdef MULTIBYTE_CHARS
   (void) local_mbtowc (NULL, NULL, 0);
@@ -1844,9 +1845,15 @@ cpp_interpret_charconst (pfile, token, warn_multi, traditional, pchars_seen)
 
   /* Width in bits.  */
   if (token->type == CPP_CHAR)
-    width = MAX_CHAR_TYPE_SIZE;
+    {
+      width = MAX_CHAR_TYPE_SIZE;
+      unsigned_p = CPP_OPTION (pfile, signed_char) == 0;
+    }
   else
-    width = MAX_WCHAR_TYPE_SIZE;
+    {
+      width = MAX_WCHAR_TYPE_SIZE;
+      unsigned_p = WCHAR_UNSIGNED;
+    }
 
   if (width < HOST_BITS_PER_WIDE_INT)
     mask = ((unsigned HOST_WIDE_INT) 1 << width) - 1;
@@ -1903,14 +1910,13 @@ cpp_interpret_charconst (pfile, token, warn_multi, traditional, pchars_seen)
   else if (chars_seen > 1 && !traditional && warn_multi)
     cpp_warning (pfile, "multi-character character constant");
 
-  /* If char type is signed, sign-extend the constant.  */
-  if (token->type == CPP_CHAR && chars_seen)
+  /* If relevant type is signed, sign-extend the constant.  */
+  if (chars_seen)
     {
       unsigned int nbits = chars_seen * width;
 
       mask = (unsigned HOST_WIDE_INT) ~0 >> (HOST_BITS_PER_WIDE_INT - nbits);
-      if (CPP_OPTION (pfile, signed_char) == 0
-         || ((result >> (nbits - 1)) & 1) == 0)
+      if (unsigned_p || ((result >> (nbits - 1)) & 1) == 0)
        result &= mask;
       else
        result |= ~mask;
index 15905e6ea5ba8a880a770cf13ae61e2506b59a91..61dedb65bf702aa76ac4e8cc8104611f6d15673b 100644 (file)
@@ -1,3 +1,7 @@
+2002-02-24  Neil Booth  <neil@daikokuya.demon.co.uk>
+
+       * testsuite/gcc.dg/cpp/wchar-1.c: New test.
+
 2002-02-23  Jakub Jelinek  <jakub@redhat.com>
 
        * gcc.dg/20020222-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/cpp/wchar-1.c b/gcc/testsuite/gcc.dg/cpp/wchar-1.c
new file mode 100644 (file)
index 0000000..f93c1cd
--- /dev/null
@@ -0,0 +1,23 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.  */
+
+/* { dg-do run } */
+
+/* Source: Neil Booth, 24 Feb 2002.
+
+   Test if compiler and preprocessor agree on signeness of wide
+   chars.  */
+
+int main ()
+{
+  __WCHAR_TYPE__ c = -1;
+
+#if L'\x0' - 1 < 0
+  if (c > 0)
+    abort ();
+#else
+  if (c < 0)
+    abort ();
+#endif
+  return 0;
+}