fortran: [PR125761] Unlimited-poly character array section base

When a CLASS(*) array section carrying a CHARACTER payload is passed
as the base of an array reference, build_array_ref and
gfc_build_array_ref computed the element span from the dynamic type's
vptr size alone, ignoring the unlimited-polymorphic object's _len
field.  For a deferred-length character payload this gave the wrong
element size, so the section's data pointer was offset incorrectly by
the lower bound, producing wrong code (no ICE needed to reproduce: a
section of a CLASS(*) character array passed to a procedure reads from
the wrong address).

	PR fortran/125761

gcc/fortran/ChangeLog:

	* trans-array.cc (build_array_ref): When the descriptor's
	canonical type is a class type, pass the class container as
	'decl' to gfc_build_array_ref for genuine array element
	references (rank > 0), so the element size can be corrected
	for an unlimited-polymorphic character payload.
	* trans-types.cc (gfc_typenode_for_spec): Move setting the
	GFC_CLASS_TYPE_P bit to..
	(gfc_get_derived_type): .. and use attr.is_class.
	(gfc_get_derived_type): Move setting the GFC_CLASS_TYPE_P bit
	as the last step before returning the derived->backend_decl
	if the derived->attr.is_class is true.

gcc/testsuite/ChangeLog:

	* gfortran.dg/select_type_53.f90: New test.
3 files changed