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

Categories

0 votes
578 views
in Technique[技术] by (71.8m points)

compilation - Detecting wrongful aliasing at compile or run time

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

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

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...