public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: Fix location for -Wunused-macros [PR66290]
Date: Sat, 30 Jul 2022 13:59:15 -0600	[thread overview]
Message-ID: <2b81d8e7-7bc7-3a43-2680-925a31c254e6@gmail.com> (raw)
In-Reply-To: <62328b0cdbdd374fdca89723306c34331d0531fa.1659015329.git.lhyatt@gmail.com>



On 7/28/2022 8:01 AM, Lewis Hyatt via Gcc-patches wrote:
> In C++, since all tokens are lexed from libcpp up front, diagnostics generated
> by libcpp after lexing has completed do not get a valid location from libcpp
> (rather, libcpp thinks they all pertain to the end of the file.) This has long
> been addressed using the global variable "done_lexing", which the C++ frontend
> sets at the appropriate time; when done_lexing is true, then c_cpp_diagnostic(),
> which outputs libcpp's diagnostics, uses input_location instead of the wrong
> libcpp location. The C++ frontend arranges that input_location will point to the
> token it is currently processing, so this generally works fine. However, there
> is one exception currently, which is -Wunused-macros. This gets generated at the
> end of processing in cpp_finish (), since we need to wait until then to
> determine whether a macro was eventually used or not. But the locations it
> passes to c_cpp_diagnostic () were remembered from the original lexing and hence
> they should not be overridden with input_location, which is now the one
> incorrectly pointing to the end of the file.
>
> Fixed by setting done_lexing=false again just prior to calling cpp_finish (). I
> also renamed the variable from done_lexing to "override_libcpp_locations", since
> it's now not strictly about lexing anymore.
>
> There is no new testcase with this patch, since we already had an xfailed
> testcase which is now fixed.
>
> gcc/c-family/ChangeLog:
>
> 	PR c++/66290
> 	* c-common.h: Rename global done_lexing to
> 	override_libcpp_locations.
> 	* c-common.cc (c_cpp_diagnostic): Likewise.
> 	* c-opts.cc (c_common_finish): Set override_libcpp_locations
> 	(formerly done_lexing) immediately prior to calling cpp_finish ().
>
> gcc/cp/ChangeLog:
>
> 	PR c++/66290
> 	* parser.cc (cp_lexer_new_main): Rename global done_lexing to
> 	override_libcpp_locations.
>
> gcc/testsuite/ChangeLog:
>
> 	PR c++/66290
> 	* c-c++-common/pragma-diag-15.c: Remove xfail for C++.
Ewww.  But OK.
Jeff


      reply	other threads:[~2022-07-30 19:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-28 14:01 Lewis Hyatt
2022-07-30 19:59 ` Jeff Law [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=2b81d8e7-7bc7-3a43-2680-925a31c254e6@gmail.com \
    --to=jeffreyalaw@gmail.com \
    --cc=gcc-patches@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: link
Be 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).