/* Return the gcc option code associated with the reason for a cpp
message, or 0 if none. */
-static int
+static diagnostic_option_id
c_option_controlling_cpp_diagnostic (enum cpp_warning_reason reason)
{
const struct cpp_reason_option_codes_t *entry;
richloc->set_range (0, input_location, SHOW_RANGE_WITH_CARET);
diagnostic_set_info_translated (&diagnostic, msg, ap,
richloc, dlevel);
- diagnostic_override_option_index
- (&diagnostic,
- c_option_controlling_cpp_diagnostic (reason));
+ diagnostic_set_option_id (&diagnostic,
+ c_option_controlling_cpp_diagnostic (reason));
ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
if (level == CPP_DL_WARNING_SYSHDR)
global_dc->m_warn_system_headers = save_warn_system_headers;
when C2Y is specified. */
bool
-pedwarn_c23 (location_t location, int opt, const char *gmsgid, ...)
+pedwarn_c23 (location_t location,
+ diagnostic_option_id option_id,
+ const char *gmsgid, ...)
{
diagnostic_info diagnostic;
va_list ap;
diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
(pedantic && !flag_isoc2y)
? DK_PEDWARN : DK_WARNING);
- diagnostic.option_index = OPT_Wc23_c2y_compat;
+ diagnostic.option_id = OPT_Wc23_c2y_compat;
warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
}
/* -Wno-c23-c2y-compat suppresses even the pedwarns. */
else if (pedantic && !flag_isoc2y)
{
diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
- diagnostic.option_index = opt;
+ diagnostic.option_id = option_id;
warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
}
va_end (ap);
when C23 is specified. */
bool
-pedwarn_c11 (location_t location, int opt, const char *gmsgid, ...)
+pedwarn_c11 (location_t location,
+ diagnostic_option_id option_id,
+ const char *gmsgid, ...)
{
diagnostic_info diagnostic;
va_list ap;
diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
(pedantic && !flag_isoc23)
? DK_PEDWARN : DK_WARNING);
- diagnostic.option_index = OPT_Wc11_c23_compat;
+ diagnostic.option_id = OPT_Wc11_c23_compat;
warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
}
/* -Wno-c11-c23-compat suppresses even the pedwarns. */
else if (pedantic && !flag_isoc23)
{
diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
- diagnostic.option_index = opt;
+ diagnostic.option_id = option_id;
warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
}
va_end (ap);
when C11 is specified. */
bool
-pedwarn_c99 (location_t location, int opt, const char *gmsgid, ...)
+pedwarn_c99 (location_t location,
+ diagnostic_option_id option_id,
+ const char *gmsgid, ...)
{
diagnostic_info diagnostic;
va_list ap;
diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
(pedantic && !flag_isoc11)
? DK_PEDWARN : DK_WARNING);
- diagnostic.option_index = OPT_Wc99_c11_compat;
+ diagnostic.option_id = OPT_Wc99_c11_compat;
warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
}
/* -Wno-c99-c11-compat suppresses even the pedwarns. */
else if (pedantic && !flag_isoc11)
{
diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
- diagnostic.option_index = opt;
+ diagnostic.option_id = option_id;
warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
}
va_end (ap);
when C99 is specified. (There is no flag_c90.) */
bool
-pedwarn_c90 (location_t location, int opt, const char *gmsgid, ...)
+pedwarn_c90 (location_t location,
+ diagnostic_option_id option_id,
+ const char *gmsgid, ...)
{
diagnostic_info diagnostic;
va_list ap;
va_start (ap, gmsgid);
/* Warnings such as -Wvla are the most specific ones. */
- if (opt != OPT_Wpedantic)
+ if (option_id.m_idx != OPT_Wpedantic)
{
- int opt_var = *(int *) option_flag_var (opt, &global_options);
+ int opt_var = *(int *) option_flag_var (option_id.m_idx, &global_options);
if (opt_var == 0)
goto out;
else if (opt_var > 0)
diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
(pedantic && !flag_isoc99)
? DK_PEDWARN : DK_WARNING);
- diagnostic.option_index = opt;
+ diagnostic.option_id = option_id;
diagnostic_report_diagnostic (global_dc, &diagnostic);
warned = true;
goto out;
diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
(pedantic && !flag_isoc99)
? DK_PEDWARN : DK_WARNING);
- diagnostic.option_index = OPT_Wc90_c99_compat;
+ diagnostic.option_id = OPT_Wc90_c99_compat;
diagnostic_report_diagnostic (global_dc, &diagnostic);
}
/* -Wno-c90-c99-compat suppresses the pedwarns. */
else if (pedantic && !flag_isoc99)
{
diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
- diagnostic.option_index = opt;
+ diagnostic.option_id = option_id;
diagnostic_report_diagnostic (global_dc, &diagnostic);
warned = true;
}
extern bool tag_exists_p (enum tree_code, tree);
/* In c-errors.cc */
-extern bool pedwarn_c90 (location_t, int opt, const char *, ...)
+extern bool pedwarn_c90 (location_t, diagnostic_option_id, const char *, ...)
ATTRIBUTE_GCC_DIAG(3,4);
-extern bool pedwarn_c99 (location_t, int opt, const char *, ...)
+extern bool pedwarn_c99 (location_t, diagnostic_option_id, const char *, ...)
ATTRIBUTE_GCC_DIAG(3,4);
-extern bool pedwarn_c11 (location_t, int opt, const char *, ...)
+extern bool pedwarn_c11 (location_t, diagnostic_option_id, const char *, ...)
ATTRIBUTE_GCC_DIAG(3,4);
-extern bool pedwarn_c23 (location_t, int opt, const char *, ...)
+extern bool pedwarn_c23 (location_t, diagnostic_option_id, const char *, ...)
ATTRIBUTE_GCC_DIAG(3,4);
extern void
{
diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
cxx_dialect < cxx23 ? DK_PEDWARN : DK_WARNING);
- diagnostic.option_index = OPT_Winvalid_constexpr;
+ diagnostic.option_id = OPT_Winvalid_constexpr;
ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
}
else
extern void maybe_warn_variadic_templates (void);
extern void maybe_warn_cpp0x (cpp0x_warn_str str,
location_t = input_location);
-extern bool pedwarn_cxx98 (location_t, int, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4);
+extern bool pedwarn_cxx98 (location_t,
+ diagnostic_option_id option_id,
+ const char *, ...) ATTRIBUTE_GCC_DIAG(3,4);
extern location_t location_of (tree);
extern void qualified_name_lookup_error (tree, tree, tree,
location_t);
if (diagnostic->kind == DK_ERROR)
if (tree tmpl = get_current_template ())
{
- diagnostic->option_index = OPT_Wtemplate_body;
+ diagnostic->option_id = OPT_Wtemplate_body;
if (context->m_permissive)
diagnostic->kind = DK_WARNING;
/* Issue an ISO C++98 pedantic warning at LOCATION, conditional on
- option OPT with text GMSGID. Use this function to report
+ option OPTION_ID with text GMSGID. Use this function to report
diagnostics for constructs that are invalid C++98, but valid
C++0x. */
bool
-pedwarn_cxx98 (location_t location, int opt, const char *gmsgid, ...)
+pedwarn_cxx98 (location_t location,
+ diagnostic_option_id option_id,
+ const char *gmsgid, ...)
{
diagnostic_info diagnostic;
va_list ap;
va_start (ap, gmsgid);
diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
(cxx_dialect == cxx98) ? DK_PEDWARN : DK_WARNING);
- diagnostic.option_index = opt;
+ diagnostic.option_id = option_id;
ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
va_end (ap);
return ret;
diagnostic_set_info_translated (&diagnostic, xformat, &argp,
&rich_loc, kind);
if (opt != 0)
- diagnostic.option_index = opt;
+ diagnostic.option_id = opt;
diagnostic_report_diagnostic (global_dc, &diagnostic);
}
/* Forward decl. */
class diagnostic_metadata; /* See diagnostic-metadata.h. */
+/* A class to use for the ID of an option that controls
+ a particular diagnostic.
+ This is just a wrapper around "int", but better documents
+ the intent of the code. */
+
+struct diagnostic_option_id
+{
+ diagnostic_option_id () : m_idx (0) {}
+
+ diagnostic_option_id (int idx) : m_idx (idx) {}
+ /* Ideally we'd take an enum opt_code here, but we don't
+ want to depend on its decl. */
+
+ bool operator== (diagnostic_option_id other) const
+ {
+ return m_idx == other.m_idx;
+ }
+
+ int m_idx;
+};
+
extern const char *progname;
extern const char *trim_filename (const char *);
extern void internal_error_no_backtrace (const char *, ...)
ATTRIBUTE_GCC_DIAG(1,2) ATTRIBUTE_NORETURN;
/* Pass one of the OPT_W* from options.h as the first parameter. */
-extern bool warning (int, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
-extern bool warning_n (location_t, int, unsigned HOST_WIDE_INT,
+extern bool warning (diagnostic_option_id,
+ const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
+extern bool warning_n (location_t,
+ diagnostic_option_id,
+ unsigned HOST_WIDE_INT,
const char *, const char *, ...)
ATTRIBUTE_GCC_DIAG(4,6) ATTRIBUTE_GCC_DIAG(5,6);
-extern bool warning_n (rich_location *, int, unsigned HOST_WIDE_INT,
+extern bool warning_n (rich_location *,
+ diagnostic_option_id,
+ unsigned HOST_WIDE_INT,
const char *, const char *, ...)
ATTRIBUTE_GCC_DIAG(4, 6) ATTRIBUTE_GCC_DIAG(5, 6);
-extern bool warning_at (location_t, int, const char *, ...)
+extern bool warning_at (location_t,
+ diagnostic_option_id,
+ const char *, ...)
ATTRIBUTE_GCC_DIAG(3,4);
-extern bool warning_at (rich_location *, int, const char *, ...)
+extern bool warning_at (rich_location *,
+ diagnostic_option_id,
+ const char *, ...)
ATTRIBUTE_GCC_DIAG(3,4);
extern bool warning_meta (rich_location *,
- const diagnostic_metadata &, int,
+ const diagnostic_metadata &,
+ diagnostic_option_id,
const char *, ...)
ATTRIBUTE_GCC_DIAG(4,5);
extern void error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
extern void fatal_error (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3)
ATTRIBUTE_NORETURN;
/* Pass one of the OPT_W* from options.h as the second parameter. */
-extern bool pedwarn (location_t, int, const char *, ...)
+extern bool pedwarn (location_t,
+ diagnostic_option_id,
+ const char *, ...)
ATTRIBUTE_GCC_DIAG(3,4);
-extern bool pedwarn (rich_location *, int, const char *, ...)
+extern bool pedwarn (rich_location *,
+ diagnostic_option_id,
+ const char *, ...)
ATTRIBUTE_GCC_DIAG(3,4);
extern bool permerror (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
extern bool permerror (rich_location *, const char *,
...) ATTRIBUTE_GCC_DIAG(2,3);
-extern bool permerror_opt (location_t, int, const char *, ...)
+extern bool permerror_opt (location_t,
+ diagnostic_option_id,
+ const char *, ...)
+ ATTRIBUTE_GCC_DIAG(3,4);
+extern bool permerror_opt (rich_location *,
+ diagnostic_option_id,
+ const char *, ...)
ATTRIBUTE_GCC_DIAG(3,4);
-extern bool permerror_opt (rich_location *, int, const char *,
- ...) ATTRIBUTE_GCC_DIAG(3,4);
extern void sorry (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
extern void sorry_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
extern void inform (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
const char *, ...)
ATTRIBUTE_GCC_DIAG(3,5) ATTRIBUTE_GCC_DIAG(4,5);
extern void verbatim (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
-extern bool emit_diagnostic (diagnostic_t, location_t, int,
+extern bool emit_diagnostic (diagnostic_t,
+ location_t,
+ diagnostic_option_id,
const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
-extern bool emit_diagnostic (diagnostic_t, rich_location *, int,
+extern bool emit_diagnostic (diagnostic_t,
+ rich_location *,
+ diagnostic_option_id,
const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
-extern bool emit_diagnostic_valist (diagnostic_t, location_t, int, const char *,
- va_list *) ATTRIBUTE_GCC_DIAG (4,0);
+extern bool emit_diagnostic_valist (diagnostic_t,
+ location_t,
+ diagnostic_option_id,
+ const char *, va_list *)
+ ATTRIBUTE_GCC_DIAG (4,0);
extern bool emit_diagnostic_valist_meta (diagnostic_t,
rich_location *,
const diagnostic_metadata *,
- int,
+ diagnostic_option_id,
const char *,
va_list *) ATTRIBUTE_GCC_DIAG (5,0);
extern bool seen_error (void);
diag_obj->set_string ("message", pp_formatted_text (pp));
pp_clear_output_area (pp);
- if (char *option_text = m_context.make_option_name (diagnostic.option_index,
+ if (char *option_text = m_context.make_option_name (diagnostic.option_id,
orig_diag_kind,
diagnostic.kind))
{
free (option_text);
}
- if (char *option_url = m_context.make_option_url (diagnostic.option_index))
+ if (char *option_url = m_context.make_option_url (diagnostic.option_id))
{
diag_obj->set_string ("option_url", option_url);
free (option_url);
/* "ruleId" property (SARIF v2.1.0 section 3.27.5). */
/* Ideally we'd have an option_name for these. */
if (char *option_text
- = context.make_option_name (diagnostic.option_index,
+ = context.make_option_name (diagnostic.option_id,
orig_diag_kind, diagnostic.kind))
{
/* Lazily create reportingDescriptor objects for and add to m_rules_arr.
it seems redundant compared to "id". */
/* "helpUri" property (SARIF v2.1.0 section 3.49.12). */
- if (char *option_url = context.make_option_url (diagnostic.option_index))
+ if (char *option_url = context.make_option_url (diagnostic.option_id))
{
reporting_desc->set_string ("helpUri", option_url);
free (option_url);
diagnostic_t orig_diag_kind)
{
if (char *option_text
- = m_context.make_option_name (diagnostic.option_index,
+ = m_context.make_option_name (diagnostic.option_id,
orig_diag_kind, diagnostic.kind))
{
char *option_url = nullptr;
pretty_printer * const pp = get_printer ();
if (pp->supports_urls_p ())
- option_url = m_context.make_option_url (diagnostic.option_index);
+ option_url = m_context.make_option_url (diagnostic.option_id);
pp_string (pp, " [");
const char *kind_color = diagnostic_get_color_for_kind (diagnostic.kind);
pp_string (pp, colorize_start (pp_show_color (pp), kind_color));
implying global_dc and taking a variable argument list. */
bool
-emit_diagnostic (diagnostic_t kind, location_t location, int opt,
+emit_diagnostic (diagnostic_t kind,
+ location_t location,
+ diagnostic_option_id option_id,
const char *gmsgid, ...)
{
auto_diagnostic_group d;
va_list ap;
va_start (ap, gmsgid);
rich_location richloc (line_table, location);
- bool ret = global_dc->diagnostic_impl (&richloc, nullptr, opt, gmsgid, &ap,
- kind);
+ bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
+ gmsgid, &ap, kind);
va_end (ap);
return ret;
}
/* As above, but for rich_location *. */
bool
-emit_diagnostic (diagnostic_t kind, rich_location *richloc, int opt,
+emit_diagnostic (diagnostic_t kind,
+ rich_location *richloc,
+ diagnostic_option_id option_id,
const char *gmsgid, ...)
{
auto_diagnostic_group d;
va_list ap;
va_start (ap, gmsgid);
- bool ret = global_dc->diagnostic_impl (richloc, nullptr, opt, gmsgid, &ap,
- kind);
+ bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id,
+ gmsgid, &ap, kind);
va_end (ap);
return ret;
}
/* As above, but taking a variable argument list. */
bool
-emit_diagnostic_valist (diagnostic_t kind, location_t location, int opt,
+emit_diagnostic_valist (diagnostic_t kind,
+ location_t location,
+ diagnostic_option_id option_id,
const char *gmsgid, va_list *ap)
{
rich_location richloc (line_table, location);
- return global_dc->diagnostic_impl (&richloc, nullptr, opt, gmsgid, ap, kind);
+ return global_dc->diagnostic_impl (&richloc, nullptr, option_id,
+ gmsgid, ap, kind);
}
/* As above, but with rich_location and metadata. */
emit_diagnostic_valist_meta (diagnostic_t kind,
rich_location *richloc,
const diagnostic_metadata *metadata,
- int opt,
+ diagnostic_option_id option_id,
const char *gmsgid, va_list *ap)
{
- return global_dc->diagnostic_impl (richloc, metadata, opt, gmsgid, ap, kind);
+ return global_dc->diagnostic_impl (richloc, metadata, option_id,
+ gmsgid, ap, kind);
}
/* An informative note at LOCATION. Use this for additional details on an error
to the relevant language specification but is likely to be buggy anyway.
Returns true if the warning was printed, false if it was inhibited. */
bool
-warning (int opt, const char *gmsgid, ...)
+warning (diagnostic_option_id option_id, const char *gmsgid, ...)
{
auto_diagnostic_group d;
va_list ap;
va_start (ap, gmsgid);
rich_location richloc (line_table, input_location);
- bool ret = global_dc->diagnostic_impl (&richloc, nullptr, opt, gmsgid, &ap,
- DK_WARNING);
+ bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
+ gmsgid, &ap, DK_WARNING);
va_end (ap);
return ret;
}
Returns true if the warning was printed, false if it was inhibited. */
bool
-warning_at (location_t location, int opt, const char *gmsgid, ...)
+warning_at (location_t location,
+ diagnostic_option_id option_id,
+ const char *gmsgid, ...)
{
auto_diagnostic_group d;
va_list ap;
va_start (ap, gmsgid);
rich_location richloc (line_table, location);
- bool ret = global_dc->diagnostic_impl (&richloc, nullptr, opt, gmsgid, &ap,
- DK_WARNING);
+ bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
+ gmsgid, &ap, DK_WARNING);
va_end (ap);
return ret;
}
/* Same as "warning at" above, but using RICHLOC. */
bool
-warning_at (rich_location *richloc, int opt, const char *gmsgid, ...)
+warning_at (rich_location *richloc,
+ diagnostic_option_id option_id,
+ const char *gmsgid, ...)
{
gcc_assert (richloc);
auto_diagnostic_group d;
va_list ap;
va_start (ap, gmsgid);
- bool ret = global_dc->diagnostic_impl (richloc, nullptr, opt, gmsgid, &ap,
- DK_WARNING);
+ bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id,
+ gmsgid, &ap, DK_WARNING);
va_end (ap);
return ret;
}
bool
warning_meta (rich_location *richloc,
const diagnostic_metadata &metadata,
- int opt, const char *gmsgid, ...)
+ diagnostic_option_id option_id,
+ const char *gmsgid, ...)
{
gcc_assert (richloc);
auto_diagnostic_group d;
va_list ap;
va_start (ap, gmsgid);
- bool ret = global_dc->diagnostic_impl (richloc, &metadata, opt, gmsgid, &ap,
- DK_WARNING);
+ bool ret = global_dc->diagnostic_impl (richloc, &metadata, option_id,
+ gmsgid, &ap, DK_WARNING);
va_end (ap);
return ret;
}
/* Same as warning_n plural variant below, but using RICHLOC. */
bool
-warning_n (rich_location *richloc, int opt, unsigned HOST_WIDE_INT n,
+warning_n (rich_location *richloc,
+ diagnostic_option_id option_id,
+ unsigned HOST_WIDE_INT n,
const char *singular_gmsgid, const char *plural_gmsgid, ...)
{
gcc_assert (richloc);
auto_diagnostic_group d;
va_list ap;
va_start (ap, plural_gmsgid);
- bool ret = global_dc->diagnostic_n_impl (richloc, nullptr, opt, n,
+ bool ret = global_dc->diagnostic_n_impl (richloc, nullptr, option_id, n,
singular_gmsgid, plural_gmsgid,
&ap, DK_WARNING);
va_end (ap);
Returns true if the warning was printed, false if it was inhibited. */
bool
-warning_n (location_t location, int opt, unsigned HOST_WIDE_INT n,
+warning_n (location_t location,
+ diagnostic_option_id option_id,
+ unsigned HOST_WIDE_INT n,
const char *singular_gmsgid, const char *plural_gmsgid, ...)
{
auto_diagnostic_group d;
va_list ap;
va_start (ap, plural_gmsgid);
rich_location richloc (line_table, location);
- bool ret = global_dc->diagnostic_n_impl (&richloc, nullptr, opt, n,
+ bool ret = global_dc->diagnostic_n_impl (&richloc, nullptr, option_id, n,
singular_gmsgid, plural_gmsgid,
&ap, DK_WARNING);
va_end (ap);
Returns true if the warning was printed, false if it was inhibited. */
bool
-pedwarn (location_t location, int opt, const char *gmsgid, ...)
+pedwarn (location_t location,
+ diagnostic_option_id option_id,
+ const char *gmsgid, ...)
{
auto_diagnostic_group d;
va_list ap;
va_start (ap, gmsgid);
rich_location richloc (line_table, location);
- bool ret = global_dc->diagnostic_impl (&richloc, nullptr, opt, gmsgid, &ap,
- DK_PEDWARN);
+ bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
+ gmsgid, &ap, DK_PEDWARN);
va_end (ap);
return ret;
}
/* Same as pedwarn above, but using RICHLOC. */
bool
-pedwarn (rich_location *richloc, int opt, const char *gmsgid, ...)
+pedwarn (rich_location *richloc,
+ diagnostic_option_id option_id,
+ const char *gmsgid, ...)
{
gcc_assert (richloc);
auto_diagnostic_group d;
va_list ap;
va_start (ap, gmsgid);
- bool ret = global_dc->diagnostic_impl (richloc, nullptr, opt, gmsgid, &ap,
- DK_PEDWARN);
+ bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id,
+ gmsgid, &ap, DK_PEDWARN);
va_end (ap);
return ret;
}
diagnostic can also be downgraded by -Wno-error=opt. */
bool
-permerror_opt (location_t location, int opt, const char *gmsgid, ...)
+permerror_opt (location_t location,
+ diagnostic_option_id option_id,
+ const char *gmsgid, ...)
{
auto_diagnostic_group d;
va_list ap;
va_start (ap, gmsgid);
rich_location richloc (line_table, location);
- bool ret = global_dc->diagnostic_impl (&richloc, nullptr, opt, gmsgid, &ap,
- DK_PERMERROR);
+ bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
+ gmsgid, &ap, DK_PERMERROR);
va_end (ap);
return ret;
}
/* Same as "permerror" above, but at RICHLOC. */
bool
-permerror_opt (rich_location *richloc, int opt, const char *gmsgid, ...)
+permerror_opt (rich_location *richloc,
+ diagnostic_option_id option_id,
+ const char *gmsgid, ...)
{
gcc_assert (richloc);
auto_diagnostic_group d;
va_list ap;
va_start (ap, gmsgid);
- bool ret = global_dc->diagnostic_impl (richloc, nullptr, opt, gmsgid, &ap,
- DK_PERMERROR);
+ bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id,
+ gmsgid, &ap, DK_PERMERROR);
va_end (ap);
return ret;
}
diagnostic->richloc = richloc;
diagnostic->metadata = NULL;
diagnostic->kind = kind;
- diagnostic->option_index = 0;
+ diagnostic->option_id = 0;
}
/* Initialize DIAGNOSTIC, where the message GMSGID has not yet been
/* Interface to specify diagnostic kind overrides. Returns the
previous setting, or DK_UNSPECIFIED if the parameters are out of
- range. If OPTION_INDEX is zero, the new setting is for all the
+ range. If OPTION_ID is zero, the new setting is for all the
diagnostics. */
diagnostic_t
diagnostic_option_classifier::
classify_diagnostic (const diagnostic_context *context,
- int option_index,
+ diagnostic_option_id option_id,
diagnostic_t new_kind,
location_t where)
{
diagnostic_t old_kind;
- if (option_index < 0
- || option_index >= m_n_opts
+ if (option_id.m_idx < 0
+ || option_id.m_idx >= m_n_opts
|| new_kind >= DK_LAST_DIAGNOSTIC_KIND)
return DK_UNSPECIFIED;
- old_kind = m_classify_diagnostic[option_index];
+ old_kind = m_classify_diagnostic[option_id.m_idx];
/* Handle pragmas separately, since we need to keep track of *where*
the pragmas were. */
/* Record the command-line status, so we can reset it back on DK_POP. */
if (old_kind == DK_UNSPECIFIED)
{
- old_kind = !context->option_enabled_p (option_index)
+ old_kind = !context->option_enabled_p (option_id)
? DK_IGNORED : DK_ANY;
- m_classify_diagnostic[option_index] = old_kind;
+ m_classify_diagnostic[option_id.m_idx] = old_kind;
}
for (i = m_n_classification_history - 1; i >= 0; i --)
- if (m_classification_history[i].option == option_index)
+ if (m_classification_history[i].option == option_id.m_idx)
{
old_kind = m_classification_history[i].kind;
break;
(diagnostic_classification_change_t *) xrealloc (m_classification_history, (i + 1)
* sizeof (diagnostic_classification_change_t));
m_classification_history[i].location = where;
- m_classification_history[i].option = option_index;
+ m_classification_history[i].option = option_id.m_idx;
m_classification_history[i].kind = new_kind;
m_n_classification_history ++;
}
else
- m_classify_diagnostic[option_index] = new_kind;
+ m_classify_diagnostic[option_id.m_idx] = new_kind;
return old_kind;
}
continue;
}
- int option = hist.option;
+ diagnostic_option_id option = hist.option;
/* The option 0 is for all the diagnostics. */
- if (option == 0 || option == diagnostic->option_index)
+ if (option == 0 || option == diagnostic->option_id)
{
diagnostic_t kind = hist.kind;
if (kind != DK_UNSPECIFIED)
get_any_inlining_info (diagnostic);
/* Diagnostics with no option or -fpermissive are always enabled. */
- if (!diagnostic->option_index
- || diagnostic->option_index == m_opt_permissive)
+ if (!diagnostic->option_id.m_idx
+ || diagnostic->option_id == m_opt_permissive)
return true;
/* This tests if the user provided the appropriate -Wfoo or
-Wno-foo option. */
- if (!option_enabled_p (diagnostic->option_index))
+ if (!option_enabled_p (diagnostic->option_id))
return false;
/* This tests for #pragma diagnostic changes. */
/* This tests if the user provided the appropriate -Werror=foo
option. */
if (diag_class == DK_UNSPECIFIED
- && !option_unspecified_p (diagnostic->option_index))
+ && !option_unspecified_p (diagnostic->option_id))
{
const diagnostic_t new_kind
- = m_option_classifier.get_current_override (diagnostic->option_index);
+ = m_option_classifier.get_current_override (diagnostic->option_id);
if (new_kind != DK_ANY)
/* DK_ANY means the diagnostic is not to be ignored, but we don't want
to change it specifically to DK_ERROR or DK_WARNING; we want to
return true;
}
-/* Returns whether warning OPT is enabled at LOC. */
+/* Returns whether warning OPTION_ID is enabled at LOC. */
bool
-diagnostic_context::warning_enabled_at (location_t loc, int opt)
+diagnostic_context::warning_enabled_at (location_t loc,
+ diagnostic_option_id option_id)
{
if (!diagnostic_report_warnings_p (this, loc))
return false;
rich_location richloc (line_table, loc);
diagnostic_info diagnostic = {};
- diagnostic.option_index = opt;
+ diagnostic.option_id = option_id;
diagnostic.richloc = &richloc;
diagnostic.message.m_richloc = &richloc;
diagnostic.kind = DK_WARNING;
bool
diagnostic_context::diagnostic_impl (rich_location *richloc,
const diagnostic_metadata *metadata,
- int opt, const char *gmsgid,
+ diagnostic_option_id option_id,
+ const char *gmsgid,
va_list *ap, diagnostic_t kind)
{
diagnostic_info diagnostic;
{
diagnostic_set_info (&diagnostic, gmsgid, ap, richloc,
m_permissive ? DK_WARNING : DK_ERROR);
- diagnostic.option_index = (opt != -1 ? opt : m_opt_permissive);
+ diagnostic.option_id = (option_id.m_idx != -1 ? option_id : m_opt_permissive);
}
else
{
diagnostic_set_info (&diagnostic, gmsgid, ap, richloc, kind);
if (kind == DK_WARNING || kind == DK_PEDWARN)
- diagnostic.option_index = opt;
+ diagnostic.option_id = option_id;
}
diagnostic.metadata = metadata;
return report_diagnostic (&diagnostic);
bool
diagnostic_context::diagnostic_n_impl (rich_location *richloc,
const diagnostic_metadata *metadata,
- int opt, unsigned HOST_WIDE_INT n,
+ diagnostic_option_id option_id,
+ unsigned HOST_WIDE_INT n,
const char *singular_gmsgid,
const char *plural_gmsgid,
va_list *ap, diagnostic_t kind)
const char *text = ngettext (singular_gmsgid, plural_gmsgid, gtn);
diagnostic_set_info_translated (&diagnostic, text, ap, richloc, kind);
if (kind == DK_WARNING)
- diagnostic.option_index = opt;
+ diagnostic.option_id = option_id;
diagnostic.metadata = metadata;
return report_diagnostic (&diagnostic);
}
struct diagnostic_info
{
diagnostic_info ()
- : message (), richloc (), metadata (), x_data (), kind (), option_index (),
+ : message (), richloc (), metadata (), x_data (), kind (), option_id (),
m_iinfo ()
{ }
/* The kind of diagnostic it is about. */
diagnostic_t kind;
/* Which OPT_* directly controls this diagnostic. */
- int option_index;
+ diagnostic_option_id option_id;
/* Inlining context containing locations for each call site along
the inlining stack. */
public:
virtual ~diagnostic_option_manager () {}
- /* Return 1 if option OPT_IDX is enabled, 0 if it is disabled,
+ /* Return 1 if option OPTION_ID is enabled, 0 if it is disabled,
or -1 if it isn't a simple on-off switch
(or if the value is unknown, typically set later in target). */
- virtual int option_enabled_p (int opt_idx) const = 0;
+ virtual int option_enabled_p (diagnostic_option_id option_id) const = 0;
- /* Return malloced memory for the name of the option OPT_IDX
+ /* Return malloced memory for the name of the option OPTION_ID
which enabled a diagnostic, originally of type ORIG_DIAG_KIND but
possibly converted to DIAG_KIND by options such as -Werror.
May return NULL if no name is to be printed.
May be passed 0 as well as the index of a particular option. */
- virtual char *make_option_name (int opt_idx,
+ virtual char *make_option_name (diagnostic_option_id option_id,
diagnostic_t orig_diag_kind,
diagnostic_t diag_kind) const = 0;
a diagnostic.
May return NULL if no URL is available.
May be passed 0 as well as the index of a particular option. */
- virtual char *make_option_url (int opt_idx) const = 0;
+ virtual char *make_option_url (diagnostic_option_id option_id) const = 0;
};
class edit_context;
is empty, revert to the state based on command line parameters. */
void pop (location_t where);
- bool option_unspecified_p (int opt) const
+ bool option_unspecified_p (diagnostic_option_id option_id) const
{
- return get_current_override (opt) == DK_UNSPECIFIED;
+ return get_current_override (option_id) == DK_UNSPECIFIED;
}
- diagnostic_t get_current_override (int opt) const
+ diagnostic_t get_current_override (diagnostic_option_id option_id) const
{
- gcc_assert (opt < m_n_opts);
- return m_classify_diagnostic[opt];
+ gcc_assert (option_id.m_idx < m_n_opts);
+ return m_classify_diagnostic[option_id.m_idx];
}
diagnostic_t
classify_diagnostic (const diagnostic_context *context,
- int option_index,
+ diagnostic_option_id option_id,
diagnostic_t new_kind,
location_t where);
struct diagnostic_classification_change_t
{
location_t location;
+
+ /* For DK_POP, this is the index of the corresponding push (as stored
+ in m_push_list).
+ Otherwise, this is an option index. */
int option;
+
diagnostic_t kind;
};
void begin_group ();
void end_group ();
- bool warning_enabled_at (location_t loc, int opt);
+ bool warning_enabled_at (location_t loc, diagnostic_option_id option_id);
- bool option_unspecified_p (int opt) const
+ bool option_unspecified_p (diagnostic_option_id option_id) const
{
- return m_option_classifier.option_unspecified_p (opt);
+ return m_option_classifier.option_unspecified_p (option_id);
}
bool report_diagnostic (diagnostic_info *);
void action_after_output (diagnostic_t diag_kind);
diagnostic_t
- classify_diagnostic (int option_index,
+ classify_diagnostic (diagnostic_option_id option_id,
diagnostic_t new_kind,
location_t where)
{
return m_option_classifier.classify_diagnostic (this,
- option_index,
+ option_id,
new_kind,
where);
}
}
/* Option-related member functions. */
- inline bool option_enabled_p (int option_index) const
+ inline bool option_enabled_p (diagnostic_option_id option_id) const
{
if (!m_option_mgr)
return true;
- return m_option_mgr->option_enabled_p (option_index);
+ return m_option_mgr->option_enabled_p (option_id);
}
- inline char *make_option_name (int option_index,
- diagnostic_t orig_diag_kind,
- diagnostic_t diag_kind) const
+ inline char *make_option_name (diagnostic_option_id option_id,
+ diagnostic_t orig_diag_kind,
+ diagnostic_t diag_kind) const
{
if (!m_option_mgr)
return nullptr;
- return m_option_mgr->make_option_name (option_index,
+ return m_option_mgr->make_option_name (option_id,
orig_diag_kind,
diag_kind);
}
- inline char *make_option_url (int option_index) const
+ inline char *make_option_url (diagnostic_option_id option_id) const
{
if (!m_option_mgr)
return nullptr;
- return m_option_mgr->make_option_url (option_index);
+ return m_option_mgr->make_option_url (option_id);
}
void
label_text get_location_text (const expanded_location &s) const;
bool diagnostic_impl (rich_location *, const diagnostic_metadata *,
- int, const char *,
+ diagnostic_option_id, const char *,
va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(5,0);
bool diagnostic_n_impl (rich_location *, const diagnostic_metadata *,
- int, unsigned HOST_WIDE_INT,
+ diagnostic_option_id, unsigned HOST_WIDE_INT,
const char *, const char *, va_list *,
diagnostic_t) ATTRIBUTE_GCC_DIAG(7,0);
diagnostic. */
inline void
-diagnostic_override_option_index (diagnostic_info *info, int optidx)
+diagnostic_set_option_id (diagnostic_info *info,
+ diagnostic_option_id option_id)
{
- info->option_index = optidx;
+ info->option_id = option_id;
}
/* Diagnostic related functions. */
/* Force diagnostics controlled by OPTIDX to be kind KIND. */
inline diagnostic_t
diagnostic_classify_diagnostic (diagnostic_context *context,
- int optidx,
+ diagnostic_option_id option_id,
diagnostic_t kind,
location_t where)
{
- return context->classify_diagnostic (optidx, kind, where);
+ return context->classify_diagnostic (option_id, kind, where);
}
inline void
extern int num_digits (int);
inline bool
-warning_enabled_at (location_t loc, int opt)
+warning_enabled_at (location_t loc, diagnostic_option_id option_id)
{
- return global_dc->warning_enabled_at (loc, opt);
+ return global_dc->warning_enabled_at (loc, option_id);
}
inline bool
-option_unspecified_p (int opt)
+option_unspecified_p (diagnostic_option_id option_id)
{
- return global_dc->option_unspecified_p (opt);
+ return global_dc->option_unspecified_p (option_id);
}
extern char *get_cwe_url (int cwe);
/* Return the gcc option code associated with the reason for a cpp
message, or 0 if none. */
-static int
+static diagnostic_option_id
cb_cpp_diagnostic_cpp_option (enum cpp_warning_reason reason)
{
const struct cpp_reason_option_codes_t *entry;
}
diagnostic_set_info_translated (&diagnostic, msg, ap,
richloc, dlevel);
- diagnostic_override_option_index (&diagnostic,
- cb_cpp_diagnostic_cpp_option (reason));
+ diagnostic_set_option_id (&diagnostic,
+ cb_cpp_diagnostic_cpp_option (reason));
ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
if (level == CPP_DL_WARNING_SYSHDR)
global_dc->m_warn_system_headers = save_warn_system_headers;
diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc,
DK_WARNING);
- diagnostic.option_index = opt;
+ diagnostic.option_id = opt;
bool ret = gfc_report_diagnostic (&diagnostic);
if (buffered_p)
va_start (argp, gmsgid);
diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_WARNING);
- diagnostic.option_index = opt;
+ diagnostic.option_id = opt;
ret = gfc_report_diagnostic (&diagnostic);
va_end (argp);
return ret;
va_start (argp, gmsgid);
diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc,
DK_WARNING);
- diagnostic.option_index = opt;
+ diagnostic.option_id = opt;
ret = gfc_report_diagnostic (&diagnostic);
va_end (argp);
return ret;
va_start (argp, gmsgid);
diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc,
DK_WARNING);
- diagnostic.option_index = opt;
+ diagnostic.option_id = opt;
ret = gfc_report_diagnostic (&diagnostic);
va_end (argp);
return ret;
by the function. */
static hash_set<tree> *
-suggest_attribute (int option, tree decl, bool known_finite,
+suggest_attribute (diagnostic_option_id option, tree decl, bool known_finite,
hash_set<tree> *warned_about,
const char * attrib_name)
{
- if (!option_enabled (option, lang_hooks.option_lang_mask (), &global_options))
+ if (!option_enabled (option.m_idx, lang_hooks.option_lang_mask (),
+ &global_options))
return warned_about;
if (TREE_THIS_VOLATILE (decl)
|| (known_finite && function_always_visible_to_compiler_p (decl)))
: gcc_diagnostic_option_manager (0 /* lang_mask */)
{
}
- int option_enabled_p (int) const final override
+ int option_enabled_p (diagnostic_option_id) const final override
{
return true;
}
- char *make_option_name (int, diagnostic_t, diagnostic_t) const final override
+ char *make_option_name (diagnostic_option_id,
+ diagnostic_t,
+ diagnostic_t) const final override
{
return nullptr;
}
}
int
-compiler_diagnostic_option_manager::option_enabled_p (int opt_idx) const
+compiler_diagnostic_option_manager::
+option_enabled_p (diagnostic_option_id opt_id) const
{
- return option_enabled (opt_idx, m_lang_mask, m_opts);
+ return option_enabled (opt_id.m_idx, m_lang_mask, m_opts);
}
/* Fill STATE with the current state of option OPTION in OPTS. Return
class gcc_diagnostic_option_manager : public diagnostic_option_manager
{
public:
- char *make_option_url (int opt) const final override;
+ char *make_option_url (diagnostic_option_id option_id) const final override;
protected:
gcc_diagnostic_option_manager (unsigned lang_mask)
{
}
- int option_enabled_p (int opt_idx) const final override;
- char *make_option_name (int opt_idx,
+ int option_enabled_p (diagnostic_option_id option_id) const final override;
+ char *make_option_name (diagnostic_option_id option_id,
diagnostic_t orig_diag_kind,
diagnostic_t diag_kind) const final override;
char *
compiler_diagnostic_option_manager::
-make_option_name (int option_index,
+make_option_name (diagnostic_option_id option_id,
diagnostic_t orig_diag_kind,
diagnostic_t diag_kind) const
{
- if (option_index)
+ if (option_id.m_idx)
{
/* A warning classified as an error. */
if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN)
&& diag_kind == DK_ERROR)
return concat (cl_options[OPT_Werror_].opt_text,
/* Skip over "-W". */
- cl_options[option_index].opt_text + 2,
+ cl_options[option_id.m_idx].opt_text + 2,
NULL);
/* A warning with option. */
else
- return xstrdup (cl_options[option_index].opt_text);
+ return xstrdup (cl_options[option_id.m_idx].opt_text);
}
/* A warning without option classified as an error. */
else if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN
which enabled a diagnostic. */
char *
-gcc_diagnostic_option_manager::make_option_url (int option_index) const
+gcc_diagnostic_option_manager::
+make_option_url (diagnostic_option_id option_id) const
{
- if (option_index)
+ if (option_id.m_idx)
{
- label_text url_suffix = get_option_url_suffix (option_index, m_lang_mask);
+ label_text url_suffix = get_option_url_suffix (option_id.m_idx,
+ m_lang_mask);
if (url_suffix.get ())
return concat (DOCUMENTATION_ROOT_URL, url_suffix.get (), nullptr);
}
{
}
-/* Emit a warning governed by option OPT, using SINGULAR_GMSGID as the
+/* Emit a warning governed by option OPTION_ID, using SINGULAR_GMSGID as the
format string (or if PLURAL_GMSGID is different from SINGULAR_GMSGID,
using SINGULAR_GMSGID, PLURAL_GMSGID and N as arguments to ngettext)
and AP as its arguments.
Return true if a warning was emitted, false otherwise. */
bool
-format_string_diagnostic_t::emit_warning_n_va (int opt,
+format_string_diagnostic_t::emit_warning_n_va (diagnostic_option_id option_id,
unsigned HOST_WIDE_INT n,
const char *singular_gmsgid,
const char *plural_gmsgid,
else
diagnostic_set_info (&diagnostic, singular_gmsgid, ap, &richloc,
DK_WARNING);
- diagnostic.option_index = opt;
+ diagnostic.option_id = option_id;
bool warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
if (!err && fmt_substring_loc && !substring_within_range)
/* Singular-only version of the above. */
bool
-format_string_diagnostic_t::emit_warning_va (int opt, const char *gmsgid,
+format_string_diagnostic_t::emit_warning_va (diagnostic_option_id option_id,
+ const char *gmsgid,
va_list *ap) const
{
- return emit_warning_n_va (opt, 0, gmsgid, gmsgid, ap);
+ return emit_warning_n_va (option_id, 0, gmsgid, gmsgid, ap);
}
/* Variadic version of the above (singular only). */
bool
-format_string_diagnostic_t::emit_warning (int opt, const char *gmsgid,
+format_string_diagnostic_t::emit_warning (diagnostic_option_id option_id,
+ const char *gmsgid,
...) const
{
va_list ap;
va_start (ap, gmsgid);
- bool warned = emit_warning_va (opt, gmsgid, &ap);
+ bool warned = emit_warning_va (option_id, gmsgid, &ap);
va_end (ap);
return warned;
/* Variadic version of the above (singular vs plural). */
bool
-format_string_diagnostic_t::emit_warning_n (int opt, unsigned HOST_WIDE_INT n,
+format_string_diagnostic_t::emit_warning_n (diagnostic_option_id option_id,
+ unsigned HOST_WIDE_INT n,
const char *singular_gmsgid,
const char *plural_gmsgid,
...) const
{
va_list ap;
va_start (ap, plural_gmsgid);
- bool warned = emit_warning_n_va (opt, n, singular_gmsgid, plural_gmsgid,
+ bool warned = emit_warning_n_va (option_id, n, singular_gmsgid, plural_gmsgid,
&ap);
va_end (ap);
/* Functions for emitting a warning about a format string. */
- bool emit_warning_va (int opt, const char *gmsgid, va_list *ap) const
+ bool emit_warning_va (diagnostic_option_id option_id,
+ const char *gmsgid,
+ va_list *ap) const
ATTRIBUTE_GCC_DIAG (3, 0);
- bool emit_warning_n_va (int opt, unsigned HOST_WIDE_INT n,
+ bool emit_warning_n_va (diagnostic_option_id option_id,
+ unsigned HOST_WIDE_INT n,
const char *singular_gmsgid,
- const char *plural_gmsgid, va_list *ap) const
+ const char *plural_gmsgid,
+ va_list *ap) const
ATTRIBUTE_GCC_DIAG (4, 0) ATTRIBUTE_GCC_DIAG (5, 0);
- bool emit_warning (int opt, const char *gmsgid, ...) const
+ bool emit_warning (diagnostic_option_id option_id,
+ const char *gmsgid, ...) const
ATTRIBUTE_GCC_DIAG (3, 4);
- bool emit_warning_n (int opt, unsigned HOST_WIDE_INT n,
+ bool emit_warning_n (diagnostic_option_id option_id,
+ unsigned HOST_WIDE_INT n,
const char *singular_gmsgid,
const char *plural_gmsgid, ...) const
ATTRIBUTE_GCC_DIAG (4, 6) ATTRIBUTE_GCC_DIAG (5, 6);