https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104391
Bug ID: 104391
Summary: Gfortran 9 regression with bind(C) and allocatable or
pointer attribute
Product: gcc
Version: 9.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: michael at scivision dot dev
Target Milestone: ---
The `bind(C)` on a procedure appears to break `pointer` and `allocatable`
attributes of a variable with regard to index start. Specifically, on exiting a
procedure with `bind(c)`, the variable(s) have their indices shifted to
zero-based.
example that works with GCC <= 8.5 and GCC 12 (broken for GCC 9, 10, 11).
```
program test_bounds
use iso_fortran_env, only : error_unit
implicit none
real, allocatable :: a(:)
integer :: L1,L2, U1,U2
allocate(a(1:2))
L1 = lbound(a,1)
U1 = ubound(a,1)
call c_bounder(a)
L2 = lbound(a,1)
U2 = ubound(a,1)
if (L1 /= L2 .or. U1 /= U2) then
write(error_unit, '(a,2i2,a,2i2)') 'FAIL: bounds changed before/after
lower:', L1,L2, " upper: ", U1,U2
error stop
endif
print '(a)', "bounds check OK"
contains
subroutine c_bounder(a) bind(c)
real, intent(inout) :: a(:)
end subroutine c_bounder
end program
```