From: Jason Merrill <jason@redhat.com>
To: Dmitry Drozodv <da.drozdov85@gmail.com>, jakub@redhat.com
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH v2] c++: side effect in nullptr_t conversion fix
Date: Tue, 16 Jan 2024 16:09:58 -0500 [thread overview]
Message-ID: <3edea91e-96f4-47bf-85f5-6cc296d92beb@redhat.com> (raw)
In-Reply-To: <CAPfxnSmw7cVkTP6w9gwQDH2u48XQCciJLGr2G3qABzMpq2PmMQ@mail.gmail.com>
On 1/11/24 15:34, Dmitry Drozodv wrote:
> You are absolutely right, we can't throw all side-effects away.
>
> + /* C++ [conv.lval]p3:
> + If T is cv std::nullptr_t, the result is a null pointer constant. */
> + return ((TREE_SIDE_EFFECTS (expr) && !CONVERT_EXPR_P (expr))
> + ? build2 (COMPOUND_EXPR, type, expr, val)
> + : val);
This seems to assume that a CONVERT_EXPR can't have any other
side-effects nested in it.
It seems to me a better approach is the one in keep_unused_object_arg
and cp_gimplify_expr, basically
if (TREE_THIS_VOLATILE (e))
e = cp_build_addr_expr (e);
since the address of a volatile lvalue is safe to put on the lhs of a
COMPOUND_EXPR.
> - if (!TREE_SIDE_EFFECTS (e))
> + /* C++ [conv.lval]p3:
> + Convert expr from nullptr to nullptr doesn't have side effect. */
> + if (!TREE_SIDE_EFFECTS (e) || CONVERT_EXPR_P (expr))
I don't see why ocp_convert needs to change at all; if TREE_SIDE_EFFECTS
is set we'll eventually get to cp_convert_to_pointer and can do the
right thing there.
> @@ -770,6 +770,15 @@ split_nonconstant_init (tree dest, tree init)
> && array_of_runtime_bound_p (TREE_TYPE (dest)))
> code = build_vec_init (dest, NULL_TREE, init, /*value-init*/false,
> /*from array*/1, tf_warning_or_error);
> + else if (TREE_CODE (TREE_TYPE(init)) == NULLPTR_TYPE)
> + {
> + /* C++ [conv.lval]p3:
> + If T is cv std::nullptr_t, the result is a null pointer
> constant. */
> + tree val = build_int_cst(TREE_TYPE(dest), 0);
> + tree ie = cp_build_init_expr(dest, val);
Why not just
DECL_INITIAL (dest) = nullptr_node;
?
Also, your mail client is mangling your patch so it doesn't apply
properly. Please see https://gcc.gnu.org/contribute.html for more
information.
Jason
next prev parent reply other threads:[~2024-01-16 21:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-11 20:34 Dmitry Drozodv
2024-01-16 21:09 ` Jason Merrill [this message]
2024-01-18 16:37 ` Dmitry Drozodv
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=3edea91e-96f4-47bf-85f5-6cc296d92beb@redhat.com \
--to=jason@redhat.com \
--cc=da.drozdov85@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@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).