aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Booth <neil@daikokuya.demon.co.uk>2002-02-02 18:56:37 +0000
committerNeil Booth <neil@gcc.gnu.org>2002-02-02 18:56:37 +0000
commit0fef3fd0eada944c2677ba0680393a12979f970f (patch)
tree955327bc9f9ac1f86814b649a8e7be4427abe84a
parent1acce4c771ff585069a1551fe1a6d0bf70fdda52 (diff)
downloadgcc-0fef3fd0eada944c2677ba0680393a12979f970f.zip
gcc-0fef3fd0eada944c2677ba0680393a12979f970f.tar.gz
gcc-0fef3fd0eada944c2677ba0680393a12979f970f.tar.bz2
cpphash.h (struct spec_nodes): Remove n__CHAR_UNSIGNED__.
* cpphash.h (struct spec_nodes): Remove n__CHAR_UNSIGNED__. * cpphash.c (_cpp_init_hashtable): Similarly. * cppinit.c (cpp_create_reader): Default the signed_char flag. (init_builtins): Define __CHAR_UNSIGNED__ appropriately. (COMMAND_LINE_OPTIONS): Recognise -f{un,}signed-char. (cpp_handle_option): Handle the new options. * cpplex.c (cpp_interpret_charconst): Use new flag. * cpplib.h (struct cpp_options): New member signed_char. * gcc.c (cpp_unique_options): Remove %c spec and documentation. (cpp_options): Handle -fsigned-char and -funsigned-char. (static_specs): Remove signed_char_spec. (do_spec1): Don't handle %c. * system.h: Poison SIGNED_CHAR_SPEC. * tradcif.y (yylex): Use flag_signed_char. * tradcpp.h (flag_signed_char): New. * tradcpp.c (flag_signed_char): New. (main): Handle new command-line options. (initialize_builtins): Define __CHAR_UNSIGNED__ if appropriate. config: * alpha/alpha.h (SIGNED_CHAR_SPEC): Remove. * avr/avr.h: Remove old comments. * i960/i960.h (CPP_SPEC): Pass -fsigned-char if -mic*. (CC1_SPEC): Pass -fsigned-char if -mic*. (SIGNED_CHAR_SPEC): Remove. doc: * tm.texi (SIGNED_CHAR_SPEC): Remove documentation. testsuite: * gcc.dg/cpp/uchar-1.c, uchar-2.c, uchar-3.c: New tests. From-SVN: r49444
-rw-r--r--gcc/ChangeLog29
-rw-r--r--gcc/config/alpha/alpha.h6
-rw-r--r--gcc/config/avr/avr.h11
-rw-r--r--gcc/config/i960/i960.h20
-rw-r--r--gcc/cpphash.c1
-rw-r--r--gcc/cpphash.h1
-rw-r--r--gcc/cppinit.c16
-rw-r--r--gcc/cpplex.c5
-rw-r--r--gcc/cpplib.h3
-rw-r--r--gcc/doc/tm.texi10
-rw-r--r--gcc/gcc.c27
-rw-r--r--gcc/system.h2
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/cpp/uchar-1.c8
-rw-r--r--gcc/testsuite/gcc.dg/cpp/uchar-2.c8
-rw-r--r--gcc/testsuite/gcc.dg/cpp/uchar-3.c17
-rw-r--r--gcc/tradcif.y3
-rw-r--r--gcc/tradcpp.c14
-rw-r--r--gcc/tradcpp.h1
19 files changed, 116 insertions, 70 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 5279c56..5ad4904 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,32 @@
+2002-02-02 Neil Booth <neil@daikokuya.demon.co.uk>
+
+ * cpphash.h (struct spec_nodes): Remove n__CHAR_UNSIGNED__.
+ * cpphash.c (_cpp_init_hashtable): Similarly.
+ * cppinit.c (cpp_create_reader): Default the signed_char flag.
+ (init_builtins): Define __CHAR_UNSIGNED__ appropriately.
+ (COMMAND_LINE_OPTIONS): Recognise -f{un,}signed-char.
+ (cpp_handle_option): Handle the new options.
+ * cpplex.c (cpp_interpret_charconst): Use new flag.
+ * cpplib.h (struct cpp_options): New member signed_char.
+ * gcc.c (cpp_unique_options): Remove %c spec and documentation.
+ (cpp_options): Handle -fsigned-char and -funsigned-char.
+ (static_specs): Remove signed_char_spec.
+ (do_spec1): Don't handle %c.
+ * system.h: Poison SIGNED_CHAR_SPEC.
+ * tradcif.y (yylex): Use flag_signed_char.
+ * tradcpp.h (flag_signed_char): New.
+ * tradcpp.c (flag_signed_char): New.
+ (main): Handle new command-line options.
+ (initialize_builtins): Define __CHAR_UNSIGNED__ if appropriate.
+config:
+ * alpha/alpha.h (SIGNED_CHAR_SPEC): Remove.
+ * avr/avr.h: Remove old comments.
+ * i960/i960.h (CPP_SPEC): Pass -fsigned-char if -mic*.
+ (CC1_SPEC): Pass -fsigned-char if -mic*.
+ (SIGNED_CHAR_SPEC): Remove.
+doc:
+ * tm.texi (SIGNED_CHAR_SPEC): Remove documentation.
+
2002-02-01 Eric Christopher <echristo@redhat.com>
From Daniel Jacobowitz <dmj+@andrew.cmu.edu>
diff --git a/gcc/config/alpha/alpha.h b/gcc/config/alpha/alpha.h
index dd8d820..4e676f2 100644
--- a/gcc/config/alpha/alpha.h
+++ b/gcc/config/alpha/alpha.h
@@ -43,12 +43,6 @@ Boston, MA 02111-1307, USA. */
#define CPP_SUBTARGET_SPEC ""
#endif
-/* Set the spec to use for signed char. The default tests the above macro
- but DEC's compiler can't handle the conditional in a "constant"
- operand. */
-
-#define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
-
#define WORD_SWITCH_TAKES_ARG(STR) \
(!strcmp (STR, "rpath") || DEFAULT_WORD_SWITCH_TAKES_ARG(STR))
diff --git a/gcc/config/avr/avr.h b/gcc/config/avr/avr.h
index 52cba88..742c811 100644
--- a/gcc/config/avr/avr.h
+++ b/gcc/config/avr/avr.h
@@ -2688,16 +2688,7 @@ extern int avr_case_values_threshold;
This should be defined if `PTRDIFF_TYPE' depends on target
dependent flags which are not accessible to the preprocessor.
- Otherwise, it should not be defined.
-
- `SIGNED_CHAR_SPEC'
- A C string constant that tells the GNU CC driver program options to
- pass to CPP. By default, this macro is defined to pass the option
- `-D__CHAR_UNSIGNED__' to CPP if `char' will be treated as
- `unsigned char' by `cc1'.
-
- Do not define this macro unless you need to override the default
- definition. */
+ Otherwise, it should not be defined. */
#define CC1_SPEC "%{profile:-p}"
/* A C string constant that tells the GNU CC driver program options to
diff --git a/gcc/config/i960/i960.h b/gcc/config/i960/i960.h
index ec4b9d1..4df5a6f 100644
--- a/gcc/config/i960/i960.h
+++ b/gcc/config/i960/i960.h
@@ -30,8 +30,9 @@ Boston, MA 02111-1307, USA. */
/* Names to predefine in the preprocessor for this target machine. */
#define CPP_PREDEFINES "-Di960 -Di80960 -DI960 -DI80960 -Acpu=i960 -Amachine=i960"
-/* Name to predefine in the preprocessor for processor variations. */
-#define CPP_SPEC "%{mic*:-D__i960\
+/* Name to predefine in the preprocessor for processor variations.
+ -mic* options make characters signed by default. */
+#define CPP_SPEC "%{mic*:-D__i960 -fsigned-char\
%{mka:-D__i960KA}%{mkb:-D__i960KB}\
%{mja:-D__i960JA}%{mjd:-D__i960JD}%{mjf:-D__i960JF}\
%{mrp:-D__i960RP}\
@@ -52,20 +53,13 @@ Boston, MA 02111-1307, USA. */
%{!mcc:%{!mcf:-D__i960_KB -D__i960KB__ %{mic*:-D__i960KB}}}}}}}}}\
%{mlong-double-64:-D__LONG_DOUBLE_64__}"
-/* -mic* options make characters signed by default. */
-/* Use #if rather than ?: because MIPS C compiler rejects ?: in
- initializers. */
-#if DEFAULT_SIGNED_CHAR
-#define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
-#else
-#define SIGNED_CHAR_SPEC "%{!fsigned-char:%{!mic*:-D__CHAR_UNSIGNED__}}"
-#endif
-
/* Specs for the compiler, to handle processor variations.
If the user gives an explicit -gstabs or -gcoff option, then do not
- try to add an implicit one, as this will fail. */
+ try to add an implicit one, as this will fail.
+ -mic* options make characters signed by default. */
#define CC1_SPEC \
- "%{!mka:%{!mkb:%{!msa:%{!msb:%{!mmc:%{!mca:%{!mcc:%{!mcf:%{!mja:%{!mjd:%{!mjf:%{!mrp:-mka}}}}}}}}}}}}\
+ "%{mic*:-fsigned-char}\
+%{!mka:%{!mkb:%{!msa:%{!msb:%{!mmc:%{!mca:%{!mcc:%{!mcf:%{!mja:%{!mjd:%{!mjf:%{!mrp:-mka}}}}}}}}}}}}\
%{!gs*:%{!gc*:%{mbout:%{g*:-gstabs}}\
%{mcoff:%{g*:-gcoff}}\
%{!mbout:%{!mcoff:%{g*:-gstabs}}}}}"
diff --git a/gcc/cpphash.c b/gcc/cpphash.c
index 8be1b2f..69e1a23 100644
--- a/gcc/cpphash.c
+++ b/gcc/cpphash.c
@@ -73,7 +73,6 @@ _cpp_init_hashtable (pfile, table)
s->n_true = cpp_lookup (pfile, DSC("true"));
s->n_false = cpp_lookup (pfile, DSC("false"));
s->n__STRICT_ANSI__ = cpp_lookup (pfile, DSC("__STRICT_ANSI__"));
- s->n__CHAR_UNSIGNED__ = cpp_lookup (pfile, DSC("__CHAR_UNSIGNED__"));
s->n__VA_ARGS__ = cpp_lookup (pfile, DSC("__VA_ARGS__"));
s->n__VA_ARGS__->flags |= NODE_DIAGNOSTIC;
}
diff --git a/gcc/cpphash.h b/gcc/cpphash.h
index be8d902..e06914a 100644
--- a/gcc/cpphash.h
+++ b/gcc/cpphash.h
@@ -164,7 +164,6 @@ struct spec_nodes
cpp_hashnode *n_true; /* C++ keyword true */
cpp_hashnode *n_false; /* C++ keyword false */
cpp_hashnode *n__STRICT_ANSI__; /* STDC_0_IN_SYSTEM_HEADERS */
- cpp_hashnode *n__CHAR_UNSIGNED__; /* plain char is unsigned */
cpp_hashnode *n__VA_ARGS__; /* C99 vararg macros */
};
diff --git a/gcc/cppinit.c b/gcc/cppinit.c
index ab3dad7..717fb3f 100644
--- a/gcc/cppinit.c
+++ b/gcc/cppinit.c
@@ -490,6 +490,11 @@ cpp_create_reader (lang)
CPP_OPTION (pfile, show_column) = 1;
CPP_OPTION (pfile, tabstop) = 8;
CPP_OPTION (pfile, operator_names) = 1;
+#if DEFAULT_SIGNED_CHAR
+ CPP_OPTION (pfile, signed_char) = 1;
+#else
+ CPP_OPTION (pfile, signed_char) = 0;
+#endif
CPP_OPTION (pfile, pending) =
(struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
@@ -761,6 +766,9 @@ init_builtins (pfile)
else if (CPP_OPTION (pfile, c99))
_cpp_define_builtin (pfile, "__STDC_VERSION__ 199901L");
+ if (CPP_OPTION (pfile, signed_char) == 0)
+ _cpp_define_builtin (pfile, "__CHAR_UNSIGNED__ 1");
+
if (CPP_OPTION (pfile, lang) == CLK_STDC89
|| CPP_OPTION (pfile, lang) == CLK_STDC94
|| CPP_OPTION (pfile, lang) == CLK_STDC99)
@@ -1186,7 +1194,9 @@ new_pending_directive (pend, text, handler)
DEF_OPT("fno-show-column", 0, OPT_fno_show_column) \
DEF_OPT("fpreprocessed", 0, OPT_fpreprocessed) \
DEF_OPT("fshow-column", 0, OPT_fshow_column) \
+ DEF_OPT("fsigned-char", 0, OPT_fsigned_char) \
DEF_OPT("ftabstop=", no_num, OPT_ftabstop) \
+ DEF_OPT("funsigned-char", 0, OPT_funsigned_char) \
DEF_OPT("h", 0, OPT_h) \
DEF_OPT("idirafter", no_dir, OPT_idirafter) \
DEF_OPT("imacros", no_fil, OPT_imacros) \
@@ -1395,6 +1405,12 @@ cpp_handle_option (pfile, argc, argv, ignore)
case OPT_fno_show_column:
CPP_OPTION (pfile, show_column) = 0;
break;
+ case OPT_fsigned_char:
+ CPP_OPTION (pfile, signed_char) = 1;
+ break;
+ case OPT_funsigned_char:
+ CPP_OPTION (pfile, signed_char) = 0;
+ break;
case OPT_ftabstop:
/* Silently ignore empty string, non-longs and silly values. */
if (arg[0] != '\0')
diff --git a/gcc/cpplex.c b/gcc/cpplex.c
index 8465350..70e6280 100644
--- a/gcc/cpplex.c
+++ b/gcc/cpplex.c
@@ -1903,14 +1903,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. The
- __CHAR_UNSIGNED__ macro is set by the driver if appropriate. */
+ /* If char type is signed, sign-extend the constant. */
if (token->type == CPP_CHAR && chars_seen)
{
unsigned int nbits = chars_seen * width;
mask = (unsigned HOST_WIDE_INT) ~0 >> (HOST_BITS_PER_WIDE_INT - nbits);
- if (pfile->spec_nodes.n__CHAR_UNSIGNED__->type == NT_MACRO
+ if (CPP_OPTION (pfile, signed_char) == 0
|| ((result >> (nbits - 1)) & 1) == 0)
result &= mask;
else
diff --git a/gcc/cpplib.h b/gcc/cpplib.h
index eeeecc0..47169dc 100644
--- a/gcc/cpplib.h
+++ b/gcc/cpplib.h
@@ -240,6 +240,9 @@ struct cpp_options
/* Non-0 means -v, so print the full set of include dirs. */
unsigned char verbose;
+ /* Nonzero means chars are signed. */
+ unsigned char signed_char;
+
/* Nonzero means use extra default include directories for C++. */
unsigned char cplusplus;
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index e9797bf..c81cd26 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -216,16 +216,6 @@ This should be defined if @code{WINT_TYPE} depends on target dependent flags
which are not accessible to the preprocessor. Otherwise, it should not
be defined.
-@findex SIGNED_CHAR_SPEC
-@item SIGNED_CHAR_SPEC
-A C string constant that tells the GCC driver program options to
-pass to CPP@. By default, this macro is defined to pass the option
-@option{-D__CHAR_UNSIGNED__} to CPP if @code{char} will be treated as
-@code{unsigned char} by @code{cc1}.
-
-Do not define this macro unless you need to override the default
-definition.
-
@findex CC1_SPEC
@item CC1_SPEC
A C string constant that tells the GCC driver program options to
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 8968af6..41c62a9 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -445,7 +445,6 @@ or with constant text in a single argument.
if multilib_dir is not set or is ".", output "".
%S process STARTFILE_SPEC as a spec. A capital S is actually used here.
%E process ENDFILE_SPEC as a spec. A capital E is actually used here.
- %c process SIGNED_CHAR_SPEC as a spec.
%C process CPP_SPEC as a spec.
%1 process CC1_SPEC as a spec.
%2 process CC1PLUS_SPEC as a spec.
@@ -511,7 +510,7 @@ CC also knows implicitly that arguments starting in `-l' are to be
treated as compiler output files, and passed to the linker in their
proper position among the other output files. */
-/* Define the macros used for specs %a, %l, %L, %S, %c, %C, %1. */
+/* Define the macros used for specs %a, %l, %L, %S, %C, %1. */
/* config.h can define ASM_SPEC to provide extra args to the assembler
or extra switch-translations. */
@@ -582,17 +581,6 @@ proper position among the other output files. */
#define ENDFILE_SPEC ""
#endif
-/* This spec is used for telling cpp whether char is signed or not. */
-#ifndef SIGNED_CHAR_SPEC
-/* Use #if rather than ?:
- because MIPS C compiler rejects like ?: in initializers. */
-#if DEFAULT_SIGNED_CHAR
-#define SIGNED_CHAR_SPEC "%{funsigned-char:-D__CHAR_UNSIGNED__}"
-#else
-#define SIGNED_CHAR_SPEC "%{!fsigned-char:-D__CHAR_UNSIGNED__}"
-#endif
-#endif
-
#ifndef LINKER_NAME
#define LINKER_NAME "collect2"
#endif
@@ -651,7 +639,6 @@ static const char *cpp_spec = CPP_SPEC;
static const char *cpp_predefines = CPP_PREDEFINES;
static const char *cc1_spec = CC1_SPEC;
static const char *cc1plus_spec = CC1PLUS_SPEC;
-static const char *signed_char_spec = SIGNED_CHAR_SPEC;
static const char *asm_spec = ASM_SPEC;
static const char *asm_final_spec = ASM_FINAL_SPEC;
static const char *link_spec = LINK_SPEC;
@@ -681,7 +668,7 @@ static const char *cpp_unique_options =
%{M} %{MM} %W{MF*} %{MG} %{MP} %{MQ*} %{MT*} %{M|MD|MM|MMD:%{o*:-MQ %*}}\
%{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2 -D__GNUC_PATCHLEVEL__=%v3}\
%{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
- %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
+ %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
%{fno-inline|O0|!O*:-D__NO_INLINE__} %{ffast-math:-D__FAST_MATH__}\
%{fshort-wchar:-U__WCHAR_TYPE__ -D__WCHAR_TYPE__=short\\ unsigned\\ int}\
%{ffreestanding:-D__STDC_HOSTED__=0} %{fno-hosted:-D__STDC_HOSTED__=0}\
@@ -694,6 +681,7 @@ static const char *cpp_unique_options =
static const char *cpp_options =
"%(cpp_unique_options) %{std*} %{d*} %{W*} %{w} %{pedantic*}\
%{fshow-column} %{fno-show-column}\
+ %{fsigned-char&funsigned-char}\
%{fleading-underscore} %{fno-leading-underscore}\
%{fno-operator-names} %{ftabstop=*}";
@@ -1382,7 +1370,6 @@ static struct spec_list static_specs[] =
INIT_STATIC_SPEC ("libgcc", &libgcc_spec),
INIT_STATIC_SPEC ("startfile", &startfile_spec),
INIT_STATIC_SPEC ("switches_need_spaces", &switches_need_spaces),
- INIT_STATIC_SPEC ("signed_char", &signed_char_spec),
INIT_STATIC_SPEC ("predefines", &cpp_predefines),
INIT_STATIC_SPEC ("cross_compile", &cross_compile),
INIT_STATIC_SPEC ("version", &compiler_version),
@@ -1785,7 +1772,7 @@ load_specs (filename)
A suffix which starts with `*' is a definition for
one of the machine-specific sub-specs. The "suffix" should be
- *asm, *cc1, *cpp, *link, *startfile, *signed_char, etc.
+ *asm, *cc1, *cpp, *link, *startfile, etc.
The corresponding spec is stored in asm_spec, etc.,
rather than in the `compilers' vector.
@@ -4783,12 +4770,6 @@ do_spec_1 (spec, inswitch, soft_matched_part)
return value;
break;
- case 'c':
- value = do_spec_1 (signed_char_spec, 0, NULL);
- if (value != 0)
- return value;
- break;
-
case 'C':
{
const char *const spec
diff --git a/gcc/system.h b/gcc/system.h
index 9bd0599..25e9549 100644
--- a/gcc/system.h
+++ b/gcc/system.h
@@ -594,7 +594,7 @@ typedef char _Bool;
SET_DEFAULT_TYPE_ATTRIBUTES SET_DEFAULT_DECL_ATTRIBUTES \
MERGE_MACHINE_TYPE_ATTRIBUTES MERGE_MACHINE_DECL_ATTRIBUTES \
MD_INIT_BUILTINS MD_EXPAND_BUILTIN ASM_OUTPUT_CONSTRUCTOR \
- ASM_OUTPUT_DESTRUCTOR
+ ASM_OUTPUT_DESTRUCTOR SIGNED_CHAR_SPEC
/* And other obsolete target macros, or macros that used to be in target
headers and were not used, and may be obsolete or may never have
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 35d019f..199f6ca 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2002-02-02 Neil Booth <neil@daikokuya.demon.co.uk>
+
+ * gcc.dg/cpp/uchar-1.c, uchar-2.c, uchar-3.c: New tests.
+
2002-02-02 Richard Henderson <rth@redhat.com>
* gcc.c-torture/execute/991118-1.c: Revert 2002-01-29 change.
diff --git a/gcc/testsuite/gcc.dg/cpp/uchar-1.c b/gcc/testsuite/gcc.dg/cpp/uchar-1.c
new file mode 100644
index 0000000..3483e328
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/uchar-1.c
@@ -0,0 +1,8 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc. */
+
+/* { dg-do preprocess } */
+/* { dg-options "-funsigned-char -fsigned-char" } */
+
+#if defined (__CHAR_UNSIGNED__)
+# error __CHAR_UNSIGNED__ defined
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/uchar-2.c b/gcc/testsuite/gcc.dg/cpp/uchar-2.c
new file mode 100644
index 0000000..739573c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/uchar-2.c
@@ -0,0 +1,8 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc. */
+
+/* { dg-do preprocess } */
+/* { dg-options "-funsigned-char -fsigned-char -traditional" } */
+
+#if defined (__CHAR_UNSIGNED__)
+# error __CHAR_UNSIGNED__ defined
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/uchar-3.c b/gcc/testsuite/gcc.dg/cpp/uchar-3.c
new file mode 100644
index 0000000..41b987f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/uchar-3.c
@@ -0,0 +1,17 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc. */
+
+/* { dg-do compile } */
+/* { dg-options "-funsigned-char -fpreprocessed" } */
+
+/* Source: Ziemowit Laski. -fpreprocessed doesn't define macros, but
+ CPP would interpret charconsts based upon whether __CHAR_UNSIGNED__
+ was defined. */
+
+int foo()
+{
+ char f = 0x83;
+ if (f == '\x83') /* { dg-bogus "always false" } */
+ f = 0;
+
+ return 0;
+}
diff --git a/gcc/tradcif.y b/gcc/tradcif.y
index 4598d61..953e2d6 100644
--- a/gcc/tradcif.y
+++ b/gcc/tradcif.y
@@ -344,8 +344,7 @@ yylex ()
/* Sign-extend the constant if chars are signed on target machine. */
{
- if (lookup ((const unsigned char *)"__CHAR_UNSIGNED__",
- sizeof ("__CHAR_UNSIGNED__")-1, -1)
+ if (flag_signed_char == 0
|| ((c >> (CHAR_TYPE_SIZE - 1)) & 1) == 0)
yylval.integer.value = c & ((1 << CHAR_TYPE_SIZE) - 1);
else
diff --git a/gcc/tradcpp.c b/gcc/tradcpp.c
index 11c5fd3..3cff998 100644
--- a/gcc/tradcpp.c
+++ b/gcc/tradcpp.c
@@ -86,6 +86,13 @@ int inhibit_warnings = 0;
/* Non-0 means don't output the preprocessed program. */
int inhibit_output = 0;
+/* Nonzero means chars are signed. */
+#if DEFAULT_SIGNED_CHAR
+int flag_signed_char = 1;
+#else
+int flag_signed_char = 0;
+#endif
+
/* Nonzero means warn if slash-star appears in a comment. */
int warn_comments;
@@ -627,6 +634,10 @@ main (argc, argv)
user_label_prefix = "_";
else if (!strcmp (argv[i], "-fno-leading-underscore"))
user_label_prefix = "";
+ else if (!strcmp (argv[i], "-fsigned-char"))
+ flag_signed_char = 1;
+ else if (!strcmp (argv[i], "-funsigned-char"))
+ flag_signed_char = 0;
break;
case 'M':
@@ -5105,6 +5116,9 @@ initialize_builtins ()
#endif
install_value ("__REGISTER_PREFIX__", REGISTER_PREFIX);
install_value ("__USER_LABEL_PREFIX__", user_label_prefix);
+
+ if (flag_signed_char == 0)
+ install_value ("__CHAR_UNSIGNED__", "1");
}
#undef DSC
#undef install_spec
diff --git a/gcc/tradcpp.h b/gcc/tradcpp.h
index 0c16cfa..89940d0 100644
--- a/gcc/tradcpp.h
+++ b/gcc/tradcpp.h
@@ -35,6 +35,7 @@ extern void fancy_abort PARAMS ((int, const char *)) ATTRIBUTE_NORETURN;
extern struct hashnode *lookup PARAMS ((const unsigned char *, int, int));
extern int parse_c_expression PARAMS ((const char *)); /* in tradcif.y */
extern int test_assertion PARAMS ((unsigned char **));
+extern int flag_signed_char;
#define is_idchar(x) ISIDNUM(x)
#define is_idstart(x) ISIDST(x)