The following MCVE compiles and works just fine for me on Linux with all the versions of GCC I tried.
program temp
implicit none
print *, hello_message()
contains
function hello_message() result(res)
character(len=80) :: res
! Comment the string below, and everything works fine.
print *, "Debug..."
res = "Hello!"
end function hello_message
end program temp
But on OS X and Windows the exact same program just stalls. I've tried different versions of gfortran from Homebrew, GCC Wiki, HPC OS X on OS X as well as few versions from MinGW-w64 project on Windows, but no luck. The code appears pretty fine for me, so what's wrong?