c-family: Avoid unnecessary work when -Wpragmas is being ignored

This speeds up handle_pragma_diagnostic by avoiding computing a spelling
suggestion for an unrecognized option inside a #pragma directive when
-Wpragmas warnings are being suppressed.

In the range-v3 library, which contains many instances of

  #pragma GCC diagnostic push
  #pragma GCC diagnostic ignored "-Wpragmas"
  #pragma GCC diagnostic ignored "-Wfoo"
  ...
  #pragma GCC diagnostic pop

(where -Wfoo stands for a warning option we don't recognize), this
reduces compile time by 33% for some of its tests.

gcc/c-family/ChangeLog:

	* c-pragma.c (handle_pragma_diagnostic): Split the
	unknown-option -Wpragmas diagnostic into a warning and a
	subsequent note containing a spelling suggestion.  Avoid
	computing the suggestion if -Wpragmas warnings are being
	suppressed.

gcc/testsuite/ChangeLog:

	* gcc.dg/pragma-diag-6.c: Adjust expected diagnostics
	accordingly.
This commit is contained in:
Patrick Palka 2020-11-09 11:14:00 -05:00
parent 4394b1ce77
commit 6624075e7e
2 changed files with 15 additions and 13 deletions

View file

@ -809,16 +809,15 @@ handle_pragma_diagnostic(cpp_reader *ARG_UNUSED(dummy))
unsigned int option_index = find_opt (option_string + 1, lang_mask);
if (option_index == OPT_SPECIAL_unknown)
{
option_proposer op;
const char *hint = op.suggest_option (option_string + 1);
if (hint)
warning_at (loc, OPT_Wpragmas,
"unknown option after %<#pragma GCC diagnostic%> kind;"
" did you mean %<-%s%>?", hint);
else
warning_at (loc, OPT_Wpragmas,
"unknown option after %<#pragma GCC diagnostic%> kind");
auto_diagnostic_group d;
if (warning_at (loc, OPT_Wpragmas,
"unknown option after %<#pragma GCC diagnostic%> kind"))
{
option_proposer op;
const char *hint = op.suggest_option (option_string + 1);
if (hint)
inform (loc, "did you mean %<-%s%>?", hint);
}
return;
}
else if (!(cl_options[option_index].flags & CL_WARNING))

View file

@ -2,7 +2,10 @@
#pragma GCC diagnostic error "-Wnoexcept" /* { dg-warning "is valid for C../ObjC.. but not for C" } */
#pragma GCC diagnostic error "-fstrict-aliasing" /* { dg-warning "not an option that controls warnings" } */
#pragma GCC diagnostic error "-Werror" /* { dg-warning "not an option that controls warnings" } */
#pragma GCC diagnostic error "-Wvla2" /* { dg-warning "unknown option after '#pragma GCC diagnostic' kind; did you mean '-Wvla'" } */
#pragma GCC diagnostic error "-Walla" /* { dg-warning "unknown option after '#pragma GCC diagnostic' kind; did you mean '-Wall'" } */
#pragma GCC diagnostic warning "-Walla" /* { dg-warning "unknown option after '#pragma GCC diagnostic' kind; did you mean '-Wall'" } */
#pragma GCC diagnostic error "-Wvla2" /* { dg-warning "unknown option after '#pragma GCC diagnostic' kind" } */
/* { dg-message "did you mean '-Wvla'" "" { target *-*-* } .-1 } */
#pragma GCC diagnostic error "-Walla" /* { dg-warning "unknown option after '#pragma GCC diagnostic' kind" } */
/* { dg-message "did you mean '-Wall'" "" { target *-*-* } .-1 } */
#pragma GCC diagnostic warning "-Walla" /* { dg-warning "unknown option after '#pragma GCC diagnostic' kind" } */
/* { dg-message "did you mean '-Wall'" "" { target *-*-* } .-1 } */
int i;