]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: lvalue_kind tweak
authorJason Merrill <jason@redhat.com>
Mon, 3 Oct 2022 21:16:38 +0000 (17:16 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 5 Oct 2022 14:09:51 +0000 (10:09 -0400)
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.

gcc/cp/tree.cc

index aa9c1b7d8f97b03099508f98e9092d62fb58e82e..6d968a2af11e15cbed9bf8d41a21904164ee7801 100644 (file)
@@ -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:
       {