Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
527 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 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.7k users

...