https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118120
Bug ID: 118120
Summary: Wrong aliasing assumptions for Fortran POINTERs
Product: gcc
Version: 14.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: szakharin at nvidia dot com
Target Milestone: ---
Sample code:
====
subroutine test(result, i, j, data)
integer :: i, j
complex, target :: data(21)
real, pointer :: result(:,:,:,:)
complex, pointer, save :: temp(:,:)
result(i:i,j:j,1:4,1:5) => data(2:)%re
temp(1:4,1:5) => data
result(i,j,:,:) = abs(temp)
end subroutine test
program main
interface
subroutine test(result, i, j, data)
integer :: i, j
complex, target :: data(21)
real, pointer :: result(:,:,:,:)
complex, pointer, save :: temp(:,:)
end subroutine test
end interface
real, pointer :: result(:,:,:,:)
complex, target :: data(21)
do k=1,21
data(k) = cmplx(-k,0.0)
end do
call test(result, 1, 1, data)
print *, data
end program main
====
# gfortran -std=f2008 alias.f90 -O0
/a.out prints (-1, 1, 1, ..., 1)
The correct result is: (-1, 1, 2, ..., 20)
result and temp POINTERs obviously alias inside 'test' subroutine, but the
elemental ABS operation is performed on temp along with writing into result
causing incorrect result.