This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix PR21034


The attached patch implements PR21034.

A "save" statement should not give the save attribute to automatic objects 
(Section 5.2.4).

Tested on i686-linux.
Applied to mainline.

Paul

2005-06-22 Paul Brook  <paul@codesourcery.com>

	PR fortran/21034
	* symbol.c (gfc_is_var_automatic): New function.
	(save_symbol): Use it.
testsuite/
	* gfortran.dg/auto_save_1.f90: New test.

Index: fortran/symbol.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/fortran/symbol.c,v
retrieving revision 1.29
diff -u -p -r1.29 symbol.c
--- fortran/symbol.c	29 Apr 2005 00:12:59 -0000	1.29
+++ fortran/symbol.c	22 Jun 2005 14:49:40 -0000
@@ -2331,6 +2331,25 @@ gfc_traverse_ns (gfc_namespace * ns, voi
 }
 
 
+/* Return TRUE if the symbol is an automatic variable.  */
+static bool
+gfc_is_var_automatic (gfc_symbol * sym)
+{
+  /* Pointer and allocatable variables are never automatic.  */
+  if (sym->attr.pointer || sym->attr.allocatable)
+    return false;
+  /* Check for arrays with non-constant size.  */
+  if (sym->attr.dimension && sym->as
+      && !gfc_is_compile_time_shape (sym->as))
+    return true;
+  /* Check for non-constant length character vairables.  */
+  if (sym->ts.type == BT_CHARACTER
+      && sym->ts.cl
+      && gfc_is_constant_expr (sym->ts.cl->length))
+    return true;
+  return false;
+}
+
 /* Given a symbol, mark it as SAVEd if it is allowed.  */
 
 static void
@@ -2344,7 +2363,9 @@ save_symbol (gfc_symbol * sym)
       || sym->attr.dummy
       || sym->attr.flavor != FL_VARIABLE)
     return;
-
+  /* Automatic objects are not saved.  */
+  if (gfc_is_var_automatic (sym))
+    return;
   gfc_add_save (&sym->attr, sym->name, &sym->declared_at);
 }
 
Index: testsuite/gfortran.dg/auto_save_1.f90
===================================================================
RCS file: testsuite/gfortran.dg/auto_save_1.f90
diff -N testsuite/gfortran.dg/auto_save_1.f90
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gfortran.dg/auto_save_1.f90	22 Jun 2005 14:48:41 -0000
@@ -0,0 +1,18 @@
+! { dg-do run }
+! Check that automatic objects work properly in the presence of a save
+! statement.
+! PR21034
+subroutine test(n)
+  implicit none
+  integer n
+  real dte(n)
+  character(len=n) :: s
+  save
+  dte = 0
+  s = ""
+end
+
+program prog
+  call test(4)
+  call test(10)
+end program

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]