Issue |
137776
|
Summary |
[flang] incorrect iostat for failed list-separated read into real
|
Labels |
flang
|
Assignees |
|
Reporter |
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](https://godbolt.org/z/9doTaGqKT)
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs