@@ -12,6 +12,10 @@ module polymorphic_test
1212 procedure :: elemental_fct
1313 procedure :: elemental_sub
1414 procedure , pass(this) :: elemental_sub_pass
15+ procedure :: read_p1
16+ procedure :: write_p1
17+ generic :: read (formatted) = > read_p1
18+ generic :: write (formatted) = > write_p1
1519 generic :: assignment (= ) = > assign_p1_int
1620 procedure :: host_assoc
1721 procedure , pass(poly) :: lt
@@ -681,6 +685,43 @@ subroutine test_elemental_sub_poly_array_assumed(p)
681685! CHECK: fir.dispatch "elemental_sub_pass"(%[[EMBOXED]] : !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) (%{{.*}}, %[[EMBOXED]] : !fir.ref<i32>, !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) {pass_arg_pos = 1 : i32}
682686! CHECK: }
683687
688+ subroutine write_p1 (dtv , unit , iotype , v_list , iostat , iomsg )
689+ class(p1), intent (in ) :: dtv
690+ integer , intent (in ) :: unit
691+ character (* ), intent (in ) :: iotype
692+ integer , intent (in ) :: v_list(:)
693+ integer , intent (out ) :: iostat
694+ character (* ), intent (inout ) :: iomsg
695+ ! dummy subroutine for testing purpose
696+ end subroutine
697+
698+ subroutine read_p1 (dtv , unit , iotype , v_list , iostat , iomsg )
699+ class(p1), intent (inout ) :: dtv
700+ integer , intent (in ) :: unit
701+ character (* ), intent (in ) :: iotype
702+ integer , intent (in ) :: v_list(:)
703+ integer , intent (out ) :: iostat
704+ character (* ), intent (inout ) :: iomsg
705+ ! dummy subroutine for testing purpose
706+ end subroutine
707+
708+ subroutine test_polymorphic_io ()
709+ type (p1), target :: t
710+ class(p1), pointer :: p
711+ open (17 , form= ' formatted' , access= ' stream' )
712+ write (17 , 1 ) t
713+ 1 Format (1X ,I10)
714+ p = > t
715+ rewind(17 )
716+ read (17 , 1 ) p
717+ end subroutine
718+
719+ ! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_polymorphic_io() {
720+ ! CHECK: %[[P:.*]] = fir.alloca !fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> {bindc_name = "p", uniq_name = "_QMpolymorphic_testFtest_polymorphic_ioEp"}
721+ ! CHECK: %[[LOAD_P:.*]] = fir.load %[[P]] : !fir.ref<!fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>
722+ ! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[LOAD_P]] : (!fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>) -> !fir.box<none>
723+ ! CHECK: %{{.*}} = fir.call @_FortranAioInputDescriptor(%{{.*}}, %[[BOX_NONE]]) {{.*}} : (!fir.ref<i8>, !fir.box<none>) -> i1
724+
684725end module
685726
686727program test
0 commit comments