https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65086
Bug ID: 65086 Summary: Segfault: Invalid copy-out of temporary as argument is in read-only memory Product: gcc Version: 5.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: burnus at gcc dot gnu.org >From James Van Buskirk's example in the comp.lang.fortran thread "Is INTENT (IN) ever used to control code generation?" / https://groups.google.com/d/msg/comp.lang.fortran/nzq3Sad_zQE/APiZzlGdNPQJ The following program segfaults at run time, unless INTENT(IN) is specified for sub4. The problem is the copy-out part as the original variable is in read-only memory. "Both gfortran and ifort throw an error at runtime for the above program with the INTENT(IN) statements commented out, but ifort runs to completion if either or both of them are in effect whereas gfortran only works if the INTENT(IN) statement in subroutine sub4 is in effect." And: "But as the standard is written it seems the Fortran processor has to do this comparison before it can copy out, which seems absolutely horrible to me, [...]" Bob replies: "Why does it seem horrible? Oracle Solaris Studio Fortran uses this implementation." module mod1 implicit none character(*), parameter :: x = 'This is a constant string.' end module mod1 module mod2 implicit none contains subroutine sub1(x) character(*) x call sub2(x,len(x)) end subroutine sub1 subroutine sub2(x,size) integer size character x(size) call sub3(x) end subroutine sub2 subroutine sub3(x) character x(:) !INTENT(IN) :: x call sub4(x(1::2)) end subroutine sub3 subroutine sub4(x) !INTENT(IN) :: x ! REQUIRED character x(*) end subroutine sub4 end module mod2 program main use mod1 use mod2 implicit none write(*,'(a)') x call sub1(x) write(*,'(a)') x end program main