Re: [PATCH] PR fortran/30792 -- Substring data-implied-do is invalid

2018-02-24 Thread Thomas Koenig

Hi Steve,


The attached patch fixes PR fortran/30792.  A substring
reference is invalid for a data-implied-do.  Regression
tested on x86_64-*-freebsd.  OK to commit.


This should be safe enough, OK for trunk.

Thanks for the patch!

Regards

Thomas


[PATCH] PR fortran/30792 -- Substring data-implied-do is invalid

2018-02-23 Thread Steve Kargl
The attached patch fixes PR fortran/30792.  A substring
reference is invalid for a data-implied-do.  Regression
tested on x86_64-*-freebsd.  OK to commit.

2018-02-23  Steven G. Kargl 

PR fortran/30792
* decl.c (gfc_match_data): Check for invalid substring in
data-implied-do

2018-02-23  Steven G. Kargl 

PR fortran/30792
* gfortran.dg/data_substring.f90: New test.

-- 
Steve
Index: gcc/fortran/decl.c
===
--- gcc/fortran/decl.c	(revision 257951)
+++ gcc/fortran/decl.c	(working copy)
@@ -585,6 +585,20 @@ gfc_match_data (void)
   if (m != MATCH_YES)
 	goto cleanup;
 
+  if (new_data->var->iter.var
+	  && new_data->var->iter.var->ts.type == BT_INTEGER
+	  && new_data->var->iter.var->symtree->n.sym->attr.implied_index == 1
+	  && new_data->var->list
+	  && new_data->var->list->expr
+	  && new_data->var->list->expr->ts.type == BT_CHARACTER
+	  && new_data->var->list->expr->ref
+	  && new_data->var->list->expr->ref->type == REF_SUBSTRING)
+	{
+	  gfc_error ("Invalid substring in data-implied-do at %L in DATA "
+		 "statement", &new_data->var->list->expr->where);
+	  goto cleanup;
+	}
+
   m = top_val_list (new_data);
   if (m != MATCH_YES)
 	goto cleanup; 
Index: gcc/testsuite/gfortran.dg/data_substring.f90
===
--- gcc/testsuite/gfortran.dg/data_substring.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/data_substring.f90	(working copy)
@@ -0,0 +1,6 @@
+! { dg-do compile }
+! PR fortran/30792
+character string*1025
+integer i
+data (string(i:i),i=1,1025)/1025*'?'/  ! { dg-error "Invalid substring" }
+end