From: Andrew Pinski <quic_apinski@quicinc.com>
To: <gcc-patches@gcc.gnu.org>
Cc: Andrew Pinski <quic_apinski@quicinc.com>
Subject: [PATCH 3/3] Add parentheses around DECL_INIT for .original [PR23872]
Date: Thu, 2 May 2024 14:39:18 -0700 [thread overview]
Message-ID: <20240502213918.2029860-3-quic_apinski@quicinc.com> (raw)
In-Reply-To: <20240502213918.2029860-1-quic_apinski@quicinc.com>
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.
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-02 21:39 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 ` Andrew Pinski [this message]
2024-05-03 11:40 ` [PATCH 3/3] Add parentheses around DECL_INIT for " Richard Biener
2024-05-03 22:12 ` Andrew Pinski
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=20240502213918.2029860-3-quic_apinski@quicinc.com \
--to=quic_apinski@quicinc.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).