-
Notifications
You must be signed in to change notification settings - Fork 187
gfortran: Arithmetic overflow converting INTEGER(16) to INTEGER(4) in stdlib_hash_32bit.f90 #635
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
Comments
The following option |
Thanks. When I run
it works. The source files are compiled with the options
Please excuse a naive question, which is more about fpm, but where are those options coming from? |
It seems like a gfortran 9's bug , and gfortran 10 and after fixed it. |
These options are triggerred by |
The hash codes emulate unsigned arithmetic using signed arithmetic assuming the underlying arithmetic is two's complement for integer over or under flows. While there have been processors that use one's complement or signed magnitude implementations, such processors do not currently have a hosted Fortran 90+ compiler and the only processors with hosted Fortran 90 compilers have two's complement signed integers. Such compilers find it easiest to implement signed arithmetic using two's complement arithmetic. However over and underflowing in many contexts represent an error in the code and compilers often have flags to turn on or off over and underflow detection. As there is a performance cost for such detection, detection is typically turned off for runtime processing with significant optimization. However there is no such cost for compile time processing, and gfortran 9.x and earlier by default reported an error when a hexadecimal literal (which is defined to be an unsigned integer) was larger than the largest positive integer of that kind. The default for those versions of the compiler could be overridden by setting the flag |
This effectively breaks the use of stdlib as a dependency of conda-forge builds on MacOS, where GFortran 9.3.0 is the current default. |
What prevents conda-forge from using the |
@wclodius2 nothing it turns out. I was fetching stdlib with the CMake example here and apparently the standard compiler flags for stdlib are not retained in this procedure. I could now add |
I pushed a fix for keeping the |
@awvwgk @Beliavsky was this issue solved by #642? Should it be closed? |
This is only fixed for the CMake build, it is still an issue for fpm. |
The hash module (or any module relying on two-complement modulo arithmetic) should be compiled with
|
Thank you Ivan for the heads up. Could this flag -fwrapv be used with
gfortran <13?
Le lun. 21 oct. 2024 à 00:15, Ivan Pribec ***@***.***> a
écrit :
… The hash module (or any module relying on two-complement modulo
arithmetic) should be compiled with -fwrapv flag when using gfortran
>=v13. Details given in the release notes
<https://gcc.gnu.org/gcc-13/porting_to.html>:
GCC 13 includes new optimizations which may change behavior on integer
overflow. Traditional code, like linear congruential pseudo-random number
generators in old programs and relying on a specific, non-standard behavior
may now generate unexpected results. The option -fsanitize=undefined can be
used to detect such code at runtime.
It is recommended to use the intrinsic subroutine RANDOM_NUMBER for random
number generators or, if the old behavior is desired, to use the -fwrapv
option. Note that this option can impact performance.
—
Reply to this email directly, view it on GitHub
<#635 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD5RO7EBZFA4SDVRNSH2SZTZ4QTP7AVCNFSM6AAAAABQI5JMLGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMRVGI2TGMRUGI>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
It can indeed. That is more explicit. I think the correct way to add file-specific flags in CMake is something like:
|
I ran
git checkout stdlib-fpm
. My gfortran version on WSL2 isWhen I build with fpm I get
Error: Arithmetic overflow converting INTEGER(16) to INTEGER(4) at (1)
in stdlib_hash_32bit.f90
The text was updated successfully, but these errors were encountered: