diff --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp --- a/flang/lib/Lower/IO.cpp +++ b/flang/lib/Lower/IO.cpp @@ -599,9 +599,10 @@ const fir::ExtendedValue &item) { mlir::Type argType = inputFunc.getFunctionType().getInput(1); llvm::SmallVector inputFuncArgs = {cookie}; - if (argType.isa()) { + if (argType.isa()) { mlir::Value box = fir::getBase(item); - assert(box.getType().isa() && "must be previously emboxed"); + assert(box.getType().isa() && + "must be previously emboxed"); inputFuncArgs.push_back(builder.createConvert(loc, argType, box)); } else { mlir::Value itemAddr = fir::getBase(item); diff --git a/flang/test/Lower/polymorphic.f90 b/flang/test/Lower/polymorphic.f90 --- a/flang/test/Lower/polymorphic.f90 +++ b/flang/test/Lower/polymorphic.f90 @@ -10,6 +10,10 @@ procedure :: print procedure :: assign_p1_int procedure :: elemental_fct + procedure :: read_p1 + procedure :: write_p1 + generic :: read(formatted) => read_p1 + generic :: write(formatted) => write_p1 generic :: assignment(=) => assign_p1_int procedure :: host_assoc end type @@ -543,4 +547,41 @@ ! CHECK: %{{.*}} = fir.call @_FortranAioOutputDescriptor(%{{.*}}, %[[BOX_NONE]]) fastmath : (!fir.ref, !fir.box) -> i1 ! CHECK: fir.freemem %[[TMP]] : !fir.heap> + subroutine write_p1(dtv, unit, iotype, v_list, iostat, iomsg) + class(p1), intent(in) :: dtv + integer, intent(in) :: unit + character(*), intent(in) :: iotype + integer, intent(in) :: v_list(:) + integer, intent(out) :: iostat + character(*), intent(inout) :: iomsg + ! dummy subroutine for testing purpose + end subroutine + + subroutine read_p1(dtv, unit, iotype, v_list, iostat, iomsg) + class(p1), intent(inout) :: dtv + integer, intent(in) :: unit + character(*), intent(in) :: iotype + integer, intent(in) :: v_list(:) + integer, intent(out) :: iostat + character(*), intent(inout) :: iomsg + ! dummy subroutine for testing purpose + end subroutine + + subroutine test_polymorphic_io() + type(p1), target :: t + class(p1), pointer :: p + open(17, form='formatted', access='stream') + write(17, 1) t + 1 Format(1X,I10) + p => t + rewind(17) + read(17, 1) p + end subroutine + +! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_polymorphic_io() { +! CHECK: %[[P:.*]] = fir.alloca !fir.class>> {bindc_name = "p", uniq_name = "_QMpolymorphic_testFtest_polymorphic_ioEp"} +! CHECK: %[[LOAD_P:.*]] = fir.load %[[P]] : !fir.ref>>> +! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[LOAD_P]] : (!fir.class>>) -> !fir.box +! CHECK: %{{.*}} = fir.call @_FortranAioInputDescriptor(%{{.*}}, %[[BOX_NONE]]) {{.*}} : (!fir.ref, !fir.box) -> i1 + end module