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

            Bug ID: 125192
           Summary: Wrong out of bound  detection
           Product: gcc
           Version: 16.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: philippe.wautelet at cnrs dot fr
  Target Milestone: ---

Hello,

The following code triggers a wrong out of bound detection:
> cat bound.f90

program boundcheck_bug
  implicit none

  type isba_pe_t
    real, pointer, dimension(:,:) :: xwg
  end type isba_pe_t
  type isba_npe_t
    type(isba_pe_t), dimension(:), pointer :: al=>null()
  end type isba_npe_t
  type(isba_npe_t) :: npe

  allocate(npe%al(10))
  allocate(npe%al(1)%xwg(3,4))

  call random_number( npe%al(1)%xwg(:,3) )
end program boundcheck_bug

If compiled with gfortran 16.1.0, it gives:
> gfortran -g -fbounds-check bound.f90
> ./a.out
At line 15 of file bound.f90
Fortran runtime error: Index '3' of dimension 2 of array 'npe...%xwg' outside
of expected range (140721260065573:140721260065631)

Error termination. Backtrace:
#0  0x40157d in boundcheck_bug
        at /home/pwautelet/tmp/bound_check/bound.f90:15
#1  0x40180d in main
        at /home/pwautelet/tmp/bound_check/bound.f90:16

This problem was not present in previous GCC versions (15.2 and before).

Reply via email to