https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108431
Bug ID: 108431
Summary: Loop variable reaching integer `huge` causes infinte
loop
Product: gcc
Version: 12.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: federico.perini at gmail dot com
Target Milestone: ---
Consider the following tiny program:
program test_huge
use iso_fortran_env, only: int8
integer(int8) :: i
do i=-huge(i),huge(i)
print "('i=',i10,' b=',b8.8)", i,i
end do
end
With gfortran 12.2 on Mac, this causes an infinite loop that never ends. I
guess there is a problem with huge(i)=127, because if use the same bounds with
an implicit loop, I get:
3 | integer(int8), parameter :: a(*) = [(i,i=-huge(i),huge(i))]
| 1
Warning: DO loop at (1) is undefined as it overflows [-Wundefined-do-loop]
I've put this example on godbolt at https://godbolt.org/z/6x7K9a6a3 .
Apparently, this issue affects all gfortran versions from 7.1 up (6.3 is the
last working version),
Federico