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

            Bug ID: 108131
           Summary: Incorrect bound calculation when bound intrinsic used
                    in size expression
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jb at gcc dot gnu.org
  Target Milestone: ---

This is from
https://stackoverflow.com/questions/74814027/where-to-report-possible-gfortran-compiler-bug
. Consider

program test
  integer, parameter :: mg(0:10) = 0
  integer, parameter :: u = ubound(mg, dim=1)
  integer, parameter :: cx(-1:ubound(mg, dim=1)) = 1
  integer, parameter :: cy(-1:10) = 2
  integer, parameter :: cz(-1:u) = 3

  write(*,*) lbound(mg, dim=1), ubound(mg, dim=1)
  write(*,*) lbound(cx, dim=1), ubound(cx, dim=1)
  write(*,*) lbound(cy, dim=1), ubound(cy, dim=1)
  write(*,*) lbound(cz, dim=1), ubound(cz, dim=1)
end program test

Obviously the ubounds of all the 4 arrays should be 10. However running the
program results in:

$ ./a.out
           0          10
          -1          11
          -1          10
          -1          10

This affects master as of today, an earlier 12.x snapshot I had lying around,
and 11.3.0 as shipped with Ubuntu 22.04. Based on a comment on the
stackoverflow question, versions 7, 8, 9, and 10 are ok. Looking at
-fdump-tree-original output, the error occurs already in the gfortran frontend.

Reply via email to