From: David Malcolm <dmalcolm@redhat.com>
To: Bernd Schmidt <bschmidt@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Fix missing range information for "%q+D" format code
Date: Fri, 04 Dec 2015 20:45:00 -0000 [thread overview]
Message-ID: <1449261952.8490.55.camel@surprise> (raw)
In-Reply-To: <56617460.8010208@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2645 bytes --]
On Fri, 2015-12-04 at 12:09 +0100, Bernd Schmidt wrote:
> On 12/03/2015 09:33 PM, David Malcolm wrote:
> > The attached patch updates the handling of %q+D, simplifying
> > the implementation, and ensuring that it retains the range
> > information of the decl, giving:
> >
> > diagnostic-ranges-1.c:6:7: warning: unused variable âredundantâ [-Wunused-variable]
> > int redundant;
> > ^~~~~~~~~
>
> For most of it I've convinced myself that it looks OK.
Thanks.
> > void
> > -rich_location::set_range (unsigned int idx, source_range src_range,
> > - bool show_caret_p, bool overwrite_loc_p)
> > +rich_location::set_range (line_maps *set, unsigned int idx,
> > + source_location loc, bool show_caret_p)
> > {
>
> Here you need to update the function comment.
Is the attached suitable?
> This is a bit of a strange function. As far as I can tell, it's called
> from only two places, one in c-common.c (which overwrites idx 0, i.e.
> the entire range, and therefore is uninteresting),
idx 0 is the primary location associated with the rich_location; but I'm
not sure it's strictly correct to say "the entire range". In theory
there could be other locations/ranges within the rich_location e.g. if
someone did something like:
rich_location richloc (loc_A); /* primary loc is "loc_A" */
/* ...then add a couple of other ranges of interest
e.g. to print a bogus infix binary operator,
or somesuch. */
richloc.add_range (range_B);
richloc.add_range (range_C);
/* richloc now has:
idx == 0 (primary) at loc_A
idx == 1 at range_B
idx == 2 at range_C. */
/* emit it... */
error_at_richloc (&richloc,
"something bad involving %q+D", decl);
where the %q+D leads to the idx == 0 location being overwritten by
DECL_SOURCE_LOCATION (decl) instead of loc_A.
> and one in
> text_info::set_location. I wonder about the use of "idx" in the latter.
> As far as I can tell, that's used by the Fortran frontend to keep track
> of two separate ranges for their diagnostics - correct?
Yes. These format codes that manipulate the location of the
diagnostic were one of the big surprises to me when I was writing this.
This function exists to support them.
> Is that really
> related to the normal function of rich_location and how it keeps track
> of multiple ranges,
Yes.
> or would that be better expressed by keeping two
> rich_locations in text_info?
No; keeping track of multiple locations/ranges, potentially with
multiple carets is rich_location's job.
Hope this makes sense; does it look OK with the proposed comment fix?
Dave
[-- Attachment #2: comment.patch --]
[-- Type: text/x-patch, Size: 955 bytes --]
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index 333e835..0c8f328 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -2064,14 +2064,14 @@ rich_location::add_range (location_range *src_range)
m_ranges[m_num_ranges++] = *src_range;
}
-/* Add or overwrite the range given by IDX. It must either
- overwrite an existing range, or add one *exactly* on the end of
+/* Add or overwrite the location given by IDX. It must either
+ overwrite an existing location, or add one *exactly* on the end of
the array.
This is primarily for use by gcc when implementing diagnostic
format decoders e.g. the "+" in the C/C++ frontends, for handling
format codes like "%q+D" (which writes the source location of a
- tree back into range 0 of the rich_location).
+ tree back into location 0 of the rich_location).
If SHOW_CARET_P is true, then the range should be rendered with
a caret at its starting location. This
next prev parent reply other threads:[~2015-12-04 20:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-03 20:13 David Malcolm
2015-12-04 11:09 ` Bernd Schmidt
2015-12-04 20:45 ` David Malcolm [this message]
2015-12-04 21:09 ` David Malcolm
2015-12-07 10:31 ` Bernd Schmidt
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=1449261952.8490.55.camel@surprise \
--to=dmalcolm@redhat.com \
--cc=bschmidt@redhat.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).