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
[runtime] Fix off-by-one error in minimum integers #916
[runtime] Fix off-by-one error in minimum integers #916
Conversation
From a practical perspective (how many ones-complement machines are there?), this seems OK. It's not clear to me without more digging, though, if this is legal Fortran. The definition of model integers in the standard (F2018 subclause 16.4) defines model integers only through the equivalent of -HUGE(the integer kind under consideration). |
@gklimowicz I read that part of the language standard and I was wondering about the same thing. However, neither flang nor gfortran complains about the use of |
@bryanpkc Yeah. It's hard to argue against that. I will stop. :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passes on OpenPOWER on LLVM 9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. A trivial comment inline (can be ignored).
runtime/flang/const.c defines min_int{1,2,4,8} to be -max_int{1,2,4,8}, which is wrong for the two's complement representation. As a result, the MAXLOC runtime function will compare each element in the input array with an incorrect minimum value. If the array contains -huge(integer)-1, MAXLOC will return an unexpected result.
05bf6d8
to
b9bde8d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. thanks
@bryanpkc please merge if no further changes required. You have approval from everyone i guess. |
Thanks @kiranchandramohan. |
runtime/flang/const.c defines min_int{1,2,4,8} to be -max_int{1,2,4,8}, which is wrong for the two's complement representation. As a result, the MAXLOC runtime function will compare each element in the input array with an incorrect minimum value. If the array contains -huge(integer)-1, MAXLOC will return an unexpected result.