Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
587 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...