Bug 40726 - [4.5 Regression] miscompilation at -O1
Summary: [4.5 Regression] miscompilation at -O1
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.5.0
Assignee: Not yet assigned to anyone
URL:
Keywords: patch, wrong-code
Depends on:
Blocks:
 
Reported: 2009-07-12 14:18 UTC by Joost VandeVondele
Modified: 2009-07-21 06:49 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.4.1
Known to fail: 4.5.0
Last reconfirmed: 2009-07-20 06:42:19


Attachments
testcase (3.09 KB, text/plain)
2009-07-12 14:20 UTC, Joost VandeVondele
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Joost VandeVondele 2009-07-12 14:18:35 UTC
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.
Comment 1 Joost VandeVondele 2009-07-12 14:20:49 UTC
Created attachment 18180 [details]
testcase

correct results with
gfortran -c -O0 PR40726.f90 
wrong code with
gfortran -c -O1 PR40726.f90
Comment 2 Richard Biener 2009-07-12 14:24:53 UTC
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.
Comment 3 Joost VandeVondele 2009-07-12 14:30:29 UTC
(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.
Comment 4 Richard Biener 2009-07-12 14:30:48 UTC
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.
Comment 5 Joost VandeVondele 2009-07-12 14:35:20 UTC
>  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 ?

Comment 6 Richard Biener 2009-07-12 14:58:55 UTC
Both.
Comment 7 Joost VandeVondele 2009-07-12 15:06:51 UTC
(In reply to comment #6)
> Both.

This seems to fix the issue, indeed.

Comment 8 Tobias Burnus 2009-07-15 07:42:56 UTC
> 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...
Comment 9 Joost VandeVondele 2009-07-15 15:32:44 UTC
(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?

Comment 10 Paul Thomas 2009-07-20 07:28:58 UTC
(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?
> 

Comment 11 Paul Thomas 2009-07-21 04:51:48 UTC
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

Comment 12 Joost VandeVondele 2009-07-21 06:49:44 UTC
I verified that this issue is now fixed on trunk.
Comment 13 Paul Thomas 2009-07-22 18:12:56 UTC
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