Detecting wrongful aliasing at compile or run time

Viewed 87

Is there some tool (or compile flag) that can detect problematic aliasing in Fortran code either during compilation or at run time? I see gfortran has -Waliasing, but that only detects the most egregious case (e.g. call whatever(x,x), but not call whatever(x(1),x(1))). Intel's ifort has -fno-alias, but apparently that just means the compiled code may give different results. Consider a code like this:

program main
implicit none
real :: x(100)
integer :: i

do i=1,size(x)
  x(i) = i
end do

call sub(100,x(1:100),x(1:100))

contains

subroutine sub(n,a,b)
implicit none
integer, intent(in) :: n
real, intent(in) :: a(n)
real, intent(out) :: b(n)

b(:) = a(:)

end subroutine sub

end program main

I don't get any kind of warning (compiling or running), due to using the same memory addresses (x(1:100)) for both dummy arguments (a and b), where one of them is modified, which as far as I understand is forbidden by the standard.

0 Answers
Related