https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87000
kargl at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |kargl at gcc dot gnu.org --- Comment #1 from kargl at gcc dot gnu.org --- (In reply to Gavin Ridley from comment #0) > If an array is allocated with indices that don't start at one, lbound and > ubound seem to give incorrect answers if the array is passed to any > subprogram. This program clearly illustrates the issue, compiled with no > flags: > > program asdf > use iso_fortran_env > implicit none > real(real64), dimension(-5:10) :: arr > print *, 'lbound = ', lbound(arr) > print *, 'ubound = ', ubound(arr) > call boundprinter(arr) > > contains > subroutine boundprinter(x) > real(real64), intent(in), dimension(:) :: x > print *, 'lbound = ', lbound(x) > print *, 'ubound = ', ubound(x) > endsubroutine boundprinter > endprogram asdf > > Which prints: > > lbound = -5 > ubound = 10 > lbound = 1 > ubound = 16 > > Shouldn't these be consistent? > > Very notably, it seems gcc 4 gives the correct answer, but not gcc 8.1.0. > This bug causes segfaults in a program called MPACT developed by Oak Ridge > National Lab and University of Michigan which I'd estimate somewhere between > 50 and 100 people use. As a result of this, all of their compiles are still > done on gcc 4. I think you may have found a bug in your code. F2003, 5.1.2.5.2, Assumed-shape array An assumed-shape array is a nonpointer dummy argument array that takes its shape from the associated actual argument array. R514 assumed-shape-spec is [ lower-bound ] : The rank is equal to the number of colons in the assumed-shape-spec-list. The extent of a dimension of an assumed-shape array dummy argument is the extent of the corresponding dimension of the associated actual argument array. If the lower bound value is 'd' and the extent of the corresponding dimension of the associated actual argument array is 's', then the value of the upper bound is 's + d - 1'. The lower bound is 'lower-bound', if present, and 1 otherwise. Of course, I could be wrong.