diff --git a/Fortran/UnitTests/CMakeLists.txt b/Fortran/UnitTests/CMakeLists.txt index 5c63b0da1e..9c166a644b 100644 --- a/Fortran/UnitTests/CMakeLists.txt +++ b/Fortran/UnitTests/CMakeLists.txt @@ -2,6 +2,7 @@ add_subdirectory(hello) add_subdirectory(assign-goto) add_subdirectory(cray_pointers_2) +add_subdirectory(defined_io) add_subdirectory(execute_command_line) add_subdirectory(fcvs21_f95) # NIST Fortran Compiler Validation Suite add_subdirectory(finalization) diff --git a/Fortran/UnitTests/defined_io/CMakeLists.txt b/Fortran/UnitTests/defined_io/CMakeLists.txt new file mode 100644 index 0000000000..8b9f2da57c --- /dev/null +++ b/Fortran/UnitTests/defined_io/CMakeLists.txt @@ -0,0 +1,3 @@ +llvm_singlesource() + +file(COPY lit.local.cfg DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") diff --git a/Fortran/UnitTests/defined_io/lit.local.cfg b/Fortran/UnitTests/defined_io/lit.local.cfg new file mode 100644 index 0000000000..1166820260 --- /dev/null +++ b/Fortran/UnitTests/defined_io/lit.local.cfg @@ -0,0 +1,2 @@ +config.traditional_output = True +config.single_source = True diff --git a/Fortran/UnitTests/defined_io/llvm-project-issue-154979.f90 b/Fortran/UnitTests/defined_io/llvm-project-issue-154979.f90 new file mode 100644 index 0000000000..115b54338d --- /dev/null +++ b/Fortran/UnitTests/defined_io/llvm-project-issue-154979.f90 @@ -0,0 +1,65 @@ +! A verbatim copy of test case from https://github.com/llvm/llvm-project/issues/154979 +module llvm_project_issue_154979_m + type base + real, allocatable :: data(:) + complex, allocatable :: cx(:) + + contains + + procedure :: readBaseFmtd + generic :: read(formatted) => readBaseFmtd + end type + + contains + + !! read in the array size before allocating dtv's components + subroutine readBaseFmtd (dtv, unit, iotype, v_list, iostat, iomsg) + class(base), intent(inout) :: dtv + integer, intent(in) :: unit + character(*), intent(in) :: iotype + integer, intent(in) :: v_list(:) + integer, intent(out) :: iostat + character(*), intent(inout) :: iomsg + + integer isize + + read (unit, *, iostat = iostat, iomsg=iomsg) isize + + if (allocated(dtv%data)) deallocate (dtv%data) + + allocate (dtv%data(isize)) + + read (unit, *, iostat=iostat, iomsg=iomsg) dtv%data + read (unit, *, iostat = iostat, iomsg=iomsg) isize + if (allocated(dtv%cx)) deallocate (dtv%cx) + + allocate (dtv%cx(isize)) + + read (unit, *, iostat=iostat, iomsg=iomsg) dtv%cx + end subroutine +end module + +program llvm_project_issue_154979 + use llvm_project_issue_154979_m + integer currentPos, ss + + type(base) :: b1(2) + + + open (1, access='stream', form='formatted', decimal='Comma', status='scratch') + + write (1, '(i4, 10(g15.7))', pos=1, decimal='Point') 10, (i*1.0, i=1, 10) + + inquire (1, pos=currentPos) + + write(1, *, pos=currentPos, decimal='point') 12, (cmplx(i*1.0, i*2.0), i=-12, -1) + + write (1, *) 20, (i*1.22, i=1,20) + write (1, *, sign='plus') 22, (cmplx(i*1.1, i*2.2), i=-10,11) + + allocate (b1(1)%cx(3), b1(2)%data(1000)) + read (1, '(dp, dt, dc, dt)', pos=1) b1 + + print*, size(b1(1)%data) + print*, size(b1(1)%cx) +end program diff --git a/Fortran/UnitTests/defined_io/llvm-project-issue-154979.reference_output b/Fortran/UnitTests/defined_io/llvm-project-issue-154979.reference_output new file mode 100644 index 0000000000..0e89553937 --- /dev/null +++ b/Fortran/UnitTests/defined_io/llvm-project-issue-154979.reference_output @@ -0,0 +1,3 @@ + 10 + 12 +exit 0