2024-11-24 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran/ChangeLog
PR fortran/85869
* trans-expr.cc (trans_class_vptr_len_assignment): To access
the '_len' field, re must be unlimited polymorphic.
gcc/testsuite/
PR fortran/85869
* gfortran.dg/pr85869.f90: Comment out test of component refs.
/* trans-expr.cc-- generate GENERIC trees for gfc_expr. */
+#define INCLUDE_MEMORY
#include "config.h"
#include "system.h"
#include "coretypes.h"
vptr_expr = NULL;
se.expr = gfc_class_vptr_get (GFC_DECL_SAVED_DESCRIPTOR (
re->symtree->n.sym->backend_decl));
- if (to_len)
+ if (to_len && UNLIMITED_POLY (re))
from_len = gfc_class_len_get (GFC_DECL_SAVED_DESCRIPTOR (
re->symtree->n.sym->backend_decl));
}
--- /dev/null
+! { dg-do compile }
+!
+! Test the fix for PR85869, where line 19 segfaulted.
+!
+! Contributed by Gerhard Steinmetz <gscfq@t-online.de>
+!
+program p
+ type t
+ integer :: i
+ end type
+ call s
+contains
+ function f()
+ class(t), allocatable :: f(:)
+ f = [(t(i), i = 1, 10)]
+ end
+ subroutine s
+ class(*), allocatable :: z(:)
+ allocate (z, source = f ()) ! Segfault in gfc_class_len_get.
+ select type (z)
+ type is (t)
+ if (any (z%i /= [(i, i = 1,10)])) stop 1
+ end select
+ end
+end