* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@49444
138bc75d-0d04-0410-961f-
82ee72b054a4
+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>
#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))
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
/* 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}\
%{!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}}}}}"
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;
}
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 */
};
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));
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)
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) \
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')
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
/* 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;
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
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.
treated as compiler output files, and passed to the linker in their
proper position among the other output files. */
\f
-/* 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. */
#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
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;
%{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}\
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=*}";
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),
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.
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
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
+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.
--- /dev/null
+/* 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
--- /dev/null
+/* 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
--- /dev/null
+/* 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;
+}
/* 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
/* 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;
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':
#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
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)