public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: Lewis Hyatt <lhyatt@gmail.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH 1/6] diagnostics: Fix macro tracking for ad-hoc locations
Date: Fri, 04 Nov 2022 11:53:58 -0400	[thread overview]
Message-ID: <cdc7049afd7a1b0e382d1b8a513a197470c7fdf1.camel@redhat.com> (raw)
In-Reply-To: <44cead99227a4bbb93860813c168163999b8d164.1667514153.git.lhyatt@gmail.com>

On Fri, 2022-11-04 at 09:44 -0400, Lewis Hyatt via Gcc-patches wrote:
> The result of linemap_resolve_location() can be an ad-hoc location,
> if that is
> what was stored in a relevant macro map. 
> maybe_unwind_expanded_macro_loc()
> did not previously handle this case, causing it to print the wrong
> tracking
> information for an example such as the new testcase macro-trace-1.c. 
> Fix that
> by checking for ad-hoc locations where needed.

Thanks; looks good to me.
Dave

> 
> gcc/ChangeLog:
> 
>         * tree-diagnostic.cc (maybe_unwind_expanded_macro_loc):
> Handle ad-hoc
>         location in return value of linemap_resolve_location().
> 
> gcc/testsuite/ChangeLog:
> 
>         * c-c++-common/cpp/macro-trace-1.c: New test.
> ---
>  gcc/testsuite/c-c++-common/cpp/macro-trace-1.c | 4 ++++
>  gcc/tree-diagnostic.cc                         | 7 +++++--
>  2 files changed, 9 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/c-c++-common/cpp/macro-trace-1.c
> 
> diff --git a/gcc/testsuite/c-c++-common/cpp/macro-trace-1.c
> b/gcc/testsuite/c-c++-common/cpp/macro-trace-1.c
> new file mode 100644
> index 00000000000..34cfbb3dad3
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/cpp/macro-trace-1.c
> @@ -0,0 +1,4 @@
> +/* This token is long enough to require an ad-hoc location. Make
> sure that
> +   the macro trace still prints properly.  */
> +#define X "0123456789012345678901234567689" /* { dg-error {expected
> .* before string constant} } */
> +X /* { dg-note {in expansion of macro 'X'} } */
> diff --git a/gcc/tree-diagnostic.cc b/gcc/tree-diagnostic.cc
> index 0d79fe3c3c1..5cf3a1c17d2 100644
> --- a/gcc/tree-diagnostic.cc
> +++ b/gcc/tree-diagnostic.cc
> @@ -190,14 +190,17 @@ maybe_unwind_expanded_macro_loc
> (diagnostic_context *context,
>          location_t l = 
>            linemap_resolve_location (line_table, resolved_def_loc,
>                                      LRK_SPELLING_LOCATION,  &m);
> -        if (l < RESERVED_LOCATION_COUNT || LINEMAP_SYSP (m))
> +       location_t l0 = l;
> +       if (IS_ADHOC_LOC (l0))
> +         l0 = get_location_from_adhoc_loc (line_table, l0);
> +       if (l0 < RESERVED_LOCATION_COUNT || LINEMAP_SYSP (m))
>            continue;
>          
>         /* We need to print the context of the macro definition only
>            when the locus of the first displayed diagnostic
> (displayed
>            before this trace) was inside the definition of the
>            macro.  */
> -        int resolved_def_loc_line = SOURCE_LINE (m, l);
> +       const int resolved_def_loc_line = SOURCE_LINE (m, l0);
>          if (ix == 0 && saved_location_line != resolved_def_loc_line)
>            {
>              diagnostic_append_note (context, resolved_def_loc, 
> 


  reply	other threads:[~2022-11-04 15:54 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-04 13:44 [PATCH 0/6] diagnostics: libcpp: Overhaul locations for _Pragma tokens Lewis Hyatt
2022-11-04 13:44 ` [PATCH 1/6] diagnostics: Fix macro tracking for ad-hoc locations Lewis Hyatt
2022-11-04 15:53   ` David Malcolm [this message]
2022-11-04 13:44 ` [PATCH 2/6] diagnostics: Use an inline function rather than hardcoding <built-in> string Lewis Hyatt
2022-11-04 15:55   ` David Malcolm
2022-11-04 13:44 ` [PATCH 3/6] libcpp: Fix paste error with unknown pragma after macro expansion Lewis Hyatt
2022-11-21 17:50   ` Jeff Law
2022-11-04 13:44 ` [PATCH 4/6] diagnostics: libcpp: Add LC_GEN linemaps to support in-memory buffers Lewis Hyatt
2022-11-05 16:23   ` David Malcolm
2022-11-05 17:28     ` Lewis Hyatt
2022-11-17 21:21     ` Lewis Hyatt
2023-01-05 22:34       ` Lewis Hyatt
2022-11-04 13:44 ` [PATCH 5/6] diagnostics: Support generated data in additional contexts Lewis Hyatt
2022-11-04 16:42   ` David Malcolm
2022-11-04 21:05     ` Lewis Hyatt
2022-11-05  1:54       ` [PATCH 5b/6] diagnostics: Remove null-termination requirement for json::string David Malcolm
2022-11-05  1:55       ` [PATCH 5a/6] diagnostics: Handle generated data locations in edit_context David Malcolm
2022-11-04 13:44 ` [PATCH 6/6] diagnostics: libcpp: Assign real locations to the tokens inside _Pragma strings Lewis Hyatt

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=cdc7049afd7a1b0e382d1b8a513a197470c7fdf1.camel@redhat.com \
    --to=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=lhyatt@gmail.com \
    /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).