re PR c/40989 (-Werror= and #pragma diagnostics do not work with group flags)

2010-05-06  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR 40989
	* doc/invoke.texi (Wimplicit): Document as C only.
	* opts.c (common_handle_option): Add argument kind.
	(handle_option): Rename as read_cmdline_option. Factor out code to...
	(handle_option): ... here. New.
	(handle_options): Rename as read_cmdline_options.
	(decode_options): Update call.
	(set_option): Use option index instead of option pointer. Classify
	diagnostics correctly.
	(enable_warning_as_error): Call handle_option.
	* opts.h (set_option): Update declaration.
	(handle_option): Declare.
	* langhooks.h (struct lang_hooks): Add argument kind to
	handle_option.
	* c.opt (Wimplicit,Wimplicit-int): Initialize to -1.
	* c-opts.c (set_Wimplicit): Delete.
	(c_family_lang_mask): New static constant.
	(c_common_handle_option): Add argument kind. Use handle_option
	instead of set_Wimplicit.
	(c_common_post_options): warn_implicit and warn_implicit_int
	are disabled by default.
	* c-common.c (warn_implicit): Do not define here.
	* c-common.h (warn_implicit): Do not declare here.
	(c_common_handle_option): Update declaration.
	* lto-opts.c (lto_reissue_options): Update call to set_option.
java/
	* lang.c (java_handle_option): Add argument kind.
fortran/	
	* options.c (gfc_handle_option): Add argument kind.
	* gfortran.h (gfc_handle_option): Update declaration.
ada/
	* gcc-interface/misc.c (gnat_handle_option): Add argument kind.
testsuite/
	* gcc.dg/pr40989.c: New.

From-SVN: r159102
This commit is contained in:
Manuel López-Ibáñez 2010-05-06 10:12:36 +00:00
parent 2b90475add
commit 3734d9607e
19 changed files with 154 additions and 76 deletions

View file

@ -1,3 +1,31 @@
2010-05-06 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR 40989
* doc/invoke.texi (Wimplicit): Document as C only.
* opts.c (common_handle_option): Add argument kind.
(handle_option): Rename as read_cmdline_option. Factor out code to...
(handle_option): ... here. New.
(handle_options): Rename as read_cmdline_options.
(decode_options): Update call.
(set_option): Use option index instead of option pointer. Classify
diagnostics correctly.
(enable_warning_as_error): Call handle_option.
* opts.h (set_option): Update declaration.
(handle_option): Declare.
* langhooks.h (struct lang_hooks): Add argument kind to
handle_option.
* c.opt (Wimplicit,Wimplicit-int): Initialize to -1.
* c-opts.c (set_Wimplicit): Delete.
(c_family_lang_mask): New static constant.
(c_common_handle_option): Add argument kind. Use handle_option
instead of set_Wimplicit.
(c_common_post_options): warn_implicit and warn_implicit_int
are disabled by default.
* c-common.c (warn_implicit): Do not define here.
* c-common.h (warn_implicit): Do not declare here.
(c_common_handle_option): Update declaration.
* lto-opts.c (lto_reissue_options): Update call to set_option.
2010-05-06 Richard Guenther <rguenther@suse.de>
PR tree-optimization/43571

View file

@ -1,3 +1,8 @@
2010-05-06 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR 40989
* gcc-interface/misc.c (gnat_handle_option): Add argument kind.
2010-05-02 Giuseppe Scrivano <gscrivano@gnu.org>
* gnathtml.pl: Use 755 as mask for new directories.

View file

@ -66,7 +66,7 @@
static bool gnat_init (void);
static unsigned int gnat_init_options (unsigned int, const char **);
static int gnat_handle_option (size_t, const char *, int);
static int gnat_handle_option (size_t, const char *, int, int);
static bool gnat_post_options (const char **);
static alias_set_type gnat_get_alias_set (tree);
static void gnat_print_decl (FILE *, tree, int);
@ -184,7 +184,7 @@ gnat_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
that have been successfully decoded or 0 on failure. */
static int
gnat_handle_option (size_t scode, const char *arg, int value)
gnat_handle_option (size_t scode, const char *arg, int value, int kind ATTRIBUTE_UNUSED)
{
const struct cl_option *option = &cl_options[scode];
enum opt_code code = (enum opt_code) scode;

View file

@ -427,10 +427,6 @@ int flag_threadsafe_statics = 1;
int flag_pretty_templates = 1;
/* Nonzero means warn about implicit declarations. */
int warn_implicit = 1;
/* Maximum template instantiation depth. This limit exists to limit the
time it takes to notice infinite template instantiations; the default
value of 1024 is likely to be in the next C++ standard. */

View file

@ -750,10 +750,6 @@ extern int flag_threadsafe_statics;
extern int flag_pretty_templates;
/* Nonzero means warn about implicit declarations. */
extern int warn_implicit;
/* Warn about using __null (as NULL in C++) as sentinel. For code compiled
with GCC this doesn't matter as __null is guaranteed to have the right
size. */
@ -827,7 +823,7 @@ extern void set_Wformat (int);
extern tree handle_format_attribute (tree *, tree, tree, int, bool *);
extern tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
extern bool attribute_takes_identifier_p (const_tree);
extern int c_common_handle_option (size_t code, const char *arg, int value);
extern int c_common_handle_option (size_t code, const char *arg, int value, int kind);
extern bool c_common_missing_argument (const char *opt, size_t code);
extern tree c_common_type_for_mode (enum machine_mode, int);
extern tree c_common_type_for_size (unsigned int, int);

View file

@ -106,7 +106,6 @@ static size_t deferred_count;
/* Number of deferred options scanned for -include. */
static size_t include_cursor;
static void set_Wimplicit (int);
static void handle_OPT_d (const char *);
static void set_std_cxx98 (int);
static void set_std_cxx0x (int);
@ -135,6 +134,10 @@ static struct deferred_opt
const char *arg;
} *deferred_opts;
static const unsigned int
c_family_lang_mask = (CL_C | CL_CXX | CL_ObjC | CL_ObjCXX);
/* Complain that switch CODE expects an argument but none was
provided. OPT was the command-line option. Return FALSE to get
the default message in opts.c, TRUE if we provide a specialized
@ -349,7 +352,8 @@ c_common_init_options (unsigned int argc, const char **argv)
invalid, a negative number to prevent language-independent
processing in toplev.c (a hack necessary for the short-term). */
int
c_common_handle_option (size_t scode, const char *arg, int value)
c_common_handle_option (size_t scode, const char *arg, int value,
int kind)
{
const struct cl_option *option = &cl_options[scode];
enum opt_code code = (enum opt_code) scode;
@ -362,7 +366,7 @@ c_common_handle_option (size_t scode, const char *arg, int value)
switch (code)
{
default:
if (cl_options[code].flags & (CL_C | CL_CXX | CL_ObjC | CL_ObjCXX))
if (cl_options[code].flags & c_family_lang_mask)
{
if ((option->flags & CL_TARGET)
&& ! targetcm.handle_c_option (scode, arg, value))
@ -471,7 +475,7 @@ c_common_handle_option (size_t scode, const char *arg, int value)
case OPT_Wall:
warn_unused = value;
set_Wformat (value);
set_Wimplicit (value);
handle_option (OPT_Wimplicit, value, NULL, c_family_lang_mask, kind);
warn_char_subscripts = value;
warn_missing_braces = value;
warn_parentheses = value;
@ -569,7 +573,13 @@ c_common_handle_option (size_t scode, const char *arg, int value)
break;
case OPT_Wimplicit:
set_Wimplicit (value);
gcc_assert (value == 0 || value == 1);
if (warn_implicit_int == -1)
handle_option (OPT_Wimplicit_int, value, NULL,
c_family_lang_mask, kind);
if (warn_implicit_function_declaration == -1)
handle_option (OPT_Wimplicit_function_declaration, value, NULL,
c_family_lang_mask, kind);
break;
case OPT_Wimport:
@ -1246,6 +1256,12 @@ c_common_post_options (const char **pfilename)
"-Wformat-security ignored without -Wformat");
}
if (warn_implicit == -1)
warn_implicit = 0;
if (warn_implicit_int == -1)
warn_implicit_int = 0;
/* -Wimplicit-function-declaration is enabled by default for C99. */
if (warn_implicit_function_declaration == -1)
warn_implicit_function_declaration = flag_isoc99;
@ -1766,15 +1782,6 @@ set_std_cxx0x (int iso)
cxx_dialect = cxx0x;
}
/* Handle setting implicit to ON. */
static void
set_Wimplicit (int on)
{
warn_implicit = on;
warn_implicit_int = on;
warn_implicit_function_declaration = on;
}
/* Args to -d specify what to dump. Silently ignore
unrecognized options; they may be aimed at toplev.c. */
static void

View file

@ -263,14 +263,15 @@ C ObjC C++ ObjC++ Var(warn_init_self) Warning
Warn about variables which are initialized to themselves
Wimplicit
C ObjC C++ ObjC++ Warning
C ObjC Var(warn_implicit) Init(-1) Warning
Warn about implicit declarations
Wimplicit-function-declaration
C ObjC Var(warn_implicit_function_declaration) Init(-1) Warning
Warn about implicit function declarations
Wimplicit-int
C ObjC Var(warn_implicit_int) Warning
C ObjC Var(warn_implicit_int) Init(-1) Warning
Warn when a declaration does not specify a type
Wimport

View file

@ -2901,8 +2901,8 @@ Options} and @ref{Objective-C and Objective-C++ Dialect Options}.
-Wc++0x-compat @gol
-Wchar-subscripts @gol
-Wenum-compare @r{(in C/Objc; this is on by default in C++)} @gol
-Wimplicit-int @gol
-Wimplicit-function-declaration @gol
-Wimplicit-int @r{(C and Objective-C only)} @gol
-Wimplicit-function-declaration @r{(C and Objective-C only)} @gol
-Wcomment @gol
-Wformat @gol
-Wmain @r{(only for C/ObjC and unless} @option{-ffreestanding}@r{)} @gol
@ -3145,7 +3145,7 @@ enabled by default and it is made into an error by
@option{-pedantic-errors}. This warning is also enabled by
@option{-Wall}.
@item -Wimplicit
@item -Wimplicit @r{(C and Objective-C only)}
@opindex Wimplicit
@opindex Wno-implicit
Same as @option{-Wimplicit-int} and @option{-Wimplicit-function-declaration}.

View file

@ -1,4 +1,10 @@
2010-05-0 Tobias Burnus <burnus@net-b.de>
2010-05-06 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR 40989
* options.c (gfc_handle_option): Add argument kind.
* gfortran.h (gfc_handle_option): Update declaration.
2010-05-06 Tobias Burnus <burnus@net-b.de>
PR fortran/43985
* trans-types.c (gfc_sym_type): Mark Cray pointees as

View file

@ -2310,7 +2310,7 @@ int get_c_kind (const char *, CInteropKind_t *);
/* options.c */
unsigned int gfc_init_options (unsigned int, const char **);
int gfc_handle_option (size_t, const char *, int);
int gfc_handle_option (size_t, const char *, int, int);
bool gfc_post_options (const char **);
/* f95-lang.c */

View file

@ -532,7 +532,8 @@ gfc_handle_runtime_check_option (const char *arg)
recognized and handled. */
int
gfc_handle_option (size_t scode, const char *arg, int value)
gfc_handle_option (size_t scode, const char *arg, int value,
int kind ATTRIBUTE_UNUSED)
{
int result = 1;
enum opt_code code = (enum opt_code) scode;

View file

@ -1,3 +1,8 @@
2010-05-06 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR 40989
* lang.c (java_handle_option): Add argument kind.
2010-04-18 Eric Botcazou <ebotcazou@adacore.com>
* decl.c (java_init_decl_processing): Remove argument in call to

View file

@ -52,7 +52,7 @@ static void java_finish (void);
static unsigned int java_init_options (unsigned int, const char **);
static bool java_post_options (const char **);
static int java_handle_option (size_t scode, const char *arg, int value);
static int java_handle_option (size_t scode, const char *arg, int value, int kind);
static void put_decl_string (const char *, int);
static void put_decl_node (tree, int);
static void java_print_error_function (diagnostic_context *, const char *,
@ -175,7 +175,8 @@ struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
* return 0, but do not complain if the option is not recognized.
*/
static int
java_handle_option (size_t scode, const char *arg, int value)
java_handle_option (size_t scode, const char *arg, int value,
int kind ATTRIBUTE_UNUSED)
{
enum opt_code code = (enum opt_code) scode;

View file

@ -283,7 +283,7 @@ struct lang_hooks
Return 1 if the switch is valid, 0 if invalid, and -1 if it's
valid and should not be treated as language-independent too. */
int (*handle_option) (size_t code, const char *arg, int value);
int (*handle_option) (size_t code, const char *arg, int value, int kind);
/* Return false to use the default complaint about a missing
argument, otherwise output a complaint and return true. */

View file

@ -383,7 +383,7 @@ lto_reissue_options (void)
const struct cl_option *option = &cl_options[o->code];
if (option->flag_var)
set_option (option, o->value, o->arg);
set_option (o->code, o->value, o->arg, 0 /*DK_UNSPECIFIED*/);
if (o->type == CL_TARGET)
targetm.handle_option (o->code, o->arg, o->value);

View file

@ -372,13 +372,11 @@ const char **in_fnames;
unsigned num_in_fnames;
static int common_handle_option (size_t scode, const char *arg, int value,
unsigned int lang_mask);
unsigned int lang_mask, int kind);
static void handle_param (const char *);
static unsigned int handle_option (const char **argv, unsigned int lang_mask);
static char *write_langs (unsigned int lang_mask);
static void complain_wrong_lang (const char *, const struct cl_option *,
unsigned int lang_mask);
static void handle_options (unsigned int, const char **, unsigned int);
static void set_debug_level (enum debug_info_type type, int extended,
const char *arg);
@ -485,10 +483,51 @@ void print_ignored_options (void)
input_location = saved_loc;
}
/* Handle option OPT_INDEX, and argument ARG, for the language
indicated by LANG_MASK. VALUE is true, unless no- form of an -f or
-W option was given. KIND is the diagnostic_t if this is a
diagnostics option, DK_UNSPECIFIED otherwise. Returns false if the
switch was invalid. */
bool
handle_option (int opt_index, int value, const char *arg,
unsigned int lang_mask, int kind)
{
const struct cl_option *option = &cl_options[opt_index];
if (option->flag_var)
set_option (opt_index, value, arg, kind);
if (option->flags & lang_mask)
{
if (lang_hooks.handle_option (opt_index, arg, value, kind) == 0)
return false;
else
lto_register_user_option (opt_index, arg, value, lang_mask);
}
if (option->flags & CL_COMMON)
{
if (common_handle_option (opt_index, arg, value, lang_mask, kind) == 0)
return false;
else
lto_register_user_option (opt_index, arg, value, CL_COMMON);
}
if (option->flags & CL_TARGET)
{
if (!targetm.handle_option (opt_index, arg, value))
return false;
else
lto_register_user_option (opt_index, arg, value, CL_TARGET);
}
return true;
}
/* Handle the switch beginning at ARGV for the language indicated by
LANG_MASK. Returns the number of switches consumed. */
static unsigned int
handle_option (const char **argv, unsigned int lang_mask)
read_cmdline_option (const char **argv, unsigned int lang_mask)
{
size_t opt_index;
const char *opt, *arg = 0;
@ -609,32 +648,8 @@ handle_option (const char **argv, unsigned int lang_mask)
}
}
if (option->flag_var)
set_option (option, value, arg);
if (option->flags & lang_mask)
{
if (lang_hooks.handle_option (opt_index, arg, value) == 0)
result = 0;
else
lto_register_user_option (opt_index, arg, value, lang_mask);
}
if (result && (option->flags & CL_COMMON))
{
if (common_handle_option (opt_index, arg, value, lang_mask) == 0)
result = 0;
else
lto_register_user_option (opt_index, arg, value, CL_COMMON);
}
if (result && (option->flags & CL_TARGET))
{
if (!targetm.handle_option (opt_index, arg, value))
result = 0;
else
lto_register_user_option (opt_index, arg, value, CL_TARGET);
}
if (!handle_option (opt_index, value, arg, lang_mask, DK_UNSPECIFIED))
result = 0;
done:
if (dup)
@ -735,7 +750,7 @@ flag_instrument_functions_exclude_p (tree fndecl)
contains has a single bit set representing the current
language. */
static void
handle_options (unsigned int argc, const char **argv, unsigned int lang_mask)
read_cmdline_options (unsigned int argc, const char **argv, unsigned int lang_mask)
{
unsigned int n, i;
@ -757,7 +772,7 @@ handle_options (unsigned int argc, const char **argv, unsigned int lang_mask)
continue;
}
n = handle_option (argv + i, lang_mask);
n = read_cmdline_option (argv + i, lang_mask);
if (!n)
{
@ -973,7 +988,7 @@ decode_options (unsigned int argc, const char **argv)
OPTIMIZATION_OPTIONS (optimize, optimize_size);
#endif
handle_options (argc, argv, lang_mask);
read_cmdline_options (argc, argv, lang_mask);
if (dump_base_name && ! IS_ABSOLUTE_PATH (dump_base_name))
{
@ -1467,7 +1482,7 @@ print_specific_help (unsigned int include_flags,
static int
common_handle_option (size_t scode, const char *arg, int value,
unsigned int lang_mask)
unsigned int lang_mask, int kind ATTRIBUTE_UNUSED)
{
static bool verbose = false;
enum opt_code code = (enum opt_code) scode;
@ -2376,8 +2391,10 @@ get_option_state (int option, struct cl_option_state *state)
/* Set *OPTION according to VALUE and ARG. */
void
set_option (const struct cl_option *option, int value, const char *arg)
set_option (int opt_index, int value, const char *arg, int kind)
{
const struct cl_option *option = &cl_options[opt_index];
if (!option->flag_var)
return;
@ -2407,6 +2424,9 @@ set_option (const struct cl_option *option, int value, const char *arg)
*(const char **) option->flag_var = arg;
break;
}
if ((diagnostic_t)kind != DK_UNSPECIFIED)
diagnostic_classify_diagnostic (global_dc, opt_index, (diagnostic_t)kind);
}
@ -2450,8 +2470,8 @@ enable_warning_as_error (const char *arg, int value, unsigned int lang_mask)
const struct cl_option * const option = cl_options + option_index;
/* -Werror=foo implies -Wfoo. */
if (option->var_type == CLVC_BOOLEAN && option->flag_var)
*(int *) option->flag_var = 1;
if (option->var_type == CLVC_BOOLEAN)
handle_option (option_index, value, arg, lang_mask, (int)kind);
if (warning_as_error_callback)
warning_as_error_callback (option_index);

View file

@ -103,8 +103,9 @@ extern void prune_options (int *argcp, char ***argvp);
extern void decode_options (unsigned int argc, const char **argv);
extern int option_enabled (int opt_idx);
extern bool get_option_state (int, struct cl_option_state *);
extern void set_option (const struct cl_option *, int, const char *);
extern void set_option (int opt_index, int value, const char *arg, int);
bool handle_option (int opt_index, int value, const char *arg,
unsigned int lang_mask, int kind);
extern void register_warning_as_error_callback (void (*callback) (int));
extern void enable_warning_as_error (const char *arg, int value,
unsigned int lang_mask);

View file

@ -1,3 +1,8 @@
2010-05-06 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR 40989
* gcc.dg/pr40989.c: New.
2010-05-06 Richard Guenther <rguenther@suse.de>
PR tree-optimization/43934

View file

@ -0,0 +1,6 @@
/* { dg-do compile } */
/* { dg-options "-Werror=implicit" } */
int main() {
return pippo(); /* { dg-error "" } */
}
/* { dg-message "warnings being treated as errors" "" { target *-*-* } 0 } */