Detecting wrongful aliasing at compile or run time

浪尽此生 提交于 2021-01-28 04:37:42

问题


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.

来源:https://stackoverflow.com/questions/65842064/detecting-wrongful-aliasing-at-compile-or-run-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!