Constant and pass-by-reference

Hafiz Abid Qadeer abid_qadeer@mentor.com
Tue Jun 18 13:13:00 GMT 2019


Hi,
I am a Fortran newbie. I was investigating a crash in an openacc
benchmark. But digging a bit deeper, it looks that problem has nothing
to do with openacc but a general issue with a 'parameter' being passed
by reference. The following program demonstrate the problem. The example
looks contrived but actual code used the "var" in an openacc kernel and
it gets written due to an implicit copy clause. I am using an explicit
write (var = 4) here instead.

module test1
      contains
      subroutine  crash(var)
        implicit none
        integer var
        var = 4
      end subroutine
end module test1


program main
  use test1
  implicit none
  integer           g_var
  parameter         (g_var = 5)
  call crash(g_var)
end program main


As I understand it, a constant value is passed to a subroutine which
tries to modify it. As value was passed by reference, the callee tries
to write to read-only memory and segfaults.

Can you kindly confirm if this is the correct understanding of the
semantics of the Fortran. Also I am wondering should compiler issue a
warning in such cases as I did not see a warning even with -Wall.

Thanks,
-- 
Hafiz Abid Qadeer
Mentor Embedded/CodeSourcery



More information about the Fortran mailing list