This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[patch, fortran] Don't apply SAVE attribute to function results
- From: Daniel Franke <franke dot daniel at gmail dot com>
- To: "fortran at gcc dot gnu dot org" <fortran at gcc dot gnu dot org>, gcc-patches at gcc dot gnu dot org
- Date: Sat, 3 Jan 2009 18:54:32 +0100
- Subject: [patch, fortran] Don't apply SAVE attribute to function results
Hi all.
The SAVE attribute shouldn't be applied to function results (posted on c.l.f
by James Van Buskirk):
$> cat save-result.f90
FUNCTION f() RESULT (g)
INTEGER :: g
SAVE
g = 42
END FUNCTION
$> gfortran-svn -c save-result.f90
save-result.f90:1.25:
function f(x) result (g)
1
Error: RESULT attribute conflicts with SAVE attribute in 'g' at (1)
Regression tested on i686-pc-linux-gnu. The patch should qualify as obvious.
I'll commit within 48h if no one objects.
Regards
Daniel
gcc/fortran:
2009-01-03 Daniel Franke <franke.daniel@gmail.com>
* symbol.c (save_symbol): Don't SAVE function results.
gcc/testsuite:
2009-01-03 Daniel Franke <franke.daniel@gmail.com>
* gfortran.dg/func_result_4.f90: New.
Index: fortran/symbol.c
===================================================================
--- fortran/symbol.c (revision 143030)
+++ fortran/symbol.c (working copy)
@@ -3197,6 +3197,7 @@ save_symbol (gfc_symbol *sym)
if (sym->attr.in_common
|| sym->attr.dummy
+ || sym->attr.result
|| sym->attr.flavor != FL_VARIABLE)
return;
/* Automatic objects are not saved. */
Index: testsuite/gfortran.dg/func_result_4.f90
===================================================================
--- testsuite/gfortran.dg/func_result_4.f90 (revision 0)
+++ testsuite/gfortran.dg/func_result_4.f90 (revision 0)
@@ -0,0 +1,10 @@
+! { dg-do "compile" }
+! { dg-options "-c" }
+!
+! Do not apply the SAVE attribute to function results.
+!
+FUNCTION f() RESULT (g)
+ INTEGER :: g
+ SAVE
+ g = 42
+END FUNCTION