public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "lhyatt at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/53431] C++ preprocessor ignores #pragma GCC diagnostic Date: Sat, 04 Dec 2021 17:48:45 +0000 [thread overview] Message-ID: <bug-53431-4-x9c0s3XKkH@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-53431-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431 Lewis Hyatt <lhyatt at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |lhyatt at gcc dot gnu.org --- Comment #44 from Lewis Hyatt <lhyatt at gcc dot gnu.org> --- I have a patch for this submitted to the mailing list here: https://gcc.gnu.org/pipermail/gcc-patches/2021-December/586191.html Initially I tried resurrecting Manuel's patch from comment #10 and got it working, however it led to other issues for C++. The problem is that, with that change, the C++ frontend processes the pragmas too early, instead of too late; it processes every #pragma GCC diagnostic in the file prior to handling any tokens. This makes a large demand on the diagnostics infrastructure, namely that it correctly handles every case of processing source lines and determining which #pragmas are in effect at that time and which are for the future. This infrastructure is in place and generally works, however it doesn't handle all cases, notably a change to the argument of an option (say something like, #pragma GCC diagnostic warning "-Wimplicit-fallthrough=4") is not tracked properly (see also PR c/71603). The state of warning options is also often queried directly by the frontend code, not making use of the diagnostics state tracking facilities, and this also leads to warnings being generated or not generated unexpectedly. So this patch leads to a lot of testcase failures, for example, c-c++-common/Wshadow-1.c. I think in the ideal case, it should be made to work correctly that all diagnostic pragmas could be parsed prior to processing the tokens and everything would work, but this seems like a large overhaul. I can try to tackle improving that later, but for the purpose of resolving this PR, I thought it was worth trying another approach, which is just to arrange that every frontend does indeed handle the #pragma when it needs to. My patch does things this way, it adds the concept of an early pragma handler, which can be registered similar to a normal one and runs in addition to it. The early handler for diagnostic pragmas then filters for libcpp-generated diagnostics and processes those when called. Then the C++ frontend, and gcc -E, are both modified to make use of it. This asks much less of the state tracking, since only libcpp diagnostics are handled early. The C++ frontend changes are not too extensive, it basically notes when it sees a CPP_PRAGMA_EOL token during initial parsing, and if so, it handles it immediately. In order to reuse the existing handler for diagnostic pragmas, it sets up the main lexer so that it is sufficiently prepared for pragma_lex() to work, which is all that is needed. For preprocessing mode, I needed to refactor the code for handle_diagnostic_pragma a bit, since in preprocess-only mode, there is no C or C++ parser available and the tokens need to be lexed directly from libcpp. I also needed adjustments in c-ppoutput.c to make sure, as Manuel pointed out, that we do still output the #pragma GCC diagnostic in the preprocessed output. I hope this looks workable, happy to adjust the patch as needed.
next prev parent reply other threads:[~2021-12-04 17:48 UTC|newest] Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-05-21 8:03 [Bug c++/53431] New: C++ preprocessor ignores #pragma GCC diagnostic ignored "-Wundef" ml.lattuada at libero dot it 2013-02-17 17:04 ` [Bug c++/53431] " rainarchitect at gmail dot com 2013-03-03 4:10 ` markus at oberhumer dot com 2013-07-12 9:20 ` nomegenerico at email dot it 2013-11-16 18:13 ` rainarchitect at gmail dot com 2013-11-16 19:51 ` manu at gcc dot gnu.org 2013-11-16 20:23 ` manu at gcc dot gnu.org 2014-09-05 17:42 ` [Bug c++/53431] C++ preprocessor ignores #pragma GCC diagnostic manu at gcc dot gnu.org 2015-06-03 8:27 ` manu at gcc dot gnu.org 2015-07-20 9:38 ` manu at gcc dot gnu.org 2015-07-22 0:00 ` noloader at gmail dot com 2015-07-22 10:51 ` redi at gcc dot gnu.org 2015-07-22 11:24 ` noloader at gmail dot com 2015-07-23 10:34 ` noloader at gmail dot com 2015-07-23 10:47 ` redi at gcc dot gnu.org 2015-07-23 11:32 ` manu at gcc dot gnu.org 2015-07-23 13:20 ` manu at gcc dot gnu.org 2015-07-23 23:26 ` noloader at gmail dot com 2015-07-30 17:22 ` miyuki at gcc dot gnu.org 2021-02-27 11:24 ` noloader at gmail dot com 2021-06-03 12:04 ` redi at gcc dot gnu.org 2021-10-06 14:40 ` jakub at gcc dot gnu.org 2021-12-01 17:43 ` egallager at gcc dot gnu.org 2021-12-04 17:48 ` lhyatt at gcc dot gnu.org [this message] 2021-12-19 11:55 ` pinskia at gcc dot gnu.org 2021-12-19 19:50 ` manu at gcc dot gnu.org 2021-12-24 21:29 ` lhyatt at gcc dot gnu.org 2022-03-23 0:58 ` pinskia at gcc dot gnu.org 2022-05-25 13:38 ` lhyatt at gcc dot gnu.org 2022-06-29 16:08 ` lhyatt at gcc dot gnu.org 2022-07-06 19:40 ` cvs-commit at gcc dot gnu.org 2022-07-06 19:42 ` lhyatt at gcc dot gnu.org 2022-07-06 22:59 ` lhyatt at gcc dot gnu.org 2022-11-08 22:28 ` redi at gcc dot gnu.org 2022-11-09 0:05 ` markus at oberhumer dot com
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=bug-53431-4-x9c0s3XKkH@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@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).