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/114423] Incorrectly placed caret in the message about expanded _Pragma Date: Fri, 22 Mar 2024 14:48:56 +0000 [thread overview] Message-ID: <bug-114423-4-Xt6Jx4vO4c@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-114423-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114423 Lewis Hyatt <lhyatt at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |lhyatt at gcc dot gnu.org --- Comment #2 from Lewis Hyatt <lhyatt at gcc dot gnu.org> --- libcpp is unfortunately not equipped to get valid locations when it lexes from a _Pragma string. (It thinks it is lexing from a file as normal.) The locations are wrong even without macros involved. The current situation is that we produce invalid locations (that happen to usually be close to reasonable, without macros, although they will be off by a few columns usually) for all the tokens, then after lexing the tokens, we replace all of their locations with the (valid) location of the _Pragma operator. This is good enough to make _Pragma("GCC diagnostic") work and do the right thing (after many bug fixes over the years), which has been the primary focus. But it means that any diagnostics generated by libcpp during lexing itself have bad locations. I submitted a rather large patch series a couple years ago that fixed it comprehensively. The bulk of it is that the line_map class needs to be able to handle locations for data that exist in memory and not in any file. Then all code that uses line_map locations and all diagnostics code needs to be aware of that concept and support it. The thread was left off here, for reference: https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628290.html with the last full patchset I sent being at https://gcc.gnu.org/pipermail/gcc-patches/2023-August/626885.html. It worked fine then, however a lot of interfaces have been changed since that time, and so it would need to be rebased extensively now. FWIW, with the above-linked patch series, on this example we output: ====== In buffer generated from t.cpp:1: <generated>:1:11: error: message 1 | GCC error "message" | ^~~~~~~~~ t.cpp:1:1: note: in <_Pragma directive> 1 | _Pragma("GCC error \"message\"") | ^~~~~~~ In buffer generated from t.cpp:6: <generated>:1:11: error: message 1 | GCC error "message" | ^~~~~~~~~ t.cpp:4:1: note: in <_Pragma directive> 4 | _Pragma("GCC error \"message\"") | ^~~~~~~ t.cpp:6:1: note: in expansion of macro ‘err’ 6 | err | ^~~ ====== I am not sure why I stopped getting responses to that patch series. I was disinclined to ping it further because I worried that it was perhaps deemed too large and invasive, to fix what ends up being a rather minor problem in practice? I think it would be doable to handle it with a more incremental approach... we could at least achieve that diagnostics generated during lexing get assigned to the valid location of the _Pragma operator instead of an invalid one.
prev parent reply other threads:[~2024-03-22 14:48 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-03-21 22:20 [Bug preprocessor/114423] New: " centurionn009 at gmail dot com 2024-03-21 22:24 ` [Bug c/114423] " pinskia at gcc dot gnu.org 2024-03-22 14:48 ` lhyatt at gcc dot gnu.org [this message]
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-114423-4-Xt6Jx4vO4c@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).