public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>,
	"Joseph S. Myers" <joseph@codesourcery.com>,
	Marek Polacek <polacek@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c: Improve build_component_ref diagnostics [PR91134]
Date: Tue, 24 May 2022 09:59:03 -0400	[thread overview]
Message-ID: <1093d0af9045b777cb3994b35070149b5f2f03ee.camel@redhat.com> (raw)
In-Reply-To: <801f6986dc99c122fb095459fe943dbadd58333c.camel@redhat.com>

On Tue, 2022-05-24 at 09:57 -0400, David Malcolm wrote:
> On Tue, 2022-05-24 at 09:25 +0200, Jakub Jelinek via Gcc-patches
> wrote:
> > Hi!
> > 
> > On the following testcase (the first dg-error line) we emit a weird
> > diagnostics and even fixit on pointerpointer->member
> > where pointerpointer is pointer to pointer to struct and we say
> > 'pointerpointer' is a pointer; did you mean to use '->'?
> > The first part is indeed true, but suggesting -> when the code
> > already
> > does use -> is confusing.
> > The following patch adjusts callers so that they tell it if it is
> > from
> > . parsing or from -> parsing and in the latter case suggests to
> > dereference
> > the left operand instead by adding (* before it and ) after it
> > (before ->).
> > Or would a suggestion to add [0] before -> be better?
> > 
> > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> > trunk?
> > 
> 
> [...snip implementation...]
> 
> >  
> > --- gcc/testsuite/gcc.dg/pr91134.c.jj   2022-05-23
> > 20:31:11.751001817
> > +0200
> > +++ gcc/testsuite/gcc.dg/pr91134.c      2022-05-23
> > 20:30:45.291268997
> > +0200
> > @@ -0,0 +1,13 @@
> > +/* PR c/91134 */
> > +
> > +struct X { int member; } x;
> > +
> > +int
> > +foo (void)
> > +{
> > +  struct X *pointer = &x;
> > +  struct X **pointerpointer = &pointer;
> > +  int i = *pointerpointer->member;     /* { dg-error
> > "'pointerpointer' is a pointer to pointer; did you mean to
> > dereference it before applying '->' to it\\\?" } */
> > +  int j = pointer.member;              /* { dg-error "'pointer' is
> > a
> > pointer; did you mean to use '->'\\\?" } */
> > +  return i + j;
> > +}
> 
> Ideally we'd have an automated check that the fix-it hint fixes the
> code, but failing that, I like to have at least some DejaGnu test
> coverage for fix-it hints - something like the tests in
> gcc.dg/fixits.c
> or gcc.dg/semicolon-fixits.c, perhaps?

Also, what does the output from:
  -fdiagnostics-generate-patch
look like?  That's usually the best way of checking if we're generating
good fix-it hints.

Dave


  reply	other threads:[~2022-05-24 13:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-24  7:25 Jakub Jelinek
2022-05-24 13:43 ` Marek Polacek
2022-05-25 12:24   ` Jakub Jelinek
2022-05-24 13:57 ` David Malcolm
2022-05-24 13:59   ` David Malcolm [this message]
2022-05-25 12:28     ` Jakub Jelinek

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=1093d0af9045b777cb3994b35070149b5f2f03ee.camel@redhat.com \
    --to=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=polacek@redhat.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).