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 compile time is reduced by 33% in some of its tests. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? 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 appropriately. --- gcc/c-family/c-pragma.c | 19 +++++++++---------- gcc/testsuite/gcc.dg/pragma-diag-6.c | 9 ++++++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c index dc52ee8b003..d68985ca277 100644 --- a/gcc/c-family/c-pragma.c +++ b/gcc/c-family/c-pragma.c @@ -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)) diff --git a/gcc/testsuite/gcc.dg/pragma-diag-6.c b/gcc/testsuite/gcc.dg/pragma-diag-6.c index 0dca1dc1ef4..f2df88d245b 100644 --- a/gcc/testsuite/gcc.dg/pragma-diag-6.c +++ b/gcc/testsuite/gcc.dg/pragma-diag-6.c @@ -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; -- 2.29.2.154.g7f7ebe054a