From: Andrew Pinski <pinskia@gmail.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: Andrew Pinski <quic_apinski@quicinc.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH 3/3] Add parentheses around DECL_INIT for .original [PR23872]
Date: Fri, 3 May 2024 15:12:26 -0700 [thread overview]
Message-ID: <CA+=Sn1miy1PP=1Eq1o=8mBpzgKKSCPm-VPsVwX11CWHzL7_XUg@mail.gmail.com> (raw)
In-Reply-To: <CAFiYyc0MHQETq+=YWBL2gGtv0By_YyrkowtDN6gY0XgQKpy9HQ@mail.gmail.com>
On Fri, May 3, 2024 at 4:41 AM Richard Biener
<richard.guenther@gmail.com> wrote:
>
> On Thu, May 2, 2024 at 11:40 PM Andrew Pinski <quic_apinski@quicinc.com> wrote:
> >
> > When we have :
> > `void f (int y, int z) { int x = ( z++,y); }`
> >
> > This would have printed the decl's initializer without
> > parentheses which can confusion if you think that is defining
> > another variable rather than the compound expression.
> >
> > This adds parenthese around DECL_INIT if it was a COMPOUND_EXPR.
>
> Looking it seems we'd hit a similar issue for
>
> foo ((z++,y), 2);
>
> thus in CALL_EXPR context. Also
>
> int k;
> void foo (int i, int j)
> {
> k = (i, 2) + j;
> }
>
> dumps as
>
> {
> k = i, j + 2;;
> }
>
> (ok that's folded to (i, j + 2) but still).
>
> So shouldn't we bite the bullet and wrap all COMPOUND_EXPRs in
> parens instead? Possibly "tail-calling" the case of
> a, b, c in COMPOUND_EXPR dumping itself?
Let me look into that but it won't be until June due to other things going on.
Thanks,
Andrew
>
> Thanks,
> Richard.
>
> > Bootstrapped and tested on x86_64-linux-gnu.
> >
> > gcc/ChangeLog:
> >
> > * tree-pretty-print.cc (print_declaration): Add parenthese
> > around DECL_INIT if it was a COMPOUND_EXPR.
> >
> > Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
> > ---
> > gcc/tree-pretty-print.cc | 9 ++++++++-
> > 1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/gcc/tree-pretty-print.cc b/gcc/tree-pretty-print.cc
> > index 825ba74443b..8b766dcd2b8 100644
> > --- a/gcc/tree-pretty-print.cc
> > +++ b/gcc/tree-pretty-print.cc
> > @@ -4240,7 +4240,14 @@ print_declaration (pretty_printer *pp, tree t, int spc, dump_flags_t flags, bool
> > pp_equal (pp);
> > pp_space (pp);
> > if (!(flags & TDF_SLIM))
> > - dump_generic_node (pp, DECL_INITIAL (t), spc, flags, false);
> > + {
> > + bool need_paren = TREE_CODE (DECL_INITIAL (t)) == COMPOUND_EXPR;
> > + if (need_paren)
> > + pp_left_paren (pp);
> > + dump_generic_node (pp, DECL_INITIAL (t), spc, flags, false);
> > + if (need_paren)
> > + pp_right_paren (pp);
> > + }
> > else
> > pp_string (pp, "<<< omitted >>>");
> > }
> > --
> > 2.43.0
> >
next prev parent reply other threads:[~2024-05-03 22:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-02 21:39 [PATCH 1/3] Fix printing COMPOUND_EXPR in " Andrew Pinski
2024-05-02 21:39 ` [PATCH 2/3] Improve DECL_EXPR printing " Andrew Pinski
2024-05-03 11:34 ` Richard Biener
2024-05-03 22:11 ` Andrew Pinski
2024-05-02 21:39 ` [PATCH 3/3] Add parentheses around DECL_INIT for " Andrew Pinski
2024-05-03 11:40 ` Richard Biener
2024-05-03 22:12 ` Andrew Pinski [this message]
2024-05-03 11:29 ` [PATCH 1/3] Fix printing COMPOUND_EXPR in " Richard Biener
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='CA+=Sn1miy1PP=1Eq1o=8mBpzgKKSCPm-VPsVwX11CWHzL7_XUg@mail.gmail.com' \
--to=pinskia@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=quic_apinski@quicinc.com \
--cc=richard.guenther@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).