Skip to content

[flang] incorrect iostat for failed list-separated read into real #137776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Inker2401 opened this issue Apr 29, 2025 · 2 comments
Closed

[flang] incorrect iostat for failed list-separated read into real #137776

Inker2401 opened this issue Apr 29, 2025 · 2 comments
Assignees
Labels
flang:runtime question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

Comments

@Inker2401
Copy link

Inker2401 commented Apr 29, 2025

There appears to be some (possibly) non-standard conforming behaviour concerning the reading of an internal file (string) containing .. into a real variable. Consider the following program:

program flang_read_dots
  implicit none

  character(len=2) :: str
  real :: x
  complex :: z
  integer  :: n, ierr

  str='..'

  ! With status checks
  read(str,*,iostat=ierr) x ! ierr=0 (success) and then x is read as 0.0 (non-standard behaviour)
  print *, 'Read real number ierr, val =', ierr, x

  read(str,*,iostat=ierr) n ! ierr is non-zero as expected as cannot read to integer
  print *, 'Read integer number ierr, val =', ierr, n

  read(str,*,iostat=ierr) z ! ierr is non-zero as expected as cannot read to complex
  print *, 'Read complex number ierr, val=', ierr, z

  ! Without status checks
  read(str,*) x ! read succeeds (incorrectly!)
  print *, 'Read real number (no stat check) val =', x

  read(str,*) n ! read does not succeed, runtime error raised
  print *, 'Read integer number (no stat check) val =', n

  read(str,*) z ! read does not succeed, runtime warning
  print *, 'Read complex number (no stat check) val =', z
end program flang_read_dots

The str containing .. when read into x gives 0.0 with iostat=0 for success (likewise, iostat is omitted, no runtime error is raised). This appears to be possibly non-standard conforming behaviour, as various other compilers such as ifort, Cray Fortran and gfortran all raise a runtime error (and will also return non-zero iostat codes).

I suspect it has to do with the interpretation decimal point as if str is initialised to hi, then a non-zero iostat value is returned as expected. Similarly, if the decimal="comma" argument is passed into the read statement, a non-zero value for iostat is also returned.

Compiler explorer link: https://godbolt.org/z/9doTaGqKT

@llvmbot llvmbot added the flang Flang issues not falling into any other category label Apr 29, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 29, 2025

@llvm/issue-subscribers-flang-runtime

Author: Visagan Ravindran (Inker2401)

There appears to be some (possibly) non-standard conforming behaviour concerning the reading of an internal file (string) containing `..` into a real variable. Consider the following program:
program flang_read_dots
  implicit none

  character(len=2) :: str
  real :: x
  complex :: z
  integer  :: n, ierr

  str='..'

  ! With status checks
  read(str,*,iostat=ierr) x ! ierr=0 (success) and then x is read as 0.0 (non-standard behaviour)
  print *, 'Read real number ierr, val =', ierr, x

  read(str,*,iostat=ierr) n ! ierr is non-zero as expected as cannot read to integer
  print *, 'Read integer number ierr, val =', ierr, n

  read(str,*,iostat=ierr) z ! ierr is non-zero as expected as cannot read to complex
  print *, 'Read complex number ierr, val=', ierr, z

  ! Without status checks
  read(str,*) x ! read succeeds (incorrectly!)
  print *, 'Read real number (no stat check) val =', x

  read(str,*) n ! read does not succeed, runtime error raised
  print *, 'Read integer number (no stat check) val =', n

  read(str,*) z ! read does not succeed, runtime warning
  print *, 'Read complex number (no stat check) val =', z
end program flang_read_dots

The str containing .. when read into x gives 0.0 with iostat=0 for success (likewise, iostat is omitted, no runtime error is raised). This appears to be possibly non-standard conforming behaviour, as various other compilers such as ifort, Cray Fortran and gfortran all raise a runtime error (and will also return non-zero iostat codes).

I suspect it has to do with the interpretation decimal point as if str is initialised to hi, then a non-zero iostat value is returned as expected. Similarly, if the decimal="comma" argument is passed into the read statement, a non-zero value for iostat is also returned.

Compiler explorer link: https://godbolt.org/z/9doTaGqKT

@EugeneZelenko EugeneZelenko removed the flang Flang issues not falling into any other category label Apr 29, 2025
@klausler klausler self-assigned this May 8, 2025
@klausler
Copy link
Contributor

klausler commented May 9, 2025

Fortran '77 allows . with no digits as real input, and this usage appears in the FCVS, so we support it.

@klausler klausler closed this as completed May 9, 2025
@EugeneZelenko EugeneZelenko added the question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! label May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:runtime question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
Projects
None yet
Development

No branches or pull requests

5 participants