This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch,fortran] PR32928 DATA statement with array element as initializer is rejected
- From: Jerry DeLisle <jvdelisle at verizon dot net>
- To: Fortran List <fortran at gcc dot gnu dot org>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>, Tobias Burnus <burnus at net-b dot de>
- Date: Sun, 25 Nov 2007 15:53:30 -0800
- Subject: Re: [patch,fortran] PR32928 DATA statement with array element as initializer is rejected
- References: <4749EF62.3060109@verizon.net>
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;
}