Reported by Charlie Sharpsteen at http://gcc.gnu.org/ml/fortran/2009-07/msg00010.html The program runs with NAG f95 5.1 and prints twice: 1.0000000000000000 1.0000000000000000 1.0000000000000000 1.0000000000000000 With gfortran: aaa.f90: In function 'bugtest': aaa.f90:30:0: internal compiler error: Segmentation fault valgrind shows: ==17749== Invalid read of size 1 ==17749== at 0x56D412: gfc_return_by_reference (trans-types.c:2089) ==17749== by 0x550D88: gfc_trans_assignment (trans-expr.c:4412) which is: 2087 gfc_return_by_reference (gfc_symbol * sym) 2088 { 2089 if (!sym->attr.function) 2090 return 0; ! Testcase by Charlie Sharpsteen module bugTestMod implicit none type:: boundTest contains procedure, nopass:: test => returnMat end type boundTest contains function returnMat( a, b ) result( mat ) integer:: a, b double precision, dimension(a,b):: mat mat = 1d0 end function returnMat end module bugTestMod program bugTest use bugTestMod implicit none double precision, dimension(2,2):: testCatch type( boundTest ):: testObj write(*,*)testObj%test(2,2) ! <<<< OK (at run time) testCatch = testObj%test(2,2)! <<<< ICE write(*,*)testCatch end program bugTest
I have just posted a fix on the list, so I might as well take the bug. Paul
The same program with procedure pointer components instead of type-bound procedures gives a different ICE: module bugTestMod implicit none type:: boundTest procedure(returnMat), pointer, nopass:: test end type boundTest contains function returnMat( a, b ) result( mat ) integer:: a, b double precision, dimension(a,b):: mat mat = 1d0 end function returnMat end module bugTestMod program bugTest use bugTestMod implicit none !double precision, dimension(2,2):: testCatch type( boundTest ):: testObj testObj%test => returnMat ! ICE in gfc_trans_pointer_assignment, at fortran/trans-expr.c:4108 !write(*,*)testObj%test(2,2) !testCatch = testObj%test(2,2) !write(*,*)testCatch end program bugTest
The problem is: gcc_assert (expr2->value.function.isym || (!comp && gfc_return_by_reference (expr2->value.function.esym) which assumes that "esym" is set. However, looking at resolve.c's resolve_compcall: e->value.function.esym = NULL; Daniel: Is there a special reason to set "esym" as NULL rather than using e->value.function.esym = e->value.compcall.tbp->u.specific->n.sym; One could also change the gcc_assert, however, I fear that the program assumes at several places that either isym or esym is set - even if it does not crash, it might cause problems if it is not available.
The same ICE as in comment #2 already appears using ordinary procedure pointers: module bugTestMod implicit none contains function returnMat( a, b ) result( mat ) integer:: a, b double precision, dimension(a,b):: mat mat = 1d0 end function returnMat end module bugTestMod program bugTest use bugTestMod implicit none procedure(returnMat), pointer :: pp pp => returnMat end program bugTest
Subject: Bug 40646 Author: pault Date: Sun Jul 5 19:13:59 2009 New Revision: 149262 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149262 Log: 2009-07-05 Paul Thomas <pault@gcc.gnu.org> and Tobias Burnus <burnus@gcc.gnu.org> PR fortran/40646 * gfortran.h : Change the compcall member of the 'value' union in the gfc_expr structure so that its fields overlap with the 'function' member. * resolve.c (resolve_compcall): Set the function.esym. * trans-expr.c (gfc_trans_arrayfunc_assign): Use is_proc_ptr_comp in the condition. * dependency.c (gfc_full_array_ref_p): Ensure that 'contiguous' retunrs a value if non-NULL. 2009-07-05 Paul Thomas <pault@gcc.gnu.org> and Tobias Burnus <burnus@gcc.gnu.org> PR fortran/40646 * gfortran.dg/func_assign_3.f90 : New test. Added: trunk/gcc/testsuite/gfortran.dg/func_assign_3.f90 Modified: trunk/gcc/fortran/dependency.c trunk/gcc/fortran/gfortran.h trunk/gcc/fortran/resolve.c trunk/gcc/fortran/trans-expr.c
The TBP problem is fixed by r149262 (thanks, Paul) and only PPC-related issues are left (cf. comment #2 and #4). I'll take over.
Subject: Bug 40646 Author: janus Date: Thu Jul 9 14:07:03 2009 New Revision: 149419 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149419 Log: 2009-07-09 Janus Weil <janus@gcc.gnu.org> PR fortran/40646 * dump-parse-tree.c (show_expr): Renamed 'is_proc_ptr_comp'. * expr.c (is_proc_ptr_comp): Renamed to 'gfc_is_proc_ptr_comp'. (gfc_check_pointer_assign): Renamed 'is_proc_ptr_comp'. (replace_comp,gfc_expr_replace_comp): New functions, analogous to 'replace_symbol' and 'gfc_expr_replace_symbol', just with components instead of symbols. * gfortran.h (gfc_expr_replace_comp): New prototype. (is_proc_ptr_comp): Renamed to 'gfc_is_proc_ptr_comp'. * interface.c (compare_actual_formal): Renamed 'is_proc_ptr_comp'. * match.c (gfc_match_pointer_assignment): Ditto. * primary.c (gfc_match_varspec): Handle array-valued procedure pointers and procedure pointer components. Renamed 'is_proc_ptr_comp'. * resolve.c (resolve_fl_derived): Correctly handle interfaces with RESULT statement, and handle array-valued procedure pointer components. (resolve_actual_arglist,resolve_ppc_call,resolve_expr_ppc): Renamed 'is_proc_ptr_comp'. * trans-array.c (gfc_walk_function_expr): Ditto. * trans-decl.c (gfc_get_symbol_decl): Security check for presence of ns->proc_name. * trans-expr.c (gfc_conv_procedure_call): Handle array-valued procedure pointer components. Renamed 'is_proc_ptr_comp'. (conv_function_val,gfc_trans_arrayfunc_assign): Renamed 'is_proc_ptr_comp'. (gfc_get_proc_ptr_comp): Do not modify the argument 'e', but instead make a copy of it. * trans-io.c (gfc_trans_transfer): Handle array-valued procedure pointer components. 2009-07-09 Janus Weil <janus@gcc.gnu.org> PR fortran/40646 * gfortran.dg/proc_ptr_22.f90: New. * gfortran.dg/proc_ptr_comp_12.f90: New. Added: trunk/gcc/testsuite/gfortran.dg/proc_ptr_22.f90 trunk/gcc/testsuite/gfortran.dg/proc_ptr_comp_12.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/dump-parse-tree.c trunk/gcc/fortran/expr.c trunk/gcc/fortran/gfortran.h trunk/gcc/fortran/interface.c trunk/gcc/fortran/match.c trunk/gcc/fortran/primary.c trunk/gcc/fortran/resolve.c trunk/gcc/fortran/trans-array.c trunk/gcc/fortran/trans-decl.c trunk/gcc/fortran/trans-expr.c trunk/gcc/fortran/trans-io.c trunk/gcc/testsuite/ChangeLog
After most of the PPC issues have been fixed by r149419, some leftover trouble: The following two variants of comment #2 and comment #4 both fail with internal compiler error: in gfc_get_symbol_decl, at fortran/trans-decl.c:1042 ******************************** module bugTestMod implicit none type:: boundTest procedure(returnMat), pointer, nopass:: test end type boundTest contains function returnMat( a, b ) result( mat ) integer:: a, b double precision, dimension(a,b):: mat mat = 1d0 end function returnMat end module bugTestMod program bugTest use bugTestMod implicit none type( boundTest ):: testObj testObj%test => returnMat print *,testObj%test(2,2) end program bugTest ******************************** module bugTestMod implicit none procedure(returnMat), pointer :: pp contains function returnMat( a, b ) result( mat ) integer:: a, b double precision, dimension(a,b):: mat mat = 1d0 end function returnMat end module bugTestMod program bugTest use bugTestMod implicit none pp => returnMat print *,pp(2,2) end program bugTest
Subject: Bug 40646 Author: janus Date: Mon Jul 13 13:41:37 2009 New Revision: 149586 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149586 Log: 2009-07-13 Janus Weil <janus@gcc.gnu.org> PR fortran/40646 * module.c (mio_symbol): If the symbol has formal arguments, the formal namespace will be present. * resolve.c (resolve_actual_arglist): Correctly handle 'called' procedure pointer components as actual arguments. (resolve_fl_derived,resolve_symbol): Make sure the formal namespace is present. * trans-expr.c (gfc_conv_procedure_call): Correctly handle the formal arguments of procedure pointer components. 2009-07-13 Janus Weil <janus@gcc.gnu.org> PR fortran/40646 * gfortran.dg/proc_ptr_22.f90: Extended. * gfortran.dg/proc_ptr_comp_12.f90: Extended. Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/module.c trunk/gcc/fortran/resolve.c trunk/gcc/fortran/trans-expr.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/proc_ptr_22.f90 trunk/gcc/testsuite/gfortran.dg/proc_ptr_comp_12.f90
Comment #8 is fixed by r149586. After three patches, I think we can finally close this PR.
At revision 149589, bootstrap fails on i686-apple-darwin9 with: ... /opt/gcc/i686-darwin/./prev-gcc/xgcc -B/opt/gcc/i686-darwin/./prev-gcc/ -B/opt/gcc/gcc4.5w/i686-apple-darwin9/bin/ -B/opt/gcc/gcc4.5w/i686-apple-darwin9/bin/ -B/opt/gcc/gcc4.5w/i686-apple-darwin9/lib/ -isystem /opt/gcc/gcc4.5w/i686-apple-darwin9/include -isystem /opt/gcc/gcc4.5w/i686-apple-darwin9/sys-include -c -g -O2 -fomit-frame-pointer -DIN_GCC -W -Wall -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -Werror -Wold-style-definition -Wc++-compat -fno-common -DHAVE_CONFIG_H -I. -Ifortran -I../../gcc-4.5-work/gcc -I../../gcc-4.5-work/gcc/fortran -I../../gcc-4.5-work/gcc/../include -I./../intl -I../../gcc-4.5-work/gcc/../libcpp/include -I/opt/mpc/build/include -I/sw/include -I../../gcc-4.5-work/gcc/../libdecnumber -I../../gcc-4.5-work/gcc/../libdecnumber/dpd -I../libdecnumber -I/sw/include -I/sw/include -DCLOOG_PPL_BACKEND ../../gcc-4.5-work/gcc/fortran/openmp.c -o fortran/openmp.o cc1: warnings being treated as errors ../../gcc-4.5-work/gcc/fortran/module.c: In function 'mio_symbol': ../../gcc-4.5-work/gcc/fortran/module.c:3435:23: error: unused variable 'formal' make[3]: *** [fortran/module.o] Error 1 make[3]: *** Waiting for unfinished jobs.... rm gcj-dbtool.pod fsf-funding.pod jcf-dump.pod jv-convert.pod gcov.pod gcj.pod gc-analyze.pod gfdl.pod cpp.pod gij.pod grmic.pod gcc.pod gfortran.pod make[2]: *** [all-stage2-gcc] Error 2 make[1]: *** [stage2-bubble] Error 2 make: *** [all] Error 2