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

            Bug ID: 125198
           Summary: [15 regression] Bad code generated with -fcheck=bounds
           Product: gcc
           Version: 16.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: neil.n.carlson at gmail dot com
  Target Milestone: ---

Bad code is generated for the following example when -fcheck=bounds is used.
Runs fine for gfortran 15 and earlier.

module unstr_mesh_type
  type unstr_mesh
    real, allocatable :: normal(:,:)
  contains
    procedure :: compute_geometry
  end type
contains
  subroutine compute_geometry(this)
    class(unstr_mesh), intent(inout) :: this
    print *, this%normal(1,1) ! THIS IS OKAY
    print *, this%normal(:,1) ! SPURIOUS BOUNDS ERROR HERE
  end subroutine
end module

use unstr_mesh_type
type(unstr_mesh) :: mesh
allocate(mesh%normal(3,10), source=0.0)
call mesh%compute_geometry
end

$ gfortran -g -fcheck=bounds example.f90

$ ./a.out
   0.00000000    
At line 11 of file example.f90
Fortran runtime error: Index '1' of dimension 2 of array 'this%normal' outside
of expected range (140722326661965:140722326662001)

Error termination. Backtrace:
#0  0x401cfa in __unstr_mesh_type_MOD_compute_geometry
        at
/home/nnc/Fortran/fortran-compiler-tests/gfortran-bugs/tmp/example.f90:11
#1  0x4022fc in MAIN__
        at
/home/nnc/Fortran/fortran-compiler-tests/gfortran-bugs/tmp/example.f90:18
#2  0x402333 in main
        at
/home/nnc/Fortran/fortran-compiler-tests/gfortran-bugs/tmp/example.f90:15

Reply via email to