https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99281

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-valid-code
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-02-26

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  We're building a temporary of type X which we shouldn't do when
expanding

get<int> (&D.2164) [return slot optimization]

and we run into

#2  0x0000000000fd165a in expand_call (exp=<call_expr 0x7ffff66ed818>, 
    target=0x0, ignore=0) at /home/rguenther/src/gcc3/gcc/calls.c:3878
3873            else
3874              {
3875                /* For variable-sized objects, we must be called with a
target
3876                   specified.  If we were to allocate space on the stack
here,
3877                   we would have no way of knowing when to free it.  */
3878                rtx d = assign_temp (rettype, 1, 1);
3879                structure_value_addr = XEXP (d, 0);
3880                target = 0;

because target is NULL when we come via

#7  0x0000000001197afe in expand_assignment (to=<component_ref 0x7ffff66d9390>,
from=<call_expr 0x7ffff66ed818>, 
    nontemporal=false) at /home/rguenther/src/gcc3/gcc/expr.c:5482
5481              else
5482                result = store_field (to_rtx, bitsize, bitpos,
5483                                      bitregion_start, bitregion_end,
5484                                      mode1, from, get_alias_set (to),
5485                                      nontemporal, reversep);

and the large conditional on

  /* If the structure is in a register or if the component
     is a bit field, we cannot use addressing to access it.
     Use bit-field techniques or SUBREG to store in it.  */

somehow misfires on this, specifically there is

          /* And except for bitwise copying of TREE_ADDRESSABLE types,
             where the FIELD_DECL has the right bitsize, but TREE_TYPE (exp)
             includes some extra padding.  store_expr / expand_expr will in
             that case call get_inner_reference that will have the bitsize
             we check here and thus the block move will not clobber the
             padding that shouldn't be clobbered.  In the future we could
             replace the TREE_ADDRESSABLE check with a check that
             get_base_address needs to live in memory.  */
          && (!TREE_ADDRESSABLE (TREE_TYPE (exp))
              || TREE_CODE (exp) != COMPONENT_REF
              || !multiple_p (bitsize, BITS_PER_UNIT)
              || !multiple_p (bitpos, BITS_PER_UNIT)
              || !poly_int_tree_p (DECL_SIZE (TREE_OPERAND (exp, 1)),
                                   &decl_bitsize)
              || maybe_ne (decl_bitsize, bitsize)))

maybe sth as simple as the following works (instead of for return-slot-opt
we can also test !TREE_ADDRESSABLE here or boht for the testcase)

diff --git a/gcc/expr.c b/gcc/expr.c
index 86dc1b6c973..54007ac0efe 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -7214,7 +7214,10 @@ store_field (rtx target, poly_int64 bitsize, poly_int64
bitpos,
              || !multiple_p (bitpos, BITS_PER_UNIT)
              || !poly_int_tree_p (DECL_SIZE (TREE_OPERAND (exp, 1)),
                                   &decl_bitsize)
-             || maybe_ne (decl_bitsize, bitsize)))
+             || maybe_ne (decl_bitsize, bitsize))
+         /* A call with return-slot-opt must not need bitfield operations.  */
+         && (TREE_CODE (exp) != CALL_EXPR
+             || !CALL_EXPR_RETURN_SLOT_OPT (exp)))
       /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
          decl we must use bitfield operations.  */
       || (known_size_p (bitsize)


note clang warns

t.ii:27:5: warning: expression result unused [-Wunused-value]
    pack_type<X>{get(1)};
    ^           ~~~~~~~~

Reply via email to