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]

[patch, fortran] PR33152 Initialization/declaration problems in block data


:ADDPATCH fortran]

The attached patch resolves the issues (several variations) identified in the PR.

The patch removes wrong error messages and adds a new one. Fairly self explanatory.

New test case provided.

Regression tested on x86-64-unknown-linux-gnu.

OK for trunk?

Jerry

2007-11-24 Jerry DeLisle <jvdelisle@gcc.gnu.org>

	PR fortran/33152
	* decl.c (add_init_expr_to_sym): Remove error message.
	* resolve.c (check_data_variable): Add new check for a data variable
	that has an array spec, but no ref and issue an error.
	* match.c (gfc_match_common): Remove error message.



Index: decl.c
===================================================================
--- decl.c	(revision 130392)
+++ decl.c	(working copy)
@@ -1167,15 +1167,6 @@ add_init_expr_to_sym (const char *name, 
       return FAILURE;
     }
 
-  if (attr.in_common
-      && !attr.data
-      && *initp != NULL)
-    {
-      gfc_error ("Initializer not allowed for COMMON variable '%s' at %C",
-		 sym->name);
-      return FAILURE;
-    }
-
   if (init == NULL)
     {
       /* An initializer is required for PARAMETER declarations.  */
Index: resolve.c
===================================================================
--- resolve.c	(revision 130392)
+++ resolve.c	(working copy)
@@ -8010,6 +8010,13 @@ check_data_variable (gfc_data_variable *
 		 e->symtree->n.sym->name, &e->symtree->n.sym->declared_at);
     }
 
+  if (e->ref == NULL && e->symtree->n.sym->as)
+    {
+      gfc_error ("DATA array '%s' at %L must be specified in a previous"
+		 " declaration", e->symtree->n.sym->name, where);
+      return FAILURE;
+    }
+
   if (e->rank == 0)
     {
       mpz_init_set_ui (size, 1);
Index: match.c
===================================================================
--- match.c	(revision 130392)
+++ match.c	(working copy)
@@ -2786,18 +2786,6 @@ gfc_match_common (void)
 	  if (gfc_add_in_common (&sym->attr, sym->name, NULL) == FAILURE) 
 	    goto cleanup;
 
-	  if (sym->value != NULL && sym->value->expr_type != EXPR_NULL
-	      && (name[0] == '\0' || !sym->attr.data))
-	    {
-	      if (name[0] == '\0')
-		gfc_error ("Previously initialized symbol '%s' in "
-			   "blank COMMON block at %C", sym->name);
-	      else
-		gfc_error ("Previously initialized symbol '%s' in "
-			   "COMMON block '%s' at %C", sym->name, name);
-	      goto cleanup;
-	    }
-
 	  if (gfc_add_in_common (&sym->attr, sym->name, NULL) == FAILURE)
 	    goto cleanup;
 
! { dg-do compile }
! PR33152 Initialization/declaration problems in block data
! Test case prepared by Jerry DeLisle  <jvdelisle@gcc.gnu.org>
blockdata bab
 character(len=3) :: myname(2)=(/'bar','baz'/)
 common/nmstr/myname
end blockdata bab

blockdata thdinit 
 implicit none 
 integer, parameter :: nmin=2 
 common/onestr/emname 
 character(len=3) :: emname(nmin) = (/'bar','baz'/) 
end blockdata thdinit

blockdata fooinit 
 implicit none 
 integer, parameter :: nmin=2 
 common/twostr/aname 
 data aname/'bar','baz'/ ! { dg-error "DATA array" }
 character(len=3) :: aname(nmin)
end blockdata fooinit

end

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