[Bug fortran/85537] [7/8/9 Regression] Invalid memory reference at runtime when calling subroutine through procedure pointer
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85537 Thomas Koenig changed: What|Removed |Added CC||tkoenig at gcc dot gnu.org --- Comment #7 from Thomas Koenig --- Created attachment 46016 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46016=edit Assembly for test case Looking at the assembly of the test case in comment #6 (with -g -fverbose-asm only): .LBE2: # a.f90:29: a = a + 1 .loc 1 29 0 movl(%rbx), %eax# CHAIN.4_10(D)->a, _11 addl$1, %eax#, _12 movl%eax, (%rbx)# _12, CHAIN.4_10(D)->a When called through a procedure pointer, rbx no longer contains the address of a. Looking further up, we have movq%r10, %rbx # CHAIN.4, CHAIN.4 movq%r10, -552(%rbp)# CHAIN.4, .LBB2: so %r10 is clobbered. This happens in the call of _gfortran_st_write. Looking at the ABI, %r10 is not supposed to be preserved. Data point: This works on POWER9. This looks like a target bug to me.
[Bug fortran/85537] [7/8/9 Regression] Invalid memory reference at runtime when calling subroutine through procedure pointer
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85537 Richard Biener changed: What|Removed |Added Target Milestone|7.4 |7.5
[Bug fortran/85537] [7/8/9 Regression] Invalid memory reference at runtime when calling subroutine through procedure pointer
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85537 --- Comment #6 from janus at gcc dot gnu.org --- (In reply to janus from comment #5) > However I don't see any failures with this variant: Sorry, I was a bit too quick in submitting this. It's really not a good example, since it's missing an "implicit none", so "bar_impl" supposedly gets its own private version of "a". The following variant fails again in the same way as the original test case: program main implicit none integer :: a call foo() contains subroutine foo() abstract interface subroutine ibar() end subroutine end interface procedure(ibar), pointer :: bar_ptr => bar_impl a = 0 call bar_impl() call bar_ptr() end subroutine subroutine bar_impl() write (*,*) "foo" a = a + 1 end subroutine end program I don't quite understand what's going on. Apparently the reference to the variable 'a' somehow goes wrong. But I don't see how the procedure pointer makes a difference here.
[Bug fortran/85537] [7/8/9 Regression] Invalid memory reference at runtime when calling subroutine through procedure pointer
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85537 --- Comment #5 from janus at gcc dot gnu.org --- However I don't see any failures with this variant: program main call foo() contains subroutine foo() integer :: a abstract interface subroutine ibar() end subroutine end interface procedure(ibar), pointer :: bar_ptr => bar_impl a = 0 call bar_impl() call bar_ptr() end subroutine subroutine bar_impl() write (*,*) "foo" a = a + 1 end subroutine end program
[Bug fortran/85537] [7/8/9 Regression] Invalid memory reference at runtime when calling subroutine through procedure pointer
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85537 janus at gcc dot gnu.org changed: What|Removed |Added CC||janus at gcc dot gnu.org --- Comment #4 from janus at gcc dot gnu.org --- (In reply to Dominique d'Humieres from comment #2) > The test works for me with 4.8.5. The change occurred between revisions > r2370089 (2016-06-04, OK) and r237310 + one patch (2016-06-10, wrong code). I see runtime segfaults with every gfortran version that I tried, starting from 4.6. 4.4 does not compile the example due to the proc-ptr init.
[Bug fortran/85537] [7/8/9 Regression] Invalid memory reference at runtime when calling subroutine through procedure pointer
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85537 --- Comment #3 from Tiziano Müller --- (In reply to Dominique d'Humieres from comment #2) > The test works for me with 4.8.5. The change occurred between revisions > r2370089 (2016-06-04, OK) and r237310 + one patch (2016-06-10, wrong code). Ok, then openSuSE must have some patches on their 4.8.5 which introduce the bug, since I get: tiziano@tcpc18 ~/tmp $ gfortran --version GNU Fortran (SUSE Linux) 4.8.5 Copyright (C) 2015 Free Software Foundation, Inc. GNU Fortran comes with NO WARRANTY, to the extent permitted by law. You may redistribute copies of GNU Fortran under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING tiziano@tcpc18 ~/tmp $ gfortran -o segfault_minimal_rep segfault_minimal_rep.f90 -ggdb tiziano@tcpc18 ~/tmp $ ./segfault_minimal_rep foo foo Program received signal SIGSEGV: Segmentation fault - invalid memory reference. Backtrace for this error: #0 0x7f9bb46c7607 in ??? #1 0x7f9bb46c686d in ??? #2 0x7f9bb3be3fdf in ??? #3 0x4007bc in bar_impl at /users/tiziano/tmp/segfault_minimal_rep.f90:21 #4 0x4007f1 in __m_MOD_foo at /users/tiziano/tmp/segfault_minimal_rep.f90:16 #5 0x4007fc in MAIN__ at /users/tiziano/tmp/segfault_minimal_rep.f90:30 #6 0x400832 in main at /users/tiziano/tmp/segfault_minimal_rep.f90:28 Segmentation fault (core dumped)
[Bug fortran/85537] [7/8/9 Regression] Invalid memory reference at runtime when calling subroutine through procedure pointer
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85537 Dominique d'Humieres changed: What|Removed |Added Keywords||wrong-code Priority|P3 |P4 Known to work||6.4.0 Target Milestone|--- |7.4 Summary|Invalid memory reference at |[7/8/9 Regression] Invalid |runtime when calling|memory reference at runtime |subroutine through |when calling subroutine |procedure pointer |through procedure pointer --- Comment #2 from Dominique d'Humieres --- The test works for me with 4.8.5. The change occurred between revisions r2370089 (2016-06-04, OK) and r237310 + one patch (2016-06-10, wrong code).