From: Patrick Palka Date: Mon, 9 Nov 2020 16:14:00 +0000 (-0500) Subject: c-family: Avoid unnecessary work when -Wpragmas is being ignored X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6624075e7e996d61143bf5fc106fa2cb61c614f6;p=gcc.git 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. --- 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;