Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28922 Discussions

User-defined derived type internal I/O leaks to output_unit when '(dt)' format is used

jwmwalrus
New Contributor I
590 Views

Hi.

The following code

module tvmod
    use ISO_FORTRAN_ENV

    implicit none
    private
    save

    type, public :: tv
        integer(int64) :: tv_secs = 0
        integer(int64) :: tv_nsecs = 0
    contains
        procedure :: write_formatted
        generic :: write(formatted) => write_formatted
    end type

contains
    subroutine write_formatted(this, unit, iotype, v_list, iostat, iomsg)
        class(tv), intent(in) :: this
        integer, intent(in) :: unit
        character(*), intent(in) :: iotype
        integer, intent(in) :: v_list(:)
        integer, intent(out) :: iostat
        character(*), intent(inout) :: iomsg
        write (unit, *, IOSTAT = iostat, IOMSG = iomsg) this%tv_secs, this%tv_nsecs
    end subroutine
end module tvmod

use tvmod

implicit none

character(63) :: list, dt
type(tv) :: v

v = tv(15, 16)

write (list, *) v
write (dt, '(dt)') v

print*,'values='
print*,'list=', trim(list)
print*,'dt=', trim(dt)

end

Is supposed to write ' 15 16' into an internal file regardless of whether the '(dt)' format expression is used or not.

For list-directed write it works, but when the '(dt)' format is used, the first number sort of leaks into stdout (i.e., the output_unit), as shown by the following:

$ ifx -V dt-io-test.f90 && ./a.out 
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2024.0.2 Build 20231213
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

 Intel(R) Fortran 24.0-1238.2
GNU ld (GNU Binutils for Debian) 2.42
                    15 values=
 list=                    15                    16
 dt=                    16

 

2 Replies
Barbara_P_Intel
Employee
560 Views

@jwmwalrus, thank you for reporting this and for the great reproducer. I filed a bug report, CMPLRLLVM-57003. We'll let you know when the fix is available.



0 Kudos
Barbara_P_Intel
Employee
404 Views

@jwmwalrus, look for the fix for this mangled output in ifx 2024.2.0 that will be released in mid-2024.



Reply