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
This commit is contained in:
Neil Booth 2002-02-02 18:56:37 +00:00 committed by Neil Booth
parent 1acce4c771
commit 0fef3fd0ea
19 changed files with 116 additions and 70 deletions

View file

@ -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>

View file

@ -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))

View file

@ -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

View file

@ -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}}}}}"

View file

@ -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;
}

View file

@ -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 */
};

View file

@ -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')

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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.

View file

@ -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

View file

@ -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

View file

@ -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;
}

View file

@ -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

View file

@ -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

View file

@ -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)