| Issue |
243201
|
| Summary |
[flang-rt] B/O/Z input: a blank among leading zeros causes a false overflow
|
| Labels |
flang:runtime
|
| Assignees |
|
| Reporter |
eugeneepshteyn
|
In a B, O or Z input field, a blank among the leading zeros makes the next zero count as a significant digit, so a value that fits is rejected with an overflow error. This happens under both BN and BZ.
```fortran
program bn_leading_zero
implicit none
integer :: i, ios
character(11) :: s
s = '0 0FFFFFFFF'
read (s, '(bn,z11)', iostat=ios) i
print '(a,i0,a,z0)', 'BN, with blank: iostat=', ios, ' value=', i
read (s, '(bz,z11)', iostat=ios) i
print '(a,i0,a,z0)', 'BZ, with blank: iostat=', ios, ' value=', i
s = '000FFFFFFFF'
read (s, '(bn,z11)', iostat=ios) i
print '(a,i0,a,z0)', 'BN, without blank: iostat=', ios, ' value=', i
end program
```
flang (main at 20b943451383):
```
BN, with blank: iostat=1034 value=0
BZ, with blank: iostat=1034 value=0
BN, without blank: iostat=0 value=FFFFFFFF
```
Expected, and what gfortran prints: `iostat=0 value=FFFFFFFF` on all three lines. Under BN the blank is ignored (F2023 13.8.7 p2), and under BZ it is a zero, so either way the field has the value `Z'FFFFFFFF'`, which fits in a default INTEGER.
Cause: `EditBOZInput` skips leading zeros only while the next character is `'0'` ([edit-input.cpp#L54-L64](https://github.com/llvm/llvm-project/blob/24580866f5d731e4962829e7b0f298092ceacb0f/flang-rt/lib/runtime/edit-input.cpp#L54-L64)). The blank ends the skip, and every zero after it is counted as a significant digit: nine hexadecimal digits here, more than a 4-byte integer holds.
Found while reviewing PR 238057, which does not change this.
(This issue was filed with the help of AI)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs