Patch to gfortran 15393/15370

Victor Leikehman LEI@il.ibm.com
Wed May 12 15:31:00 GMT 2004


(Apparently my original posting did not make it through.
 My apologies if you get this twice).

In fortran, initialization of automatic arrays is not permitted
and should be rejected by front end (currently triggers ICE).

      Victor
===================================================================
!Testcase from 15370:
module crash
  implicit none
  integer :: N
contains

  subroutine crasher()
    implicit none
    real :: threshold(N,N) = 1.0 ! This causes an ICE
    threshold = 1.0
  end subroutine crasher

end module crash
===================================================================
!Testcase from 15393
subroutine foo(n)
  integer :: n
  integer, dimension(n) :: t = 123  !!! this is illegal !!!
  print*, t
end subroutine foo
===================================================================
RCS file: /home/lei/cvsroot/fortran/decl.c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 decl.c
--- decl.c  4 Feb 2004 11:42:50 -0000     1.1.1.1
+++ decl.c  12 May 2004 13:46:07 -0000
@@ -254,6 +254,7 @@ static try
 add_init_expr_to_sym (const char *name, gfc_expr ** initp,
                  locus * var_locus)
 {
+  int i;
   symbol_attribute attr;
   gfc_symbol *sym;
   gfc_expr *init;
@@ -301,6 +310,17 @@ add_init_expr_to_sym (const char *name,
        && gfc_check_assign_symbol (sym, init) == FAILURE)
      return FAILURE;

+      for (i = 0; i < sym->attr.dimension; i++)
+        {
+          if (sym->as->lower[i]->expr_type != EXPR_CONSTANT ||
+              sym->as->upper[i]->expr_type != EXPR_CONSTANT)
+            {
+              gfc_error ("Automatic array '%s' at %C cannot have
initializer",
+                         sym->name);
+              return FAILURE;
+            }
+        }
+
       /* Add initializer.  Make sure we keep the ranks sane.  */
       if (sym->attr.dimension && init->rank == 0)
      init->rank = sym->as->rank;


--
  Victor Leikehman
  IBM Research Labs in Haifa, Israel




More information about the Gcc-patches mailing list