public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: David Malcolm <dmalcolm@redhat.com>
Cc: "Joseph S. Myers" <joseph@codesourcery.com>,
	Marek Polacek <polacek@redhat.com>,
	gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c: Improve build_component_ref diagnostics [PR91134]
Date: Wed, 25 May 2022 14:28:42 +0200	[thread overview]
Message-ID: <Yo4g+ndezNqLa6j8@tucnak> (raw)
In-Reply-To: <1093d0af9045b777cb3994b35070149b5f2f03ee.camel@redhat.com>

On Tue, May 24, 2022 at 09:59:03AM -0400, David Malcolm wrote:
> > 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?

Done, see another mail.

> 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.

--- pr91134.c
+++ pr91134.c
@@ -10,19 +10,19 @@
   struct X *pointer = &x;
   struct Y *yp = &y;
   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 i = *(*pointerpointer)->member;	/* { dg-error "'pointerpointer' is a pointer to pointer; did you mean to dereference it before applying '->' to it\\\?" } */
 /* { dg-begin-multiline-output "" }
    int i = *pointerpointer->member;
                           ^~
             (*            )
    { dg-end-multiline-output "" } */
-  int j = pointer.member;		/* { dg-error "'pointer' is a pointer; did you mean to use '->'\\\?" } */
+  int j = pointer->member;		/* { dg-error "'pointer' is a pointer; did you mean to use '->'\\\?" } */
 /* { dg-begin-multiline-output "" }
    int j = pointer.member;
                   ^
                   ->
    { dg-end-multiline-output "" } */
-  int k = yp->x->member;		/* { dg-error "'yp->x' is a pointer to pointer; did you mean to dereference it before applying '->' to it\\\?" } */
+  int k = (*yp->x)->member;		/* { dg-error "'yp->x' is a pointer to pointer; did you mean to dereference it before applying '->' to it\\\?" } */
 /* { dg-begin-multiline-output "" }
    int k = yp->x->member;
                 ^~

The second and third change actually fix those issues and make it compile,
the first one will generate a different error, because the right
change in that case is int i = (*pointerpointer)->member;
but guessing that in the compiler would be too hard, when
parsing pointerpointer->member we really don't know that
there is * before it...

	Jakub


      reply	other threads:[~2022-05-25 12:28 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
2022-05-25 12:28     ` Jakub Jelinek [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=Yo4g+ndezNqLa6j8@tucnak \
    --to=jakub@redhat.com \
    --cc=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --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).