Commit 707024b2 by Janus Weil

re PR fortran/78848 ([OOP] ICE on writing CLASS variable with non-typebound DTIO procedure)

2016-12-18  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/78848
	* trans-io.c (get_dtio_proc): Generate non-typebound DTIO call for class
	variables, if no typebound DTIO procedure is available.

2016-12-18  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/78848
	* gfortran.dg/dtio_22.f90: New test.

From-SVN: r243784
parent 413e859c
2016-12-18 Janus Weil <janus@gcc.gnu.org> 2016-12-18 Janus Weil <janus@gcc.gnu.org>
PR fortran/78848
* trans-io.c (get_dtio_proc): Generate non-typebound DTIO call for class
variables, if no typebound DTIO procedure is available.
2016-12-18 Janus Weil <janus@gcc.gnu.org>
PR fortran/78592 PR fortran/78592
* interfac.c (gfc_find_specific_dtio_proc): Fixup for r243005, making * interfac.c (gfc_find_specific_dtio_proc): Fixup for r243005, making
sure that the generic list is followed through until the end. sure that the generic list is followed through until the end.
......
...@@ -2180,24 +2180,16 @@ get_dtio_proc (gfc_typespec * ts, gfc_code * code, gfc_symbol **dtio_sub) ...@@ -2180,24 +2180,16 @@ get_dtio_proc (gfc_typespec * ts, gfc_code * code, gfc_symbol **dtio_sub)
formatted = true; formatted = true;
} }
if (ts->type == BT_DERIVED) if (ts->type == BT_CLASS)
{ derived = ts->u.derived->components->ts.u.derived;
else
derived = ts->u.derived; derived = ts->u.derived;
*dtio_sub = gfc_find_specific_dtio_proc (derived, last_dt == WRITE,
formatted);
if (*dtio_sub)
return gfc_build_addr_expr (NULL, gfc_get_symbol_decl (*dtio_sub));
}
else if (ts->type == BT_CLASS)
{
gfc_symtree *tb_io_st;
derived = ts->u.derived->components->ts.u.derived; gfc_symtree *tb_io_st = gfc_find_typebound_dtio_proc (derived,
tb_io_st = gfc_find_typebound_dtio_proc (derived,
last_dt == WRITE, formatted); last_dt == WRITE, formatted);
if (tb_io_st) if (ts->type == BT_CLASS && tb_io_st)
{ {
// polymorphic DTIO call (based on the dynamic type)
gfc_se se; gfc_se se;
gfc_expr *expr = gfc_find_and_cut_at_last_class_ref (code->expr1); gfc_expr *expr = gfc_find_and_cut_at_last_class_ref (code->expr1);
gfc_add_vptr_component (expr); gfc_add_vptr_component (expr);
...@@ -2210,11 +2202,17 @@ get_dtio_proc (gfc_typespec * ts, gfc_code * code, gfc_symbol **dtio_sub) ...@@ -2210,11 +2202,17 @@ get_dtio_proc (gfc_typespec * ts, gfc_code * code, gfc_symbol **dtio_sub)
gfc_free_expr (expr); gfc_free_expr (expr);
return se.expr; return se.expr;
} }
} else
{
// non-polymorphic DTIO call (based on the declared type)
*dtio_sub = gfc_find_specific_dtio_proc (derived, last_dt == WRITE,
formatted);
if (*dtio_sub)
return gfc_build_addr_expr (NULL, gfc_get_symbol_decl (*dtio_sub));
}
return NULL_TREE; return NULL_TREE;
} }
/* Generate the call for a scalar transfer node. */ /* Generate the call for a scalar transfer node. */
......
2016-12-18 Janus Weil <janus@gcc.gnu.org> 2016-12-18 Janus Weil <janus@gcc.gnu.org>
PR fortran/78848
* gfortran.dg/dtio_22.f90: New test.
2016-12-18 Janus Weil <janus@gcc.gnu.org>
PR fortran/78592 PR fortran/78592
* gfortran.dg/dtio_21.f90: New test. * gfortran.dg/dtio_21.f90: New test.
......
! { dg-do run }
!
! PR 78848: [OOP] ICE on writing CLASS variable with non-typebound DTIO procedure
!
! Contributed by Mikael Morin <morin-mikael@orange.fr>
module m
type :: t
integer :: i = 123
end type
interface write(formatted)
procedure wf
end interface
contains
subroutine wf(this, unit, b, c, iostat, iomsg)
class(t), intent(in) :: this
integer, intent(in) :: unit
character, intent(in) :: b
integer, intent(in) :: c(:)
integer, intent(out) :: iostat
character, intent(inout) :: iomsg
write (unit, "(i3)", IOSTAT=iostat, IOMSG=iomsg) this%i
end subroutine
end
program p
use m
character(3) :: buffer
class(t), allocatable :: z
allocate(z)
write(buffer,"(DT)") z
if (buffer /= "123") call abort()
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment