https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87000
Bug ID: 87000
Summary: LBOUND and UBOUND give unexpected result for arrays
without 1-based indices if in subprogram
Product: gcc
Version: 8.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libfortran
Assignee: unassigned at gcc dot gnu.org
Reporter: gavin.keith.ridley at gmail dot com
Target Milestone: ---
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.