PR fortran/30792 -- Substring data-implied-do is invalid

Message ID 20180224012502.GA4196@troutmask.apl.washington.edu
State New
Headers show
Series
  • PR fortran/30792 -- Substring data-implied-do is invalid
Related show

Commit Message

Steve Kargl Feb. 24, 2018, 1:25 a.m.
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 <kargl@gcc.gnu.org>

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

2018-02-23  Steven G. Kargl <kargl@gcc.gnu.org>

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

-- 
Steve

Comments

Thomas Koenig Feb. 24, 2018, 12:32 p.m. | #1
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

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