public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Lewis Hyatt <lhyatt@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1863] preprocessor: Set input_location to the most recently seen token Date: Wed, 27 Jul 2022 22:10:52 +0000 (GMT) [thread overview] Message-ID: <20220727221052.0AFC0385829F@sourceware.org> (raw) https://gcc.gnu.org/g:219f86495791fd27b012678f13e10cada211daab commit r13-1863-g219f86495791fd27b012678f13e10cada211daab Author: Lewis Hyatt <lhyatt@gmail.com> Date: Sun Jul 10 09:30:29 2022 -0400 preprocessor: Set input_location to the most recently seen token When preprocessing with -E and -save-temps, input_location points always to the first character of the current file. This was previously irrelevant because nothing was called during the token streaming process that would inspect input_location. But since r13-1544, "#pragma GCC diagnostic" is supported in preprocess-only mode, and that pragma relies on input_location to decide if a given source code location is subject to a diagnostic or not. Most diagnostics work fine anyway, because they are handled as soon as they are seen and so everything is still seen in the expected order even though all the diagnostic pragmas are treated as if they applied at the start of the file. One example that doesn't work correctly is the new testcase, since here the warning is not triggered until the end of the file and so it is necessary to track the location properly. Fixed by setting input_location to point to each token as it is being streamed, similar to how C++ mode sets it. gcc/c-family/ChangeLog: * c-ppoutput.cc (token_streamer::stream): Update input_location prior to streaming each token. gcc/testsuite/ChangeLog: * c-c++-common/pragma-diag-14.c: New test. * c-c++-common/pragma-diag-15.c: New test. Diff: --- gcc/c-family/c-ppoutput.cc | 4 ++++ gcc/testsuite/c-c++-common/pragma-diag-14.c | 9 +++++++++ gcc/testsuite/c-c++-common/pragma-diag-15.c | 13 +++++++++++++ 3 files changed, 26 insertions(+) diff --git a/gcc/c-family/c-ppoutput.cc b/gcc/c-family/c-ppoutput.cc index cd38c969ea0..98081ccfbb0 100644 --- a/gcc/c-family/c-ppoutput.cc +++ b/gcc/c-family/c-ppoutput.cc @@ -210,6 +210,10 @@ void token_streamer::stream (cpp_reader *pfile, const cpp_token *token, location_t loc) { + /* Keep input_location up to date, since it is needed for processing early + pragmas such as #pragma GCC diagnostic. */ + input_location = loc; + if (token->type == CPP_PADDING) { avoid_paste = true; diff --git a/gcc/testsuite/c-c++-common/pragma-diag-14.c b/gcc/testsuite/c-c++-common/pragma-diag-14.c new file mode 100644 index 00000000000..618e7e1ef27 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pragma-diag-14.c @@ -0,0 +1,9 @@ +/* { dg-do preprocess } */ +/* { dg-additional-options "-Wunused-macros" } */ + +/* In the past, the pragma has erroneously disabled the warning because the + location was not tracked properly with -E or -save-temps; check that it works + now. */ + +#define X /* { dg-warning "-:-Wunused-macros" } */ +#pragma GCC diagnostic ignored "-Wunused-macros" diff --git a/gcc/testsuite/c-c++-common/pragma-diag-15.c b/gcc/testsuite/c-c++-common/pragma-diag-15.c new file mode 100644 index 00000000000..d8076b4f93a --- /dev/null +++ b/gcc/testsuite/c-c++-common/pragma-diag-15.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-Wunused-macros" } */ + +/* In the past, the pragma has erroneously disabled the warning because the + location was not tracked properly with -E or -save-temps; check that it works + now. + + This test currently fails for C++ but it's not because of the pragma, it's + because the location of the macro definition is incorrectly set. This is a + separate issue, will resolve it in a later patch. */ + +#define X /* { dg-warning "-:-Wunused-macros" {} { xfail c++ } } */ +#pragma GCC diagnostic ignored "-Wunused-macros"
reply other threads:[~2022-07-27 22:10 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220727221052.0AFC0385829F@sourceware.org \ --to=lhyatt@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).