CP2K is currently miscompiled by gcc trunk. The last know good version is rev. 149159 first bad version is 149201. I've been able to narrow the problem down to a miscompilation of 1 file, works fine at -O0, but goes wrong at -O1. I don't have a runtime testcase (except running cp2k.sopt on cp2k/tests/QS/H2O.inp), but the file to be attached (derived from cp_linked_list_val.F) is maybe small & clear enough. I can also easily test a number of compile time options.
Created attachment 18180 [details] testcase correct results with gfortran -c -O0 PR40726.f90 wrong code with gfortran -c -O1 PR40726.f90
Do you by chance return pointers in any function? In which case you should try removing DECL_IS_MALLOC (fndecl) = 1 in trans-decl.c. I pointed this out to Paul already, but appearantly it is still stuck in his whole-file patch queue.
(In reply to comment #2) > Do you by chance return pointers in any function? In which case you should > try removing DECL_IS_MALLOC (fndecl) = 1 in trans-decl.c. I pointed this out > to Paul already, but appearantly it is still stuck in his whole-file > patch queue. > yes, this happens here: FUNCTION cp_sll_val_get_first_el(sll,error) RESULT(res) TYPE(cp_sll_val_type), POINTER :: sll TYPE(cp_error_type), INTENT(inout) :: error TYPE(val_type), POINTER :: res and in several other places, I'll see if I can remove the statement you mention.
Instead, if the Fortran return type does not have POINTER, TARGET or ALLOCATABLE attributes the middle-end type for the result-decl should have TYPE_RESTRICT set if it is a pointer.
> In which case you should > > try removing DECL_IS_MALLOC (fndecl) = 1 in trans-decl.c. this matches twice (line 1565 and line 1429). Which one should be removed ?
Both.
(In reply to comment #6) > Both. This seems to fix the issue, indeed.
> I pointed this out to Paul already, but appearantly it is still stuck in his > whole-file patch queue. Last incarnation of that patch (containing this fix) is at: http://gcc.gnu.org/ml/fortran/2009-07/msg00105.html Paul had another version which fixed several issues, but some last-minute regressions were found...
(In reply to comment #8) > > I pointed this out to Paul already, but appearantly it is still stuck in his > > whole-file patch queue. > > Last incarnation of that patch (containing this fix) is at: > http://gcc.gnu.org/ml/fortran/2009-07/msg00105.html > Paul had another version which fixed several issues, but some last-minute > regressions were found... maybe this part of the patch should be submitted separately, since it fixes an issue that is independent of -fwhole-file?
(In reply to comment #9) > (In reply to comment #8) > > > I pointed this out to Paul already, but appearantly it is still stuck in his > > > whole-file patch queue. > > > > Last incarnation of that patch (containing this fix) is at: > > http://gcc.gnu.org/ml/fortran/2009-07/msg00105.html > > Paul had another version which fixed several issues, but some last-minute > > regressions were found... > I will apply this fix tonight - it is he first opportunity that I have had for a week. Cheers Paul > maybe this part of the patch should be submitted separately, since it fixes an > issue that is independent of -fwhole-file? >
Subject: Bug 40726 Author: pault Date: Tue Jul 21 04:51:30 2009 New Revision: 149846 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149846 Log: 2009-07-21 Paul Thomas <pault@gcc.gnu.org> PR fortran/40726 * trans-decl.c (gfc_get_extern_function_decl): Do not set DECL_IS_MALLOC for pointer valued functions. (build_function_decl): The same. Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/trans-decl.c
I verified that this issue is now fixed on trunk.
Subject: Bug 40726 Author: pault Date: Wed Jul 22 18:12:35 2009 New Revision: 149952 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149952 Log: 2009-07-22 Paul Thomas <pault@gcc.gnu.org> PR fortran/40796 * trans-decl.c (generate_local_decl): Unreferenced result variables with allocatable components should be treated like INTENT_OUT dummy variables. 2009-07-21 Richard Guenther <rguenther@suse.de> PR fortran/40726 Change attribution to Richi. Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/trans-decl.c