This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Don't quietly skip unrecognized -Wblah-blah options, avoid duplication on command line
- From: Jakub Jelinek <jakub at redhat dot com>
- To: rth at redhat dot com
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 28 Jan 2002 12:01:43 +0100
- Subject: [PATCH] Don't quietly skip unrecognized -Wblah-blah options, avoid duplication on command line
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
Although cpp should ignore unrecognized -W options, cc1/cc1plus/... IMHO
shouldn't (they didn't used to do this before integrated cpp and we issue
error about other unrecognized options too).
After writing this, I've noticed gcc -Wabcde foo.c would error twice, not
once on it (similarly to e.g. gcc -std=c54 foo.c issues 2 identical errors).
The issue seems to be that some options like -W* or -std* are both in
cpp_options and cc1_options, which means that the options are passed twice
on the command line when using integrated preprocessor).
Fix below, ok to commit?
2002-01-28 Jakub Jelinek <jakub@redhat.com>
* cppinit.c (cpp_handle_option): Add ignore argument, if it is zero,
don't ignore unrecognized -W* options.
(cpp_handle_options): Pass 1 as last argument to cpp_handle_option.
* cpplib.h (cpp_handle_option): Adjust prototype.
* gcc.c (cpp_unique_options): Split from cpp_options.
(cpp_options): Source cpp_unique_options.
(default_compilers): Use cpp_unique_options instead of cpp_options
when used together with cc1_options.
(static_specs): Add cpp_unique_options.
* c-decl.c (c_decode_options): Pass 0 as last argument to
cpp_handle_option.
* objc/lang-specs.h: Use cpp_unique_options instead of cpp_options
when used together with cc1_options.
* decl2.c (cxx_decode_option): Pass 0 as last argument to
cpp_handle_option.
* lang-specs.h: Use cpp_unique_options instead of cpp_options
when used together with cc1_options.
--- gcc/cppinit.c.jj Wed Jan 9 14:31:50 2002
+++ gcc/cppinit.c Sun Jan 27 23:37:22 2002
@@ -1317,12 +1317,14 @@ parse_option (input)
/* Handle one command-line option in (argc, argv).
Can be called multiple times, to handle multiple sets of options.
+ If ignore is non-zero, this will ignore unrecognized -W* options.
Returns number of strings consumed. */
int
-cpp_handle_option (pfile, argc, argv)
+cpp_handle_option (pfile, argc, argv, ignore)
cpp_reader *pfile;
int argc;
char **argv;
+ int ignore;
{
int i = 0;
struct cpp_pending *pend = CPP_OPTION (pfile, pending);
@@ -1733,6 +1735,8 @@ cpp_handle_option (pfile, argc, argv)
CPP_OPTION (pfile, warnings_are_errors) = 0;
else if (!strcmp (argv[i], "-Wno-system-headers"))
CPP_OPTION (pfile, warn_system_headers) = 0;
+ else if (! ignore)
+ return i;
break;
}
}
@@ -1754,7 +1758,7 @@ cpp_handle_options (pfile, argc, argv)
for (i = 0; i < argc; i += strings_processed)
{
- strings_processed = cpp_handle_option (pfile, argc - i, argv + i);
+ strings_processed = cpp_handle_option (pfile, argc - i, argv + i, 1);
if (strings_processed == 0)
break;
}
--- gcc/gcc.c.jj Fri Jan 18 19:41:37 2002
+++ gcc/gcc.c Mon Jan 28 12:54:48 2002
@@ -673,10 +673,9 @@ static const char *link_libgcc_spec = LI
static const char *trad_capable_cpp =
"%{traditional|ftraditional|traditional-cpp:trad}cpp0";
-static const char *cpp_options =
+static const char *cpp_unique_options =
"%{C:%{!E:%eGNU C does not support -C without using -E}}\
- %{std*} %{nostdinc*}\
- %{C} %{v} %{I*} %{P} %{$} %I\
+ %{nostdinc*} %{C} %{v} %{I*} %{P} %{$} %I\
%{MD:-M -MF %W{!o: %b.d}%W{o*:%.d%*}}\
%{MMD:-MM -MF %W{!o: %b.d}%W{o*:%.d%*}}\
%{M} %{MM} %W{MF*} %{MG} %{MP} %{MQ*} %{MT*} %{M|MD|MM|MMD:%{o*:-MQ %*}}\
@@ -686,12 +685,17 @@ static const char *cpp_options =
%{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}\
- %{!ffreestanding:%{!fno-hosted:-D__STDC_HOSTED__=1}}\
+ %{!ffreestanding:%{!fno-hosted:-D__STDC_HOSTED__=1}} %{remap}\
+ %{g3:-dD} %{H} %C %{D*&U*&A*} %{i*} %Z %i\
+ %{E:%{!M*:%W{o*}}}";
+
+/* This contains cpp options which are common with cc1_options and are passed
+ only when preprocessing only to avoid duplication. */
+static const char *cpp_options =
+"%(cpp_unique_options) %{std*} %{d*} %{W*} %{w} %{pedantic*}\
%{fshow-column} %{fno-show-column}\
%{fleading-underscore} %{fno-leading-underscore}\
- %{fno-operator-names} %{ftabstop=*} %{remap}\
- %{g3:-dD} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*&U*&A*} %{i*} %Z %i\
- %{E:%{!M*:%W{o*}}}";
+ %{fno-operator-names} %{ftabstop=*}";
/* NB: This is shared amongst all front-ends. */
static const char *cc1_options =
@@ -840,7 +844,7 @@ static const struct compiler default_com
tradcpp0 -lang-c %{ansi:-std=c89} %(cpp_options) %{!pipe:%g.i} |\n\
cc1 -fpreprocessed %{!pipe:%g.i} %(cc1_options)}\
%{!traditional:%{!ftraditional:%{!traditional-cpp:\
- cc1 -lang-c %{ansi:-std=c89} %(cpp_options) %(cc1_options)}}}}\
+ cc1 -lang-c %{ansi:-std=c89} %(cpp_unique_options) %(cc1_options)}}}}\
%{!fsyntax-only:%(invoke_as)}}}}", 0},
{"-",
"%{!E:%e-E required when input is from standard input}\
@@ -1367,6 +1371,7 @@ static struct spec_list static_specs[] =
INIT_STATIC_SPEC ("invoke_as", &invoke_as),
INIT_STATIC_SPEC ("cpp", &cpp_spec),
INIT_STATIC_SPEC ("cpp_options", &cpp_options),
+ INIT_STATIC_SPEC ("cpp_unique_options", &cpp_unique_options),
INIT_STATIC_SPEC ("trad_capable_cpp", &trad_capable_cpp),
INIT_STATIC_SPEC ("cc1", &cc1_spec),
INIT_STATIC_SPEC ("cc1_options", &cc1_options),
--- gcc/c-decl.c.jj Fri Jan 11 14:01:06 2002
+++ gcc/c-decl.c Sun Jan 27 22:52:01 2002
@@ -463,7 +463,7 @@ c_decode_option (argc, argv)
int strings_processed;
char *p = argv[0];
- strings_processed = cpp_handle_option (parse_in, argc, argv);
+ strings_processed = cpp_handle_option (parse_in, argc, argv, 0);
if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
{
--- gcc/cpplib.h.jj Fri Jan 4 13:40:52 2002
+++ gcc/cpplib.h Sun Jan 27 22:56:00 2002
@@ -473,7 +473,7 @@ extern void cpp_set_callbacks PARAMS ((c
structure reliable. Options processing is not completed until you
call cpp_finish_options. */
extern int cpp_handle_options PARAMS ((cpp_reader *, int, char **));
-extern int cpp_handle_option PARAMS ((cpp_reader *, int, char **));
+extern int cpp_handle_option PARAMS ((cpp_reader *, int, char **, int));
extern void cpp_post_options PARAMS ((cpp_reader *));
/* This function reads the file, but does not start preprocessing. It
--- gcc/cp/decl2.c.jj Thu Jan 24 23:37:31 2002
+++ gcc/cp/decl2.c Sun Jan 27 22:52:38 2002
@@ -493,7 +493,7 @@ cxx_decode_option (argc, argv)
int strings_processed;
const char *p = argv[0];
- strings_processed = cpp_handle_option (parse_in, argc, argv);
+ strings_processed = cpp_handle_option (parse_in, argc, argv, 0);
if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
/* ignore */;
--- gcc/cp/lang-specs.h.jj Sun Jul 22 21:34:46 2001
+++ gcc/cp/lang-specs.h Mon Jan 28 12:58:45 2002
@@ -1,5 +1,5 @@
/* Definitions for specs for C++.
- Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001
+ Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
Free Software Foundation, Inc.
This file is part of GNU CC.
@@ -49,7 +49,7 @@ Boston, MA 02111-1307, USA. */
%{ansi:-D__STRICT_ANSI__ -trigraphs -$}\
%(cpp_options) %b.ii \n}\
cc1plus %{save-temps:-fpreprocessed %b.ii}\
- %{!save-temps:%(cpp_options)\
+ %{!save-temps:%(cpp_unique_options)\
%{!no-gcc:-D__GNUG__=%v1} \
%{!Wno-deprecated:-D__DEPRECATED}\
%{!fno-exceptions:-D__EXCEPTIONS}\
--- gcc/objc/lang-specs.h.jj Mon Mar 12 11:45:44 2001
+++ gcc/objc/lang-specs.h Mon Jan 28 13:00:28 2002
@@ -1,5 +1,5 @@
/* Definitions for specs for Objective-C.
- Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc.
This file is part of GNU CC.
@@ -35,7 +35,7 @@ Boston, MA 02111-1307, USA. */
tradcpp0 -lang-objc %{ansi:-std=c89} %(cpp_options) %{!pipe:%g.mi} |\n\
cc1obj -fpreprocessed %{!pipe:%g.mi} %(cc1_options) %{gen-decls}}\
%{!traditional:%{!ftraditional:%{!traditional-cpp:\
- cc1obj %{ansi:-std=c89} %(cpp_options) %(cc1_options) %{gen-decls}}}}}\
+ cc1obj %{ansi:-std=c89} %(cpp_unique_options) %(cc1_options) %{gen-decls}}}}}\
%{!fsyntax-only:%(invoke_as)}}}}", 0},
{".mi", "@objc-cpp-output", 0},
{"@objc-cpp-output",
Jakub