re PR fortran/21034 ([4.0 only] internal compiler error: in gfc_trans_auto_array_allo...
authorPaul Brook <paul@codesourcery.com>
Wed, 22 Jun 2005 15:34:02 +0000 (15:34 +0000)
committerPaul Brook <pbrook@gcc.gnu.org>
Wed, 22 Jun 2005 15:34:02 +0000 (15:34 +0000)
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.

From-SVN: r101250

gcc/fortran/ChangeLog
gcc/fortran/symbol.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/auto_save_1.f90 [new file with mode: 0644]

index 4ebd01d8e44ede821110620d55aef01cd36c923d..4badf66df53d8840138d9cb750c649ec98a7e175 100644 (file)
@@ -1,3 +1,9 @@
+2005-06-22 Paul Brook  <paul@codesourcery.com>
+
+       PR fortran/21034
+       * symbol.c (gfc_is_var_automatic): New function.
+       (save_symbol): Use it.
+
 2005-06-21  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
            Paul Thomas  <pault@gcc.gnu.org>
 
index 5fb9f53db8781d1d6948ecdd1f6d2a8b9206b052..f91b72de1aaf55ab0159cc2b24f8ca1b89ac4de7 100644 (file)
@@ -2331,6 +2331,25 @@ gfc_traverse_ns (gfc_namespace * ns, void (*func) (gfc_symbol *))
 }
 
 
+/* 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 606d4049d3f382b6c7eaeb4a86720b691a9a49dc..1e0c949acdf3c21bc8b58b2fb292e4172373f978 100644 (file)
@@ -1,3 +1,8 @@
+2005-06-22 Paul Brook  <paul@codesourcery.com>
+
+       PR fortran/21034
+       * gfortran.dg/auto_save_1.f90: New test.
+
 2005-06-22  Michael Matz  <matz@suse.de>
 
        * gcc.target/x86-64/abi: New directory.
diff --git a/gcc/testsuite/gfortran.dg/auto_save_1.f90 b/gcc/testsuite/gfortran.dg/auto_save_1.f90
new file mode 100644 (file)
index 0000000..b4571d2
--- /dev/null
@@ -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