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]

Re: [patch,fortran] PR32928 DATA statement with array element as initializer is rejected


Jerry DeLisle wrote:
:ADDPATCH fortran:

The attached patch fixes this by using gfc_match_init_expr in match_data_constant and thereby matching the array specifier given in the test case. This is then simplified and comes out a nice BT_CONSTANT. Magic!

Regression tested on x86-64.

OK for trunk?

Best regards,

Jerry

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

    PR fortran/32928
    * decl.c (match_data_constant): Use gfc_match_init_expr to match the
    array spec and set the initializer expression.

The attached revised patch catches some invalids pointed out by Tobias Burnus on IRC.

OK to commit?

Thanks for reviews,

Jerry


! { dg-do compile }
! PR32928 DATA statement with array element as initializer is rejected
integer, parameter,dimension(4) :: myint = [ 4,3,2,1 ]
integer :: a(5)
data a(1:2) / myint(a(1)), myint(2) / ! { dg-error "Invalid initializer" }
end
! { dg-do compile }
! PR32928 DATA statement with array element as initializer is rejected
integer, parameter,dimension(4) :: myint = [ 4,3,2,1 ]
integer :: a(5),b
data a(1:2) / myint(b), myint(2) / ! { dg-error "Invalid initializer" }
end
Index: decl.c
===================================================================
--- decl.c	(revision 130417)
+++ decl.c	(working copy)
@@ -370,6 +370,27 @@ match_data_constant (gfc_expr **result)
   else if (sym->attr.flavor == FL_DERIVED)
     return gfc_match_structure_constructor (sym, result);
 
+  /* Check to see if the value is an initialization expression.  */
+  gfc_current_locus = old_loc;
+  
+  m = gfc_match_init_expr (result);
+  if (m == MATCH_ERROR)
+    return m;
+
+  if (m == MATCH_YES)
+    {
+      if (gfc_simplify_expr (*result, 0) == FAILURE)
+	m = MATCH_ERROR;
+
+      if ((*result)->expr_type == EXPR_CONSTANT)
+	return m;
+      else
+	{
+	  gfc_error ("Invalid initializer %s in Data statement at %C", name);
+	  return MATCH_ERROR;
+	}
+    }
+
   *result = gfc_copy_expr (sym->value);
   return MATCH_YES;
 }

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