This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch to gfortran 15393/15370
- From: Victor Leikehman <lei at haifasphere dot co dot il>
- To: gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org
- Date: Wed, 12 May 2004 17:21:39 +0300
- Subject: Patch to gfortran 15393/15370
- Organization: IBM Research Lab in Haifa, Israel
- Reply-to: lei at il dot ibm dot com
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