-
-/* Return a malloced slash-separated list of languages in MASK. */
-static char *
-write_langs (unsigned int mask)
-{
- unsigned int n = 0, len = 0;
- const char *lang_name;
- char *result;
-
- for (n = 0; (lang_name = lang_names[n]) != 0; n++)
- if (mask & (1U << n))
- len += strlen (lang_name) + 1;
-
- result = XNEWVEC (char, len);
- len = 0;
- for (n = 0; (lang_name = lang_names[n]) != 0; n++)
- if (mask & (1U << n))
- {
- if (len)
- result[len++] = '/';
- strcpy (result + len, lang_name);
- len += strlen (lang_name);
- }
-
- result[len] = 0;
-
- return result;
-}
-
-/* Complain that switch DECODED does not apply to this front end (mask
- LANG_MASK). */
-static void
-complain_wrong_lang (const struct cl_decoded_option *decoded,
- unsigned int lang_mask)
-{
- const struct cl_option *option = &cl_options[decoded->opt_index];
- const char *text = decoded->orig_option_with_args_text;
- char *ok_langs = NULL, *bad_lang = NULL;
- unsigned int opt_flags = option->flags;
-
- if (!lang_hooks.complain_wrong_lang_p (option))
- return;
-
- opt_flags &= ((1U << cl_lang_count) - 1) | CL_DRIVER;
- if (opt_flags != CL_DRIVER)
- ok_langs = write_langs (opt_flags);
- if (lang_mask != CL_DRIVER)
- bad_lang = write_langs (lang_mask);
-
- if (opt_flags == CL_DRIVER)
- error ("command line option %qs is valid for the driver but not for %s",
- text, bad_lang);
- else if (lang_mask == CL_DRIVER)
- gcc_unreachable ();
- else
- /* Eventually this should become a hard error IMO. */
- warning (0, "command line option %qs is valid for %s but not for %s",
- text, ok_langs, bad_lang);
-
- free (ok_langs);
- free (bad_lang);
-}
-
-/* Buffer the unknown option described by the string OPT. Currently,
- we only complain about unknown -Wno-* options if they may have
- prevented a diagnostic. Otherwise, we just ignore them.
- Note that if we do complain, it is only as a warning, not an error;
- passing the compiler an unrecognised -Wno-* option should never
- change whether the compilation succeeds or fails. */
-
-static void postpone_unknown_option_warning(const char *opt)
-{
- VEC_safe_push (const_char_p, heap, ignored_options, opt);
-}
-
-/* Produce a warning for each option previously buffered. */
-
-void print_ignored_options (void)
-{
- location_t saved_loc = input_location;
-
- input_location = 0;
-
- while (!VEC_empty (const_char_p, ignored_options))
- {
- const char *opt;
- opt = VEC_pop (const_char_p, ignored_options);
- warning (0, "unrecognized command line option \"%s\"", opt);
- }
-
- input_location = saved_loc;
-}
-
-/* Handle an unknown option DECODED, returning true if an error should be
- given. */
-
-static bool
-unknown_option_callback (const struct cl_decoded_option *decoded)
-{
- const char *opt = decoded->arg;
-
- if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-'
- && !(decoded->errors & CL_ERR_NEGATIVE))
- {
- /* We don't generate warnings for unknown -Wno-* options unless
- we issue diagnostics. */
- postpone_unknown_option_warning (opt);
- return false;
- }
- else
- return true;
-}
-
-/* Note that an option DECODED has been successfully handled with a
- handler for mask MASK. */
-
-static void
-post_handling_callback (const struct cl_decoded_option *decoded ATTRIBUTE_UNUSED,
- unsigned int mask ATTRIBUTE_UNUSED)
-{
-#ifdef ENABLE_LTO
- lto_register_user_option (decoded->opt_index, decoded->arg,
- decoded->value, mask);
-#endif
-}
-
-/* Handle a front-end option; arguments and return value as for
- handle_option. */
-
-static bool
-lang_handle_option (struct gcc_options *opts,
- struct gcc_options *opts_set,
- const struct cl_decoded_option *decoded,
- unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
- const struct cl_option_handlers *handlers,
- diagnostic_context *dc)
-{
- gcc_assert (opts == &global_options);
- gcc_assert (opts_set == &global_options_set);
- gcc_assert (dc == global_dc);
- gcc_assert (decoded->canonical_option_num_elements <= 2);
- return lang_hooks.handle_option (decoded->opt_index, decoded->arg,
- decoded->value, kind, handlers);
-}