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

--- Comment #5 from vries at gcc dot gnu.org ---
There's a bit of code in gfc_trans_allocate:
...
      if (code->expr3 && !code->expr3->mold)
        {
          /* Initialization via SOURCE block (or static default initializer).
             Classes need some special handling, so catch them first.  */
          if (expr3 != NULL_TREE
              && TREE_CODE (expr3) != POINTER_PLUS_EXPR
              && code->expr3->ts.type == BT_CLASS
              && (expr->ts.type == BT_CLASS
                  || expr->ts.type == BT_DERIVED))
            {
              /* copy_class_to_class can be used for class arrays, too.
                 It just needs to be ensured, that the decl_saved_descriptor
                 has a way to get to the vptr.  */
              tree to;
              to = VAR_P (se.expr) ? se.expr : TREE_OPERAND (se.expr, 0);
              tmp = gfc_copy_class_to_class (expr3, to,
                                             nelems, upoly_expr);
            }
...

Without r229621, we have:
...
(gdb) call debug_generic_expr (expr3)
(struct integrand *) previous->_data.data + (sizetype) ((previous->_data.offset
+ (integer(kind=8)) self->_data->steps * previous->_data.dim[0].stride) *
(integer(kind=8)) previous->_vptr->_size)
(gdb) p expr3.base.code
$10 = POINTER_PLUS_EXPR
...
and the gfc_copy_class_to_class is not triggered.

With r229621, we have:
...
(gdb) call debug_generic_expr (expr3)
(struct integrand *) (previous->_data.data + (sizetype)
((previous->_data.offset + (integer(kind=8)) self->_data->steps *
previous->_data.dim[0].stride) * (integer(kind=8)) previous->_vptr->_size))
(gdb) p expr3.base.code
$1 = NOP_EXPR
...
and the gfc_copy_class_to_class is triggered, and we hit the assert.

So AFAIU, r229621 inhibits folding in this case. That looks not incorrect to
me.

I've got no idea what the POINTER_PLUS_EXPR test in the bit above is trying to
achieve (and more generally, I've got little knowledge of fortran, and no
knowledge of the fortran frontend), so I've got no idea how this assert should
be fixed.

Reply via email to