https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113128
Bug ID: 113128
Summary: Wrong implied-do with optimizations
Product: gcc
Version: 12.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: gigor-ads at yandex dot ru
Target Milestone: ---
Hello!
With the following small example (called test.f90):
program main
implicit none
integer, parameter :: nal = 5, nbe = 4
real(8) :: v(nal,nal,nbe,nbe)
integer :: i,j,k,l
open(16,file='ijklab',form='unformatted')
write(16) ((((v(i,k,j,l),i=1,merge(k,nal,l==j)),j=1,l),k=1,nal),l=1,nbe)
close(16)
end program main
With different level of optimizations, one can get file 'ijklab' with different
sizes.
With -O0:
gfortran -O0 test.f90 -o test.O0 && ./test.O0 && ls -la
-rw-rw-r-- 1 user group 1688 Dec 24 18:02 ijklab
With -O1:
gfortran -O1 test.f90 -o test.O1 && ./test.O1 && ls -la
-rw-rw-r-- 1 user group 2008 Dec 24 18:04 ijklab
Tested version:
$ gfortran --version
GNU Fortran (GCC) 12.2.0 20220819 (HPE)
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1688 bytes is a correct answer.