Created attachment 44938 [details] Output from -save-temps Function pointer to a function contained within the same program gives a segmentation fault. Confirmed in both 7.3.0 and 8.2.0-1 (Ubuntu 18.04 installed from apt). Compiled with gfortran test.f03 and gfortran-8 test.f03. Minimal failing example: program test_func_ptrs implicit none abstract interface subroutine func() end subroutine end interface procedure (func), pointer :: f_ptr => null () f_ptr => f1 call f_ptr() contains subroutine f1() implicit none return end subroutine end program test_func_ptrs
WORKSFORME on x86_64-apple-darwin18.2. I don't get any segmentation fault with the various revisions I have tested (from 5.5 up to trunk).
Thank you Dominique for testing this on a Mac. So perhaps the problem is specific to Linux. Additional information that might help with debugging the segmentation fault: 1) Compiling this code with gfortran -ffree-form -std=f2003 test.f gives the error test.f:12:13: f_ptr => f1 1 Error: Fortran 2008: Internal procedure ‘f1’ is invalid in procedure pointer assignment at (1) (this code is within gcc/fortran/expr.c: if (attr.proc == PROC_INTERNAL && !gfc_notify_std(GFC_STD_F2008, "Internal procedure %qs " "is invalid in procedure pointer assignment " "at %L", rvalue->symtree->name, &rvalue->where)) ) 2) However, gfortran -ffree-form -std=f2008 test.f compiles successfully but gives a segmentation fault. ./a.out Program received signal SIGSEGV: Segmentation fault - invalid memory reference. Backtrace for this error: #0 0x7fe7aae3b31a #1 0x7fe7aae3a503 #2 0x7fe7aaa5ef1f #3 0x7fffed8fe6c0 Segmentation fault (core dumped)
(In reply to menospaamthereaper from comment #2) > Thank you Dominique for testing this on a Mac. So perhaps the problem is > specific to Linux. I just compiled the test case on Ubuntu 18.04 with gfortran versions 5, 6, 7, 8 and trunk. I don't see a segfault with any of these. Also gdb and valgrind don't show any kind of problem. > Additional information that might help with debugging the segmentation fault: > > 1) Compiling this code with > > gfortran -ffree-form -std=f2003 test.f > > gives the error > > test.f:12:13: > > f_ptr => f1 > 1 > Error: Fortran 2008: Internal procedure ‘f1’ is invalid in procedure pointer > assignment at (1) This error is correct. That's just not allowed in Fortran 2003. All fine. > 2) However, > > gfortran -ffree-form -std=f2008 test.f > > compiles successfully but gives a segmentation fault. > > ./a.out > > Program received signal SIGSEGV: Segmentation fault - invalid memory > reference. > > Backtrace for this error: > #0 0x7fe7aae3b31a > #1 0x7fe7aae3a503 > #2 0x7fe7aaa5ef1f > #3 0x7fffed8fe6c0 > Segmentation fault (core dumped) Could you please compile with the -g flag, in order to get a more meaningful backtrace? Alternatively try running the executable via gdb or valgrind for further debugging.
> Could you please compile with the -g flag, in order to get a more meaningful > backtrace? Alternatively try running the executable via gdb or valgrind > for further debugging. Any progress before closing the PR as WORKSFORME?
No feedback from OP. Works for me on FreeBSD. Closing.