Skip to content
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

Flang Binary Release 2019-03-29: NaN > 0 #1337

Closed
zaikunzhang opened this issue Dec 12, 2022 · 5 comments
Closed

Flang Binary Release 2019-03-29: NaN > 0 #1337

zaikunzhang opened this issue Dec 12, 2022 · 5 comments

Comments

@zaikunzhang
Copy link

zaikunzhang commented Dec 12, 2022

This is a bug in Flang Binary Release 2019-03-29, which evaluates NaN > 0 to .TRUE..

Since I have not succeeded in building Flang, and there is no up-to-date binary release, I am still using this old version.
I am not sure whether the same problem exists in the current version. It would be great if someone can check it.

Code:

program test_nan_flang                                                                                                               
use, intrinsic :: ieee_arithmetic, only : ieee_value, ieee_quiet_nan, ieee_is_nan                                                    
                                                                                                                                     
implicit none                                                                                                                        
                                                                                                                                     
real :: a                                                                                                                            
                                                                                                                                     
a = ieee_value(a, ieee_quiet_nan)                                                                                                    
                                                                                                                                     
print *, a, ieee_is_nan(a), a > 0, a >= a, a == a, a <= a                                                                                                                                            
                                                                                                                                     
end program test_nan_flang 

Result:

$  uname -a && flang --version && flang -O1 test_nan_flang.f90 && ./a.out             
Linux 5.4.0-135-generic #152-Ubuntu SMP Wed Nov 23 20:19:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
clang version 7.0.1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
             NaN  T  T  T  T  T 

Thank you very much!

@bryanpkc
Copy link
Collaborator

@zaikunzhang I tried your test in a recent build of classic-flang-llvm-project/release_14x with flang/legacy (sorry I don't have the exact commit hashes), and it produces this output:

$ ./a.out
             NaN  T  F  F  F  F

So I don't think this problem exists in the latest version of the code. I will double-check with release_15x and master.

@zaikunzhang
Copy link
Author

zaikunzhang commented Dec 16, 2022

Thank you @bryanpkc for checking this. It is great to know that the latest version does not have the same issue.

@zaikunzhang
Copy link
Author

I hope to mention that the bug arises only if flang is invoked with -O or higher optimization options. Without -O, the result is

./a.out 
             NaN  T  F  T  T  T

which is wrong as well, but NaN > 0 is evaluated to .FALSE..

@bryanpkc
Copy link
Collaborator

I ran with release_15x and master as well, with -O2, and the output is still correct.

@zaikunzhang
Copy link
Author

zaikunzhang commented Dec 19, 2022

Hi @bryanpkc . Thank you again for checking this. I have succeeded in compiling release_15x and made the test. As you observed, the bug does not affect release_15x, which is great. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants