https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120788

            Bug ID: 120788
           Summary: gfortran problem with integer overflow comparison
           Product: gcc
           Version: 15.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dolev.ronen at mail dot huji.ac.il
  Target Milestone: ---

Code:

program bug
implicit none
integer, parameter :: K4B = selected_int_kind(9)
integer(K4B), parameter :: hg = huge(1_K4B), hgm=-hg, hgng = hgm-1
integer(K4B) :: hgt
hgt = hg        
write(*, *) "hgng = ", hgng
write(*, *) "hgt + 1 = ", hgt + 1
write(*, *) "hgt + 1 /= hgng = ", hgt + 1 /= hgng
write(*, *) "hgt + 1 == hgng = ", hgt + 1 == hgng
end program bug

Expected output (which is the same as ifx output):

hgng =  -2147483648
hgt + 1 =  -2147483648
hgt + 1 /= hgng =  F
hgt + 1 == hgng =  T

gfortran output:

hgng =  -2147483648
hgt + 1 =  -2147483648
hgt + 1 /= hgng =  T
hgt + 1 == hgng =  F

Comment:
we can see that although both hgng and hgt + 1 = -2147483648 (hgt + 1 is an
overflow) gfortran states that they are unequal. 

compilation through bash terminal.
gfortran compilation: gfortran -Wall -O0 -fcheck=all bug.f90 -o bug.exe
ifx compilation: ifx -warn all -O0 -check all bug.f90 -o bug.exe

gfortran version: GNU Fortran (GCC) 15.1.0
ifx version: ifx (IFX) 2025.1.1 20250418

Reply via email to