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-3092] c++: lvalue_kind tweak
Date: Wed,  5 Oct 2022 14:10:32 +0000 (GMT)	[thread overview]
Message-ID: <20221005141032.9DD8F3857378@sourceware.org> (raw)

https://gcc.gnu.org/g:49192c41de94b2746cd33366134b6aeaefa6ca2a

commit r13-3092-g49192c41de94b2746cd33366134b6aeaefa6ca2a
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Oct 3 17:16:38 2022 -0400

    c++: lvalue_kind tweak
    
    I was wondering how lvalue_kind handles VIEW_CONVERT_EXPR; in cases where
    the type actually changes, it should have the same prvalue->xvalue effect as
    ARRAY_REF, since we need to materialize a temporary to get an object we can
    reinterpret as another type.
    
    Currently this only fires on builtin-shufflevector-3.c, where we use
    VIEW_CONVERT_EXPR to reinterpret a vector as an array.
    
    REALPART_EXPR and IMAGPART_EXPR should also be treated like COMPONENT_REF.
    PREINCREMENT_EXPR and PREDECREMENT_EXPR should only be applied to glvalues,
    but if for some reason they were applied to a prvalue this would be correct.
    TRY_CATCH_EXPR around a prvalue is also questionable, but this is the right
    handling.
    
    gcc/cp/ChangeLog:
    
            * tree.cc (lvalue_kind) [VIEW_CONVERT_EXPR]: Change prvalue to
            xvalue.

Diff:
---
 gcc/cp/tree.cc | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index aa9c1b7d8f9..6d968a2af11 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -104,7 +104,17 @@ lvalue_kind (const_tree ref)
     case REALPART_EXPR:
     case IMAGPART_EXPR:
     case VIEW_CONVERT_EXPR:
-      return lvalue_kind (TREE_OPERAND (ref, 0));
+      op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
+      /* As for ARRAY_REF and COMPONENT_REF, these codes turn a class prvalue
+	 into an xvalue: we need to materialize the temporary before we mess
+	 with it.  Except VIEW_CONVERT_EXPR that doesn't actually change the
+	 type, as in location wrapper and REF_PARENTHESIZED_P.	*/
+      if (op1_lvalue_kind == clk_class
+	  && !(TREE_CODE (ref) == VIEW_CONVERT_EXPR
+	       && (same_type_ignoring_top_level_qualifiers_p
+		   (TREE_TYPE (ref), TREE_TYPE (TREE_OPERAND (ref, 0))))))
+	return clk_rvalueref;
+      return op1_lvalue_kind;
 
     case ARRAY_REF:
       {

                 reply	other threads:[~2022-10-05 14:10 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=20221005141032.9DD8F3857378@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).