From: Richard Biener <richard.guenther@gmail.com>
To: Alexandre Oliva <oliva@adacore.com>
Cc: Jason Merrill <jason@redhat.com>, GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] c++: set loc on call even if result is discarded
Date: Fri, 8 Apr 2022 08:42:32 +0200 [thread overview]
Message-ID: <CAFiYyc3npCjJ8KzPPUTc3PKyrRha74xObmZSYKQSN=AfK=AmVA@mail.gmail.com> (raw)
In-Reply-To: <ork0c033yc.fsf_-_@lxoliva.fsfla.org>
On Fri, Apr 8, 2022 at 12:49 AM Alexandre Oliva via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> On Apr 6, 2022, Jason Merrill <jason@redhat.com> wrote:
>
> > On 4/6/22 15:37, Alexandre Oliva wrote:
> > Need to adjust this subject line, as well.
>
> *nod*, thanks
>
> >> * tree.cc (protected_set_expr_location): Propagate locus to
> >> call wrapped in cast-to-void.
>
> > I'm reluctant to put this C++-specific change in a simple function
> > shared by all languages;
>
> Perhaps it benefits other languages as well? The effect is presumably
> desirable on other languages too: setting a cast-to-void's location
> seems completely ineffective, as it's eventually thrown away, and
> perhaps propagating the location to any operand (rather than just calls)
> would carry out the intent of [protected_]set_expr_location more
> effectively. It doesn't feel right to require every caller to worry
> about that.
Hmm, but then maybe it would be better the task of the code
actually throwing away the cast? I agree the original
proposed location to fix this looks bad.
> > how about handling it in set_cleanup_locs instead?
>
> Like this? That seems reasonable to me. I'll give it a spin.
>
> diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
> index a7f6449dafd2e..43627ed30afcb 100644
> --- a/gcc/cp/semantics.cc
> +++ b/gcc/cp/semantics.cc
> @@ -609,7 +609,17 @@ set_cleanup_locs (tree stmts, location_t loc)
> {
> if (TREE_CODE (stmts) == CLEANUP_STMT)
> {
> - protected_set_expr_location (CLEANUP_EXPR (stmts), loc);
> + tree t = CLEANUP_EXPR (stmts);
> + protected_set_expr_location (t, loc);
> + /* Avoid locus differences for C++ cdtor calls depending on whether
> + cdtor_returns_this: a conversion to void is added to discard the return
> + value, and this conversion ends up carrying the location, and when it
> + gets discarded, the location is lost. So hold it in the call as
> + well. */
> + if (TREE_CODE (t) == NOP_EXPR
> + && TREE_TYPE (t) == void_type_node
> + && TREE_CODE (TREE_OPERAND (t, 0)) == CALL_EXPR)
> + protected_set_expr_location (TREE_OPERAND (t, 0), loc);
> set_cleanup_locs (CLEANUP_BODY (stmts), loc);
> }
> else if (TREE_CODE (stmts) == STATEMENT_LIST)
>
>
> --
> Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/
> Free Software Activist GNU Toolchain Engineer
> Disinformation flourishes because many people care deeply about injustice
> but very few check the facts. Ask me about <https://stallmansupport.org>
next prev parent reply other threads:[~2022-04-08 6:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-06 19:37 Alexandre Oliva
2022-04-06 21:19 ` Jason Merrill
2022-04-07 22:48 ` [PATCH] c++: " Alexandre Oliva
2022-04-08 6:42 ` Richard Biener [this message]
2022-04-09 3:45 ` Jason Merrill
2022-04-11 15:19 ` [PATCH v2] " Alexandre Oliva
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='CAFiYyc3npCjJ8KzPPUTc3PKyrRha74xObmZSYKQSN=AfK=AmVA@mail.gmail.com' \
--to=richard.guenther@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=oliva@adacore.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).