public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-5316] c++: TARGET_EXPR_ELIDING_P and std::move [PR107267]
Date: Mon, 23 Jan 2023 23:35:18 +0000 (GMT)	[thread overview]
Message-ID: <20230123233518.DE57A3858C2F@sourceware.org> (raw)

https://gcc.gnu.org/g:4cbc71691e47b1ca6b64feb0af678606705d2f92

commit r13-5316-g4cbc71691e47b1ca6b64feb0af678606705d2f92
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jan 23 17:14:11 2023 -0500

    c++: TARGET_EXPR_ELIDING_P and std::move [PR107267]
    
    With -ffold-simple-inlines, we turn calls to std::move into the static_cast
    equivalent.  In this testcase, this exposes the FindResult temporary to copy
    elision which is not specified by the standard, through an optimization in
    gimplify_modify_expr_rhs.  Since the type is not TREE_ADDRESSABLE, this is
    not detectable by the user, so we just need to soften the assert.
    
            PR c++/107267
    
    gcc/cp/ChangeLog:
    
            * cp-gimplify.cc (cp_gimplify_init_expr): Allow unexpected elision
            of trivial types.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/move2.C: New test.

Diff:
---
 gcc/cp/cp-gimplify.cc              |  5 ++++-
 gcc/testsuite/g++.dg/cpp0x/move2.C | 14 ++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc
index 340b4641046..83ba1285bfd 100644
--- a/gcc/cp/cp-gimplify.cc
+++ b/gcc/cp/cp-gimplify.cc
@@ -250,7 +250,10 @@ cp_gimplify_init_expr (tree *expr_p)
   if (TREE_CODE (from) == TARGET_EXPR)
     if (tree init = TARGET_EXPR_INITIAL (from))
       {
-	gcc_checking_assert (TARGET_EXPR_ELIDING_P (from));
+	/* Make sure that we expected to elide this temporary.  But also allow
+	   gimplify_modify_expr_rhs to elide temporaries of trivial type.  */
+	gcc_checking_assert (TARGET_EXPR_ELIDING_P (from)
+			     || !TREE_ADDRESSABLE (TREE_TYPE (from)));
 	if (target_expr_needs_replace (from))
 	  {
 	    /* If this was changed by cp_genericize_target_expr, we need to
diff --git a/gcc/testsuite/g++.dg/cpp0x/move2.C b/gcc/testsuite/g++.dg/cpp0x/move2.C
new file mode 100644
index 00000000000..b8c8683c4d2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/move2.C
@@ -0,0 +1,14 @@
+// PR c++/107267
+// { dg-do compile { target c++11 } }
+// { dg-additional-options -ffold-simple-inlines }
+
+namespace std {
+  template<typename _Tp> _Tp &&move(_Tp &&);
+}
+
+struct FindResult {
+  FindResult();
+  int result;
+};
+
+FindResult pop_ret = std::move(FindResult());

                 reply	other threads:[~2023-01-23 23:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230123233518.DE57A3858C2F@sourceware.org \
    --to=jason@gcc.gnu.org \
    --cc=gcc-cvs@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).