This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[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: "pat >> gcc-patches" <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 25 Nov 2007 13:55:46 -0800
- Subject: [patch,fortran] PR32928 DATA statement with array element as initializer is rejected
: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.
Index: decl.c
===================================================================
--- decl.c (revision 130392)
+++ decl.c (working copy)
@@ -370,6 +370,20 @@ 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;
+ return m;
+ }
+
*result = gfc_copy_expr (sym->value);
return MATCH_YES;
}
! { dg-do run }
! PR32928 DATA statement with array element as initializer is rejected
! Test case by Jerry DeLisle <jvdelisle @gcc.gnu.org>
program chkdata
integer, parameter,dimension(4) :: myint = [ 4,3,2,1 ]
character(3), parameter, dimension(3) :: mychar = [ "abc", "def", "ghi" ]
character(50) :: buffer
integer :: a(5)
character(5) :: c(5)
data a(1:2) / myint(4), myint(2) /
data a(3:5) / myint(1), myint(3), myint(1) /
data c / mychar(1), mychar(2), mychar(3), mychar(1), mychar(2) /
buffer = ""
if (any(a.ne.[1,3,4,2,4])) call abort
write(buffer,'(5(a))')c
if (buffer.ne."abc def ghi abc def ") call abort
end program chkdata