[flang] IEEE_IS_NAN sets IEEE_INVALID after inspecting a signaling NaN
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
LLVM Flang leaves the IEEE_INVALID status flag set after IEEE_IS_NAN is applied to a real or double-precision value produced with IEEE_VALUE(..., IEEE_SIGNALING_NAN), even when halting on invalid is disabled and the flag was cleared immediately before the call. Fortran 2018 does not state that IEEE_IS_NAN may signal IEEE_INVALID for a signaling NaN (unlike IEEE_UNORDERED), so the flag should remain unset when the predicate is evaluated without other invalid operations.
Expected output:
The program should run to completion and print a single success line, with IEEE_GET_FLAG(IEEE_INVALID, …) remaining false after each IEEE_IS_NAN call.
Actual Output:
`FAIL real Ieee_Is_Nan raises INVALID`
Reproducer:
```Fortran
Program test
use Ieee_Arithmetic
Real r
Double Precision d
Logical invalid
If (Ieee_Support_Halting(Ieee_Invalid)) &
Call Ieee_Set_Halting_Mode(Ieee_Invalid,.False.)
r = Ieee_Value(r,Ieee_Signaling_Nan)
d = Ieee_Value(d,Ieee_Signaling_Nan)
Call Ieee_Set_Flag(Ieee_Invalid,.False.)
If (.Not.Ieee_Is_NaN(r)) Stop 'FAIL real Ieee_Is_Nan wrong value'
Call Ieee_Get_Flag(Ieee_Invalid,invalid)
If (invalid) Stop 'FAIL real Ieee_Is_Nan raises INVALID'
Call Ieee_Set_Flag(Ieee_Invalid,.False.)
If (.Not.Ieee_Is_NaN(d)) Stop 'FAIL double Ieee_Is_Nan wrong value'
Call Ieee_Get_Flag(Ieee_Invalid,invalid)
If (invalid) Stop 'FAIL double Ieee_Is_Nan raises INVALID'
Print '("Ok")'
End Program test
```
Contributor guide
Research direction
Start at Flang's IEEE_IS_NAN implementation and run the Fortran reproducer from the issue with halting on invalid disabled. Check the IEEE_INVALID flag after each real and double-precision call; done means the program prints a single "Ok" line and both checks remain false.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fortran
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100