Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28632 Discussions

Wrong overflow warning in parameter statement in ifx and ifort

martinmath
New Contributor I
483 Views

Both current compilers (classical 2021.10.0 20230609, ifx 2023.2.0 20230721) print an overflow warning for the line, defining parameter b2. Interestingly all numbers are correct and output is as it should be. So no internal overflow actually happened.

program smallest_int

implicit none

integer(4), parameter :: a1 = -huge(0_4) - 1_4
integer(4), parameter :: a2 = ibset(0_4, bit_size(0_4)-1_4)

integer(4), parameter :: b1 = a1 + 1_4
integer(4), parameter :: b2 = a2 + 1_4

print *, a1, a2, b1, b2

end program smallest_int

As this is from some rather old code, the problem must have been introduced recently.

3 Replies
Barbara_P_Intel
Employee
459 Views

Just love your tiny reproducers!

Are these the results you expect?

 -2147483648 -2147483648 -2147483647 -2147483647

I compiled and ran with the previous Fortran compilers ifx 2023.1.0 and ifort 2021.9.0 and there is no warning message.

I filed a bug report, CMPLRLLVM-50199, asking if this is a bug or a feature? I'll let you know what I find out.



0 Kudos
martinmath
New Contributor I
404 Views

Thanks. Yes, these are the number to expect in 32 bit signed integer model (-2^31 and -2^31+1). As a1 and a2 are equal, it is surprising to see only a warning for b2. I can still see this, if a1 and a2 are defined elsewhere. So I guess, these values are stored internally as 64bit. Then bit pattern of a1 is different than a2, and in particular a1 is a positive number not fitting into 32 bit signed integer.

 

0 Kudos
Barbara_P_Intel
Employee
277 Views

This erroneous error message is gone with ifx and ifort in the latest release 2024.0. It was released earlier this week. Please give it a try!



0 Kudos
Reply