Message ID | Pine.LNX.4.64.1010051401560.23544@digraph.polyomino.org.uk |
---|---|
State | New |
Headers | show |
On Tue, Oct 5, 2010 at 4:02 PM, Joseph S. Myers <joseph@codesourcery.com> wrote: > I noted in <http://gcc.gnu.org/ml/gcc-patches/2010-09/msg02362.html> > that one remaining use of global state in functions in opts-common.c > was direct use of global_dc for adjusting state of diagnostic > options. > > This patch fixes this by passing a diagnostic context to various > functions; the functions in opts-common.c should now be usable for > processing multiple independent sets of options in a single > compilation, although much still needs to be done for the functions in > opts.c and elsewhere. The idea is that when options structures other > than the global one are processed in multilib selection, a NULL > diagnostic context pointer will be passed and handled appropriately. > (My expectation is that the state generally passed in option handling > will be the options structure, the structure for which options were > explicitly passed and the diagnostic context, with other state that > changes during option processing, such as --param state, moving into > the options structure or not being set up until after the main option > processing. It is not a problem that the global diagnostic context is > implicitly used in diagnostics for bad options, since if the options > associated with any multilib are generating diagnostics then your > compiler configuration is seriously broken anyway.) > > Enough random headers were already declaring "struct > diagnostic_context;" that rather than add to the set I put this type > and the diagnostic_context typedef in coretypes.h, removed the random > declarations and made places that previously used the struct name > consistently use the typedef. > > Bootstrapped with no regressions on x86_64-unknown-linux-gnu. OK to > commit? Ok. Thanks, Richard. > 2010-10-05 Joseph Myers <joseph@codesourcery.com> > > * opts-common.c (handle_option, handle_generated_option, > read_cmdline_option, set_option): Add diagnostic_context > parameter. Update calls among these functions. > (set_option): Don't use global_dc. > * opts.c (read_cmdline_options): Pass global_dc to > read_cmdline_option. > (decode_options): Pass global_dc to enable_warning_as_error. > (common_handle_option): Pass global_dc to enable_warning_as_error. > (enable_warning_as_error): Add diagnostic_context parameter. > Document parameters. Don't use global_dc. Pass > diagnostic_context parameter to handle_generated_option. > * opts.h (set_option, handle_option, handle_generated_option, > read_cmdline_option, enable_warning_as_error): Add > diagnostic_context parameter. > * Makefile.in (lto-opts.o): Update dependencies. > * coretypes.h (struct diagnostic_context, diagnostic_context): > Declare here. > * diagnostic.h (diagnostic_context): Don't declare typedef here. > * gcc.c (process_command): Pass global_dc to read_cmdline_option. > * langhooks-def.h (struct diagnostic_context): Don't declare here. > (lhd_print_error_function, lhd_initialize_diagnostics): Declare > using diagnostic_context typedef. > * langhooks.c (lhd_initialize_diagnostics): Declare using > diagnostic_context typedef. > * langhooks.h (struct diagnostic_context): Don't declare here. > (initialize_diagnostics, print_error_function): Declare using > diagnostic_context typedef. > * lto-opts.c: Include diagnostic.h. > (lto_reissue_options): Pass global_dc to set_option. Pass > DK_UNSPECIFIED not 0. > * plugin.c (plugins_internal_error_function): Declare using > diagnostic_context typedef. > * plugin.h (struct diagnostic_context): Don't declare here. > (plugins_internal_error_function): Declare using > diagnostic_context typedef. > > c-family: > 2010-10-05 Joseph Myers <joseph@codesourcery.com> > > * c-common.h (struct diagnostic_context): Don't declare here. > (c_common_initialize_diagnostics): Declare using > diagnostic_context typedef. > * c-opts.c (c_common_handle_option): Pass global_dc to > handle_generated_option. > > cp: > 2010-10-05 Joseph Myers <joseph@codesourcery.com> > > * cp-tree.h (cxx_print_error_function, > cxx_initialize_diagnostics): Declare using diagnostic_context > typedef. > > Index: gcc/opts-common.c > =================================================================== > --- gcc/opts-common.c (revision 164960) > +++ gcc/opts-common.c (working copy) > @@ -804,7 +804,8 @@ keep: > option, DK_UNSPECIFIED otherwise. GENERATED_P is true for an > option generated as part of processing another option or otherwise > generated internally, false for one explicitly passed by the user. > - Returns false if the switch was invalid. */ > + Returns false if the switch was invalid. DC is the diagnostic > + context for options affecting diagnostics state, or NULL. */ > > bool > handle_option (struct gcc_options *opts, > @@ -812,7 +813,7 @@ handle_option (struct gcc_options *opts, > const struct cl_decoded_option *decoded, > unsigned int lang_mask, int kind, > const struct cl_option_handlers *handlers, > - bool generated_p) > + bool generated_p, diagnostic_context *dc) > { > size_t opt_index = decoded->opt_index; > const char *arg = decoded->arg; > @@ -823,7 +824,7 @@ handle_option (struct gcc_options *opts, > > if (flag_var) > set_option (opts, (generated_p ? NULL : opts_set), > - opt_index, value, arg, kind); > + opt_index, value, arg, kind, dc); > > for (i = 0; i < handlers->num_handlers; i++) > if (option->flags & handlers->handlers[i].mask) > @@ -849,13 +850,14 @@ handle_generated_option (struct gcc_opti > struct gcc_options *opts_set, > size_t opt_index, const char *arg, int value, > unsigned int lang_mask, int kind, > - const struct cl_option_handlers *handlers) > + const struct cl_option_handlers *handlers, > + diagnostic_context *dc) > { > struct cl_decoded_option decoded; > > generate_option (opt_index, arg, value, lang_mask, &decoded); > return handle_option (opts, opts_set, &decoded, lang_mask, kind, handlers, > - true); > + true, dc); > } > > /* Fill in *DECODED with an option described by OPT_INDEX, ARG and > @@ -915,14 +917,16 @@ generate_option_input_file (const char * > > /* Handle the switch DECODED for the language indicated by LANG_MASK, > using the handlers in *HANDLERS and setting fields in OPTS and > - OPTS_SET. */ > + OPTS_SET and using diagnostic context DC (if not NULL) for > + diagnostic options. */ > > void > read_cmdline_option (struct gcc_options *opts, > struct gcc_options *opts_set, > struct cl_decoded_option *decoded, > unsigned int lang_mask, > - const struct cl_option_handlers *handlers) > + const struct cl_option_handlers *handlers, > + diagnostic_context *dc) > { > const struct cl_option *option; > const char *opt = decoded->orig_option_with_args_text; > @@ -974,16 +978,19 @@ read_cmdline_option (struct gcc_options > gcc_assert (!decoded->errors); > > if (!handle_option (opts, opts_set, decoded, lang_mask, DK_UNSPECIFIED, > - handlers, false)) > + handlers, false, dc)) > error ("unrecognized command line option %qs", opt); > } > > /* Set any field in OPTS, and OPTS_SET if not NULL, for option > - OPT_INDEX according to VALUE and ARG, diagnostic kind KIND. */ > + OPT_INDEX according to VALUE and ARG, diagnostic kind KIND, using > + diagnostic context DC if not NULL for diagnostic > + classification. */ > > void > set_option (struct gcc_options *opts, struct gcc_options *opts_set, > - int opt_index, int value, const char *arg, int kind) > + int opt_index, int value, const char *arg, int kind, > + diagnostic_context *dc) > { > const struct cl_option *option = &cl_options[opt_index]; > void *flag_var = option_flag_var (opt_index, opts); > @@ -1028,8 +1035,9 @@ set_option (struct gcc_options *opts, st > break; > } > > - if ((diagnostic_t) kind != DK_UNSPECIFIED) > - diagnostic_classify_diagnostic (global_dc, opt_index, (diagnostic_t) kind, > + if ((diagnostic_t) kind != DK_UNSPECIFIED > + && dc != NULL) > + diagnostic_classify_diagnostic (dc, opt_index, (diagnostic_t) kind, > UNKNOWN_LOCATION); > } > > Index: gcc/c-family/c-opts.c > =================================================================== > --- gcc/c-family/c-opts.c (revision 164960) > +++ gcc/c-family/c-opts.c (working copy) > @@ -438,7 +438,7 @@ c_common_handle_option (size_t scode, co > set_Wformat (value); > handle_generated_option (&global_options, &global_options_set, > OPT_Wimplicit, NULL, value, > - c_family_lang_mask, kind, handlers); > + c_family_lang_mask, kind, handlers, global_dc); > warn_char_subscripts = value; > warn_missing_braces = value; > warn_parentheses = value; > @@ -533,11 +533,13 @@ c_common_handle_option (size_t scode, co > if (warn_implicit_int == -1) > handle_generated_option (&global_options, &global_options_set, > OPT_Wimplicit_int, NULL, value, > - c_family_lang_mask, kind, handlers); > + c_family_lang_mask, kind, handlers, > + global_dc); > if (warn_implicit_function_declaration == -1) > handle_generated_option (&global_options, &global_options_set, > OPT_Wimplicit_function_declaration, NULL, > - value, c_family_lang_mask, kind, handlers); > + value, c_family_lang_mask, kind, handlers, > + global_dc); > break; > > case OPT_Winvalid_pch: > Index: gcc/c-family/c-common.h > =================================================================== > --- gcc/c-family/c-common.h (revision 164960) > +++ gcc/c-family/c-common.h (working copy) > @@ -740,10 +740,8 @@ extern void set_compound_literal_name (t > > extern tree build_va_arg (location_t, tree, tree); > > -struct diagnostic_context; > - > extern unsigned int c_common_option_lang_mask (void); > -extern void c_common_initialize_diagnostics (struct diagnostic_context *); > +extern void c_common_initialize_diagnostics (diagnostic_context *); > extern bool c_common_complain_wrong_lang_p (const struct cl_option *); > extern void c_common_init_options (unsigned int, struct cl_decoded_option *); > extern bool c_common_post_options (const char **); > Index: gcc/diagnostic.h > =================================================================== > --- gcc/diagnostic.h (revision 164960) > +++ gcc/diagnostic.h (working copy) > @@ -52,7 +52,6 @@ typedef struct diagnostic_classification > } diagnostic_classification_change_t; > > /* Forward declarations. */ > -typedef struct diagnostic_context diagnostic_context; > typedef void (*diagnostic_starter_fn) (diagnostic_context *, > diagnostic_info *); > typedef diagnostic_starter_fn diagnostic_finalizer_fn; > Index: gcc/gcc.c > =================================================================== > --- gcc/gcc.c (revision 164960) > +++ gcc/gcc.c (working copy) > @@ -3806,7 +3806,8 @@ process_command (unsigned int decoded_op > } > > read_cmdline_option (&global_options, &global_options_set, > - decoded_options + j, CL_DRIVER, &handlers); > + decoded_options + j, CL_DRIVER, &handlers, > + global_dc); > } > > /* If -save-temps=obj and -o name, create the prefix to use for %b. > Index: gcc/cp/cp-tree.h > =================================================================== > --- gcc/cp/cp-tree.h (revision 164960) > +++ gcc/cp/cp-tree.h (working copy) > @@ -5430,7 +5430,7 @@ extern void cxx_print_xnode (FILE *, t > extern void cxx_print_decl (FILE *, tree, int); > extern void cxx_print_type (FILE *, tree, int); > extern void cxx_print_identifier (FILE *, tree, int); > -extern void cxx_print_error_function (struct diagnostic_context *, > +extern void cxx_print_error_function (diagnostic_context *, > const char *, > struct diagnostic_info *); > > @@ -5594,7 +5594,7 @@ extern alias_set_type cxx_get_alias_set > extern bool cxx_warn_unused_global_decl (const_tree); > extern size_t cp_tree_size (enum tree_code); > extern bool cp_var_mod_type_p (tree, tree); > -extern void cxx_initialize_diagnostics (struct diagnostic_context *); > +extern void cxx_initialize_diagnostics (diagnostic_context *); > extern int cxx_types_compatible_p (tree, tree); > extern void init_shadowed_var_for_decl (void); > > Index: gcc/opts.c > =================================================================== > --- gcc/opts.c (revision 164960) > +++ gcc/opts.c (working copy) > @@ -639,7 +639,8 @@ read_cmdline_options (struct cl_decoded_ > } > > read_cmdline_option (&global_options, &global_options_set, > - decoded_options + i, lang_mask, handlers); > + decoded_options + i, lang_mask, handlers, > + global_dc); > } > } > > @@ -879,7 +880,8 @@ decode_options (unsigned int argc, const > } > > /* Enable -Werror=coverage-mismatch by default */ > - enable_warning_as_error ("coverage-mismatch", 1, lang_mask, &handlers); > + enable_warning_as_error ("coverage-mismatch", 1, lang_mask, &handlers, > + global_dc); > > if (first_time_p) > { > @@ -1606,7 +1608,7 @@ common_handle_option (struct gcc_options > break; > > case OPT_Werror_: > - enable_warning_as_error (arg, value, lang_mask, handlers); > + enable_warning_as_error (arg, value, lang_mask, handlers, global_dc); > break; > > case OPT_Wlarger_than_: > @@ -2284,12 +2286,15 @@ register_warning_as_error_callback (void > warning_as_error_callback = callback; > } > > -/* Enable a warning option as an error. This is used by -Werror= and > - also by legacy Werror-implicit-function-declaration. */ > +/* Enable (or disable if VALUE is 0) a warning option ARG (language > + mask LANG_MASK, option handlers HANDLERS) as an error for > + diagnostic context DC (possibly NULL). This is used by > + -Werror=. */ > > void > enable_warning_as_error (const char *arg, int value, unsigned int lang_mask, > - const struct cl_option_handlers *handlers) > + const struct cl_option_handlers *handlers, > + diagnostic_context *dc) > { > char *new_option; > int option_index; > @@ -2311,8 +2316,9 @@ enable_warning_as_error (const char *arg > option_index = option->alias_target; > if (option_index == OPT_SPECIAL_ignore) > return; > - diagnostic_classify_diagnostic (global_dc, option_index, kind, > - UNKNOWN_LOCATION); > + if (dc) > + diagnostic_classify_diagnostic (dc, option_index, kind, > + UNKNOWN_LOCATION); > if (kind == DK_ERROR) > { > const struct cl_option * const option = cl_options + option_index; > @@ -2321,7 +2327,8 @@ enable_warning_as_error (const char *arg > if (option->var_type == CLVC_BOOLEAN) > handle_generated_option (&global_options, &global_options_set, > option_index, NULL, value, lang_mask, > - (int)kind, handlers); > + (int)kind, handlers, > + dc); > > if (warning_as_error_callback) > warning_as_error_callback (option_index); > Index: gcc/opts.h > =================================================================== > --- gcc/opts.h (revision 164960) > +++ gcc/opts.h (working copy) > @@ -216,19 +216,21 @@ extern bool get_option_state (struct gcc > struct cl_option_state *); > extern void set_option (struct gcc_options *opts, > struct gcc_options *opts_set, > - int opt_index, int value, const char *arg, int); > + int opt_index, int value, const char *arg, int kind, > + diagnostic_context *dc); > extern void *option_flag_var (int opt_index, struct gcc_options *opts); > bool handle_option (struct gcc_options *opts, > struct gcc_options *opts_set, > const struct cl_decoded_option *decoded, > unsigned int lang_mask, int kind, > const struct cl_option_handlers *handlers, > - bool generated_p); > + bool generated_p, diagnostic_context *dc); > bool handle_generated_option (struct gcc_options *opts, > struct gcc_options *opts_set, > size_t opt_index, const char *arg, int value, > unsigned int lang_mask, int kind, > - const struct cl_option_handlers *handlers); > + const struct cl_option_handlers *handlers, > + diagnostic_context *dc); > void generate_option (size_t opt_index, const char *arg, int value, > unsigned int lang_mask, > struct cl_decoded_option *decoded); > @@ -238,10 +240,12 @@ extern void read_cmdline_option (struct > struct gcc_options *opts_set, > struct cl_decoded_option *decoded, > unsigned int lang_mask, > - const struct cl_option_handlers *handlers); > + const struct cl_option_handlers *handlers, > + diagnostic_context *dc); > 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, > - const struct cl_option_handlers *handlers); > + const struct cl_option_handlers *handlers, > + diagnostic_context *dc); > extern void print_ignored_options (void); > #endif > Index: gcc/langhooks.c > =================================================================== > --- gcc/langhooks.c (revision 164960) > +++ gcc/langhooks.c (working copy) > @@ -333,7 +333,7 @@ write_global_declarations (void) > > /* Called to perform language-specific initialization of CTX. */ > void > -lhd_initialize_diagnostics (struct diagnostic_context *ctx ATTRIBUTE_UNUSED) > +lhd_initialize_diagnostics (diagnostic_context *ctx ATTRIBUTE_UNUSED) > { > } > > Index: gcc/langhooks.h > =================================================================== > --- gcc/langhooks.h (revision 164960) > +++ gcc/langhooks.h (working copy) > @@ -23,7 +23,6 @@ along with GCC; see the file COPYING3. > > /* This file should be #include-d after tree.h. */ > > -struct diagnostic_context; > struct diagnostic_info; > > struct gimplify_omp_ctx; > @@ -275,7 +274,7 @@ struct lang_hooks > > /* Callback used to perform language-specific initialization for the > global diagnostic context structure. */ > - void (*initialize_diagnostics) (struct diagnostic_context *); > + void (*initialize_diagnostics) (diagnostic_context *); > > /* Return true if a warning should be given about option OPTION, > which is for the wrong language, false if it should be quietly > @@ -374,7 +373,7 @@ struct lang_hooks > int (*types_compatible_p) (tree x, tree y); > > /* Called by report_error_function to print out function name. */ > - void (*print_error_function) (struct diagnostic_context *, const char *, > + void (*print_error_function) (diagnostic_context *, const char *, > struct diagnostic_info *); > > /* Convert a character from the host's to the target's character > Index: gcc/coretypes.h > =================================================================== > --- gcc/coretypes.h (revision 164960) > +++ gcc/coretypes.h (working copy) > @@ -70,6 +70,8 @@ struct cl_optimization; > struct cl_option; > struct cl_decoded_option; > struct cl_option_handlers; > +struct diagnostic_context; > +typedef struct diagnostic_context diagnostic_context; > struct gimple_seq_d; > typedef struct gimple_seq_d *gimple_seq; > typedef const struct gimple_seq_d *const_gimple_seq; > Index: gcc/plugin.c > =================================================================== > --- gcc/plugin.c (revision 164960) > +++ gcc/plugin.c (working copy) > @@ -830,7 +830,7 @@ warn_if_plugins (void) > /* Likewise, as a callback from the diagnostics code. */ > > void > -plugins_internal_error_function (struct diagnostic_context *context ATTRIBUTE_UNUSED, > +plugins_internal_error_function (diagnostic_context *context ATTRIBUTE_UNUSED, > const char *msgid ATTRIBUTE_UNUSED, > va_list *ap ATTRIBUTE_UNUSED) > { > Index: gcc/plugin.h > =================================================================== > --- gcc/plugin.h (revision 164960) > +++ gcc/plugin.h (working copy) > @@ -23,7 +23,6 @@ along with GCC; see the file COPYING3. > #include "gcc-plugin.h" > > struct attribute_spec; > -struct diagnostic_context; > > extern void add_new_plugin (const char *); > extern void parse_plugin_arg_opt (const char *); > @@ -33,7 +32,7 @@ extern bool plugins_active_p (void); > extern void dump_active_plugins (FILE *); > extern void debug_active_plugins (void); > extern void warn_if_plugins (void); > -extern void plugins_internal_error_function (struct diagnostic_context *, > +extern void plugins_internal_error_function (diagnostic_context *, > const char *, va_list *); > extern void print_plugins_versions (FILE *file, const char *indent); > extern void print_plugins_help (FILE *file, const char *indent); > Index: gcc/Makefile.in > =================================================================== > --- gcc/Makefile.in (revision 164960) > +++ gcc/Makefile.in (working copy) > @@ -2325,7 +2325,7 @@ lto-symtab.o: lto-symtab.c $(CONFIG_H) $ > $(LTO_STREAMER_H) $(LINKER_PLUGIN_API_H) gt-lto-symtab.h > lto-opts.o: lto-opts.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TREE_H) \ > $(HASHTAB_H) $(GGC_H) $(BITMAP_H) $(FLAGS_H) opts.h options.h \ > - $(TARGET_H) $(TOPLEV_H) $(DIAGNOSTIC_CORE_H) $(LTO_STREAMER_H) > + $(TARGET_H) $(TOPLEV_H) $(DIAGNOSTIC_H) $(LTO_STREAMER_H) > lto-streamer.o: lto-streamer.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \ > $(TM_H) $(TREE_H) $(GIMPLE_H) $(BITMAP_H) $(LTO_STREAMER_H) $(FLAGS_H) \ > $(TREE_FLOW_H) $(DIAGNOSTIC_CORE_H) $(LTO_SYMTAB_H) $(TOPLEV_H) $(DIAGNOSTIC_CORE_H) > Index: gcc/lto-opts.c > =================================================================== > --- gcc/lto-opts.c (revision 164960) > +++ gcc/lto-opts.c (working copy) > @@ -31,7 +31,7 @@ along with GCC; see the file COPYING3. > #include "opts.h" > #include "options.h" > #include "target.h" > -#include "diagnostic-core.h" > +#include "diagnostic.h" > #include "toplev.h" > #include "lto-streamer.h" > > @@ -404,7 +404,7 @@ lto_reissue_options (void) > if (flag_var) > set_option (&global_options, &global_options_set, > o->code, o->value, o->arg, > - 0 /*DK_UNSPECIFIED*/); > + DK_UNSPECIFIED, global_dc); > > if (o->type == CL_TARGET) > targetm.handle_option (o->code, o->arg, o->value); > Index: gcc/langhooks-def.h > =================================================================== > --- gcc/langhooks-def.h (revision 164960) > +++ gcc/langhooks-def.h (working copy) > @@ -24,7 +24,6 @@ along with GCC; see the file COPYING3. > > #include "hooks.h" > > -struct diagnostic_context; > struct diagnostic_info; > > /* Note to creators of new hooks: > @@ -51,7 +50,7 @@ extern void lhd_print_tree_nothing (FILE > extern const char *lhd_decl_printable_name (tree, int); > extern const char *lhd_dwarf_name (tree, int); > extern int lhd_types_compatible_p (tree, tree); > -extern void lhd_print_error_function (struct diagnostic_context *, > +extern void lhd_print_error_function (diagnostic_context *, > const char *, struct diagnostic_info *); > extern void lhd_set_decl_assembler_name (tree); > extern bool lhd_warn_unused_global_decl (const_tree); > @@ -65,7 +64,7 @@ extern tree lhd_expr_to_decl (tree, bool > extern tree lhd_builtin_function (tree); > > /* Declarations of default tree inlining hooks. */ > -extern void lhd_initialize_diagnostics (struct diagnostic_context *); > +extern void lhd_initialize_diagnostics (diagnostic_context *); > extern void lhd_init_options (unsigned int, > struct cl_decoded_option *); > extern bool lhd_complain_wrong_lang_p (const struct cl_option *); > > -- > Joseph S. Myers > joseph@codesourcery.com >
On Tue, Oct 5, 2010 at 9:02 AM, Joseph S. Myers <joseph@codesourcery.com> wrote: > Enough random headers were already declaring "struct > diagnostic_context;" that rather than add to the set I put this type > and the diagnostic_context typedef in coretypes.h, removed the random > declarations and made places that previously used the struct name > consistently use the typedef. Makes sense.
Index: gcc/opts-common.c =================================================================== --- gcc/opts-common.c (revision 164960) +++ gcc/opts-common.c (working copy) @@ -804,7 +804,8 @@ keep: option, DK_UNSPECIFIED otherwise. GENERATED_P is true for an option generated as part of processing another option or otherwise generated internally, false for one explicitly passed by the user. - Returns false if the switch was invalid. */ + Returns false if the switch was invalid. DC is the diagnostic + context for options affecting diagnostics state, or NULL. */ bool handle_option (struct gcc_options *opts, @@ -812,7 +813,7 @@ handle_option (struct gcc_options *opts, const struct cl_decoded_option *decoded, unsigned int lang_mask, int kind, const struct cl_option_handlers *handlers, - bool generated_p) + bool generated_p, diagnostic_context *dc) { size_t opt_index = decoded->opt_index; const char *arg = decoded->arg; @@ -823,7 +824,7 @@ handle_option (struct gcc_options *opts, if (flag_var) set_option (opts, (generated_p ? NULL : opts_set), - opt_index, value, arg, kind); + opt_index, value, arg, kind, dc); for (i = 0; i < handlers->num_handlers; i++) if (option->flags & handlers->handlers[i].mask) @@ -849,13 +850,14 @@ handle_generated_option (struct gcc_opti struct gcc_options *opts_set, size_t opt_index, const char *arg, int value, unsigned int lang_mask, int kind, - const struct cl_option_handlers *handlers) + const struct cl_option_handlers *handlers, + diagnostic_context *dc) { struct cl_decoded_option decoded; generate_option (opt_index, arg, value, lang_mask, &decoded); return handle_option (opts, opts_set, &decoded, lang_mask, kind, handlers, - true); + true, dc); } /* Fill in *DECODED with an option described by OPT_INDEX, ARG and @@ -915,14 +917,16 @@ generate_option_input_file (const char * /* Handle the switch DECODED for the language indicated by LANG_MASK, using the handlers in *HANDLERS and setting fields in OPTS and - OPTS_SET. */ + OPTS_SET and using diagnostic context DC (if not NULL) for + diagnostic options. */ void read_cmdline_option (struct gcc_options *opts, struct gcc_options *opts_set, struct cl_decoded_option *decoded, unsigned int lang_mask, - const struct cl_option_handlers *handlers) + const struct cl_option_handlers *handlers, + diagnostic_context *dc) { const struct cl_option *option; const char *opt = decoded->orig_option_with_args_text; @@ -974,16 +978,19 @@ read_cmdline_option (struct gcc_options gcc_assert (!decoded->errors); if (!handle_option (opts, opts_set, decoded, lang_mask, DK_UNSPECIFIED, - handlers, false)) + handlers, false, dc)) error ("unrecognized command line option %qs", opt); } /* Set any field in OPTS, and OPTS_SET if not NULL, for option - OPT_INDEX according to VALUE and ARG, diagnostic kind KIND. */ + OPT_INDEX according to VALUE and ARG, diagnostic kind KIND, using + diagnostic context DC if not NULL for diagnostic + classification. */ void set_option (struct gcc_options *opts, struct gcc_options *opts_set, - int opt_index, int value, const char *arg, int kind) + int opt_index, int value, const char *arg, int kind, + diagnostic_context *dc) { const struct cl_option *option = &cl_options[opt_index]; void *flag_var = option_flag_var (opt_index, opts); @@ -1028,8 +1035,9 @@ set_option (struct gcc_options *opts, st break; } - if ((diagnostic_t) kind != DK_UNSPECIFIED) - diagnostic_classify_diagnostic (global_dc, opt_index, (diagnostic_t) kind, + if ((diagnostic_t) kind != DK_UNSPECIFIED + && dc != NULL) + diagnostic_classify_diagnostic (dc, opt_index, (diagnostic_t) kind, UNKNOWN_LOCATION); } Index: gcc/c-family/c-opts.c =================================================================== --- gcc/c-family/c-opts.c (revision 164960) +++ gcc/c-family/c-opts.c (working copy) @@ -438,7 +438,7 @@ c_common_handle_option (size_t scode, co set_Wformat (value); handle_generated_option (&global_options, &global_options_set, OPT_Wimplicit, NULL, value, - c_family_lang_mask, kind, handlers); + c_family_lang_mask, kind, handlers, global_dc); warn_char_subscripts = value; warn_missing_braces = value; warn_parentheses = value; @@ -533,11 +533,13 @@ c_common_handle_option (size_t scode, co if (warn_implicit_int == -1) handle_generated_option (&global_options, &global_options_set, OPT_Wimplicit_int, NULL, value, - c_family_lang_mask, kind, handlers); + c_family_lang_mask, kind, handlers, + global_dc); if (warn_implicit_function_declaration == -1) handle_generated_option (&global_options, &global_options_set, OPT_Wimplicit_function_declaration, NULL, - value, c_family_lang_mask, kind, handlers); + value, c_family_lang_mask, kind, handlers, + global_dc); break; case OPT_Winvalid_pch: Index: gcc/c-family/c-common.h =================================================================== --- gcc/c-family/c-common.h (revision 164960) +++ gcc/c-family/c-common.h (working copy) @@ -740,10 +740,8 @@ extern void set_compound_literal_name (t extern tree build_va_arg (location_t, tree, tree); -struct diagnostic_context; - extern unsigned int c_common_option_lang_mask (void); -extern void c_common_initialize_diagnostics (struct diagnostic_context *); +extern void c_common_initialize_diagnostics (diagnostic_context *); extern bool c_common_complain_wrong_lang_p (const struct cl_option *); extern void c_common_init_options (unsigned int, struct cl_decoded_option *); extern bool c_common_post_options (const char **); Index: gcc/diagnostic.h =================================================================== --- gcc/diagnostic.h (revision 164960) +++ gcc/diagnostic.h (working copy) @@ -52,7 +52,6 @@ typedef struct diagnostic_classification } diagnostic_classification_change_t; /* Forward declarations. */ -typedef struct diagnostic_context diagnostic_context; typedef void (*diagnostic_starter_fn) (diagnostic_context *, diagnostic_info *); typedef diagnostic_starter_fn diagnostic_finalizer_fn; Index: gcc/gcc.c =================================================================== --- gcc/gcc.c (revision 164960) +++ gcc/gcc.c (working copy) @@ -3806,7 +3806,8 @@ process_command (unsigned int decoded_op } read_cmdline_option (&global_options, &global_options_set, - decoded_options + j, CL_DRIVER, &handlers); + decoded_options + j, CL_DRIVER, &handlers, + global_dc); } /* If -save-temps=obj and -o name, create the prefix to use for %b. Index: gcc/cp/cp-tree.h =================================================================== --- gcc/cp/cp-tree.h (revision 164960) +++ gcc/cp/cp-tree.h (working copy) @@ -5430,7 +5430,7 @@ extern void cxx_print_xnode (FILE *, t extern void cxx_print_decl (FILE *, tree, int); extern void cxx_print_type (FILE *, tree, int); extern void cxx_print_identifier (FILE *, tree, int); -extern void cxx_print_error_function (struct diagnostic_context *, +extern void cxx_print_error_function (diagnostic_context *, const char *, struct diagnostic_info *); @@ -5594,7 +5594,7 @@ extern alias_set_type cxx_get_alias_set extern bool cxx_warn_unused_global_decl (const_tree); extern size_t cp_tree_size (enum tree_code); extern bool cp_var_mod_type_p (tree, tree); -extern void cxx_initialize_diagnostics (struct diagnostic_context *); +extern void cxx_initialize_diagnostics (diagnostic_context *); extern int cxx_types_compatible_p (tree, tree); extern void init_shadowed_var_for_decl (void); Index: gcc/opts.c =================================================================== --- gcc/opts.c (revision 164960) +++ gcc/opts.c (working copy) @@ -639,7 +639,8 @@ read_cmdline_options (struct cl_decoded_ } read_cmdline_option (&global_options, &global_options_set, - decoded_options + i, lang_mask, handlers); + decoded_options + i, lang_mask, handlers, + global_dc); } } @@ -879,7 +880,8 @@ decode_options (unsigned int argc, const } /* Enable -Werror=coverage-mismatch by default */ - enable_warning_as_error ("coverage-mismatch", 1, lang_mask, &handlers); + enable_warning_as_error ("coverage-mismatch", 1, lang_mask, &handlers, + global_dc); if (first_time_p) { @@ -1606,7 +1608,7 @@ common_handle_option (struct gcc_options break; case OPT_Werror_: - enable_warning_as_error (arg, value, lang_mask, handlers); + enable_warning_as_error (arg, value, lang_mask, handlers, global_dc); break; case OPT_Wlarger_than_: @@ -2284,12 +2286,15 @@ register_warning_as_error_callback (void warning_as_error_callback = callback; } -/* Enable a warning option as an error. This is used by -Werror= and - also by legacy Werror-implicit-function-declaration. */ +/* Enable (or disable if VALUE is 0) a warning option ARG (language + mask LANG_MASK, option handlers HANDLERS) as an error for + diagnostic context DC (possibly NULL). This is used by + -Werror=. */ void enable_warning_as_error (const char *arg, int value, unsigned int lang_mask, - const struct cl_option_handlers *handlers) + const struct cl_option_handlers *handlers, + diagnostic_context *dc) { char *new_option; int option_index; @@ -2311,8 +2316,9 @@ enable_warning_as_error (const char *arg option_index = option->alias_target; if (option_index == OPT_SPECIAL_ignore) return; - diagnostic_classify_diagnostic (global_dc, option_index, kind, - UNKNOWN_LOCATION); + if (dc) + diagnostic_classify_diagnostic (dc, option_index, kind, + UNKNOWN_LOCATION); if (kind == DK_ERROR) { const struct cl_option * const option = cl_options + option_index; @@ -2321,7 +2327,8 @@ enable_warning_as_error (const char *arg if (option->var_type == CLVC_BOOLEAN) handle_generated_option (&global_options, &global_options_set, option_index, NULL, value, lang_mask, - (int)kind, handlers); + (int)kind, handlers, + dc); if (warning_as_error_callback) warning_as_error_callback (option_index); Index: gcc/opts.h =================================================================== --- gcc/opts.h (revision 164960) +++ gcc/opts.h (working copy) @@ -216,19 +216,21 @@ extern bool get_option_state (struct gcc struct cl_option_state *); extern void set_option (struct gcc_options *opts, struct gcc_options *opts_set, - int opt_index, int value, const char *arg, int); + int opt_index, int value, const char *arg, int kind, + diagnostic_context *dc); extern void *option_flag_var (int opt_index, struct gcc_options *opts); bool handle_option (struct gcc_options *opts, struct gcc_options *opts_set, const struct cl_decoded_option *decoded, unsigned int lang_mask, int kind, const struct cl_option_handlers *handlers, - bool generated_p); + bool generated_p, diagnostic_context *dc); bool handle_generated_option (struct gcc_options *opts, struct gcc_options *opts_set, size_t opt_index, const char *arg, int value, unsigned int lang_mask, int kind, - const struct cl_option_handlers *handlers); + const struct cl_option_handlers *handlers, + diagnostic_context *dc); void generate_option (size_t opt_index, const char *arg, int value, unsigned int lang_mask, struct cl_decoded_option *decoded); @@ -238,10 +240,12 @@ extern void read_cmdline_option (struct struct gcc_options *opts_set, struct cl_decoded_option *decoded, unsigned int lang_mask, - const struct cl_option_handlers *handlers); + const struct cl_option_handlers *handlers, + diagnostic_context *dc); 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, - const struct cl_option_handlers *handlers); + const struct cl_option_handlers *handlers, + diagnostic_context *dc); extern void print_ignored_options (void); #endif Index: gcc/langhooks.c =================================================================== --- gcc/langhooks.c (revision 164960) +++ gcc/langhooks.c (working copy) @@ -333,7 +333,7 @@ write_global_declarations (void) /* Called to perform language-specific initialization of CTX. */ void -lhd_initialize_diagnostics (struct diagnostic_context *ctx ATTRIBUTE_UNUSED) +lhd_initialize_diagnostics (diagnostic_context *ctx ATTRIBUTE_UNUSED) { } Index: gcc/langhooks.h =================================================================== --- gcc/langhooks.h (revision 164960) +++ gcc/langhooks.h (working copy) @@ -23,7 +23,6 @@ along with GCC; see the file COPYING3. /* This file should be #include-d after tree.h. */ -struct diagnostic_context; struct diagnostic_info; struct gimplify_omp_ctx; @@ -275,7 +274,7 @@ struct lang_hooks /* Callback used to perform language-specific initialization for the global diagnostic context structure. */ - void (*initialize_diagnostics) (struct diagnostic_context *); + void (*initialize_diagnostics) (diagnostic_context *); /* Return true if a warning should be given about option OPTION, which is for the wrong language, false if it should be quietly @@ -374,7 +373,7 @@ struct lang_hooks int (*types_compatible_p) (tree x, tree y); /* Called by report_error_function to print out function name. */ - void (*print_error_function) (struct diagnostic_context *, const char *, + void (*print_error_function) (diagnostic_context *, const char *, struct diagnostic_info *); /* Convert a character from the host's to the target's character Index: gcc/coretypes.h =================================================================== --- gcc/coretypes.h (revision 164960) +++ gcc/coretypes.h (working copy) @@ -70,6 +70,8 @@ struct cl_optimization; struct cl_option; struct cl_decoded_option; struct cl_option_handlers; +struct diagnostic_context; +typedef struct diagnostic_context diagnostic_context; struct gimple_seq_d; typedef struct gimple_seq_d *gimple_seq; typedef const struct gimple_seq_d *const_gimple_seq; Index: gcc/plugin.c =================================================================== --- gcc/plugin.c (revision 164960) +++ gcc/plugin.c (working copy) @@ -830,7 +830,7 @@ warn_if_plugins (void) /* Likewise, as a callback from the diagnostics code. */ void -plugins_internal_error_function (struct diagnostic_context *context ATTRIBUTE_UNUSED, +plugins_internal_error_function (diagnostic_context *context ATTRIBUTE_UNUSED, const char *msgid ATTRIBUTE_UNUSED, va_list *ap ATTRIBUTE_UNUSED) { Index: gcc/plugin.h =================================================================== --- gcc/plugin.h (revision 164960) +++ gcc/plugin.h (working copy) @@ -23,7 +23,6 @@ along with GCC; see the file COPYING3. #include "gcc-plugin.h" struct attribute_spec; -struct diagnostic_context; extern void add_new_plugin (const char *); extern void parse_plugin_arg_opt (const char *); @@ -33,7 +32,7 @@ extern bool plugins_active_p (void); extern void dump_active_plugins (FILE *); extern void debug_active_plugins (void); extern void warn_if_plugins (void); -extern void plugins_internal_error_function (struct diagnostic_context *, +extern void plugins_internal_error_function (diagnostic_context *, const char *, va_list *); extern void print_plugins_versions (FILE *file, const char *indent); extern void print_plugins_help (FILE *file, const char *indent); Index: gcc/Makefile.in =================================================================== --- gcc/Makefile.in (revision 164960) +++ gcc/Makefile.in (working copy) @@ -2325,7 +2325,7 @@ lto-symtab.o: lto-symtab.c $(CONFIG_H) $ $(LTO_STREAMER_H) $(LINKER_PLUGIN_API_H) gt-lto-symtab.h lto-opts.o: lto-opts.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TREE_H) \ $(HASHTAB_H) $(GGC_H) $(BITMAP_H) $(FLAGS_H) opts.h options.h \ - $(TARGET_H) $(TOPLEV_H) $(DIAGNOSTIC_CORE_H) $(LTO_STREAMER_H) + $(TARGET_H) $(TOPLEV_H) $(DIAGNOSTIC_H) $(LTO_STREAMER_H) lto-streamer.o: lto-streamer.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \ $(TM_H) $(TREE_H) $(GIMPLE_H) $(BITMAP_H) $(LTO_STREAMER_H) $(FLAGS_H) \ $(TREE_FLOW_H) $(DIAGNOSTIC_CORE_H) $(LTO_SYMTAB_H) $(TOPLEV_H) $(DIAGNOSTIC_CORE_H) Index: gcc/lto-opts.c =================================================================== --- gcc/lto-opts.c (revision 164960) +++ gcc/lto-opts.c (working copy) @@ -31,7 +31,7 @@ along with GCC; see the file COPYING3. #include "opts.h" #include "options.h" #include "target.h" -#include "diagnostic-core.h" +#include "diagnostic.h" #include "toplev.h" #include "lto-streamer.h" @@ -404,7 +404,7 @@ lto_reissue_options (void) if (flag_var) set_option (&global_options, &global_options_set, o->code, o->value, o->arg, - 0 /*DK_UNSPECIFIED*/); + DK_UNSPECIFIED, global_dc); if (o->type == CL_TARGET) targetm.handle_option (o->code, o->arg, o->value); Index: gcc/langhooks-def.h =================================================================== --- gcc/langhooks-def.h (revision 164960) +++ gcc/langhooks-def.h (working copy) @@ -24,7 +24,6 @@ along with GCC; see the file COPYING3. #include "hooks.h" -struct diagnostic_context; struct diagnostic_info; /* Note to creators of new hooks: @@ -51,7 +50,7 @@ extern void lhd_print_tree_nothing (FILE extern const char *lhd_decl_printable_name (tree, int); extern const char *lhd_dwarf_name (tree, int); extern int lhd_types_compatible_p (tree, tree); -extern void lhd_print_error_function (struct diagnostic_context *, +extern void lhd_print_error_function (diagnostic_context *, const char *, struct diagnostic_info *); extern void lhd_set_decl_assembler_name (tree); extern bool lhd_warn_unused_global_decl (const_tree); @@ -65,7 +64,7 @@ extern tree lhd_expr_to_decl (tree, bool extern tree lhd_builtin_function (tree); /* Declarations of default tree inlining hooks. */ -extern void lhd_initialize_diagnostics (struct diagnostic_context *); +extern void lhd_initialize_diagnostics (diagnostic_context *); extern void lhd_init_options (unsigned int, struct cl_decoded_option *); extern bool lhd_complain_wrong_lang_p (const struct cl_option *);