&& sym->attr.codimension && !sym->attr.allocatable)))
TREE_STATIC (decl) = 1;
- /* If derived-type variables with DTIO procedures are not made static
- some bits of code referencing them get optimized away.
- TODO Understand why this is so and fix it. */
- if (!sym->attr.use_assoc
- && ((sym->ts.type == BT_DERIVED
- && sym->ts.u.derived->attr.has_dtio_procs)
- || (sym->ts.type == BT_CLASS
- && CLASS_DATA (sym)->ts.u.derived->attr.has_dtio_procs)))
- TREE_STATIC (decl) = 1;
-
/* Treat asynchronous variables the same as volatile, for now. */
if (sym->attr.volatile_ || sym->attr.asynchronous)
{
integer_type_node, gfc_charlen_type_node);
iocall[IOCALL_X_DERIVED] = gfc_build_library_function_decl_with_spec (
- get_identifier (PREFIX("transfer_derived")), ". w r ",
+ get_identifier (PREFIX("transfer_derived")), ". w w ",
void_type_node, 2, dt_parm_type, pvoid_type_node);
/* Library entry points */
--- /dev/null
+! { dg-do run }
+! { dg-additional-options "-O2" }
+!
+! PR fortran/125059 - derived type IO and automatic deallocation
+! PR fortran/111952
+
+module m
+ type t
+ integer :: i = 42
+ contains
+ procedure :: w
+ generic :: write(formatted) => w
+ end type t
+contains
+ subroutine w(dtv,unit,iotype,v_list,iostat,iomsg)
+ class(t), intent(in) :: dtv
+ integer, intent(in) :: unit
+ character(len=*),intent(in) :: iotype
+ integer, intent(in) :: v_list(:)
+ integer, intent(out) :: iostat
+ character(len=*),intent(inout) :: iomsg
+ write(unit,*,iostat=iostat,iomsg=iomsg) dtv%i
+ end subroutine w
+end
+
+program p
+ use m
+ call f()
+ call f()
+contains
+ subroutine f()
+ type(t), allocatable :: a(:)
+ allocate (a(1))
+ print *, a(1)
+ end subroutine f
+end