From 8dc998fb42ad043e3a0bfc8f36af07613121b3d4 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Sun, 20 Nov 2016 18:43:16 +0000 Subject: [PATCH] re PR fortran/69741 (Bad error in forall with array loop counters) 2016-11-20 Harald Anlauf PR fortran/69741 * resolve.c (gfc_resolve_forall): Check for nonscalar index variables. 2016-11-20 Harald Anlauf PR fortran/69741 * gfortran.dg/forall_18.f90: New testcase. From-SVN: r242641 --- gcc/fortran/ChangeLog | 5 +++++ gcc/fortran/resolve.c | 23 ++++++++++++++--------- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/forall_18.f90 | 16 ++++++++++++++++ 4 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/forall_18.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index c06bb162c07..109aca33261 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2016-11-20 Harald Anlauf + + PR fortran/69741 + * resolve.c (gfc_resolve_forall): Check for nonscalar index variables. + 2016-11-20 Andre Vehreschild PR fortran/78395 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 589a673e52e..9e628f18a11 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -9647,16 +9647,15 @@ gfc_resolve_forall (gfc_code *code, gfc_namespace *ns, int forall_save) static gfc_expr **var_expr; static int total_var = 0; static int nvar = 0; - int old_nvar, tmp; + int i, old_nvar, tmp; gfc_forall_iterator *fa; - int i; old_nvar = nvar; /* Start to resolve a FORALL construct */ if (forall_save == 0) { - /* Count the total number of FORALL index in the nested FORALL + /* Count the total number of FORALL indices in the nested FORALL construct in order to allocate the VAR_EXPR with proper size. */ total_var = gfc_count_forall_iterators (code); @@ -9664,19 +9663,25 @@ gfc_resolve_forall (gfc_code *code, gfc_namespace *ns, int forall_save) var_expr = XCNEWVEC (gfc_expr *, total_var); } - /* The information about FORALL iterator, including FORALL index start, end - and stride. The FORALL index can not appear in start, end or stride. */ + /* The information about FORALL iterator, including FORALL indices start, end + and stride. An outer FORALL indice cannot appear in start, end or stride. */ for (fa = code->ext.forall_iterator; fa; fa = fa->next) { + /* Fortran 20008: C738 (R753). */ + if (fa->var->ref && fa->var->ref->type == REF_ARRAY) + { + gfc_error ("FORALL index-name at %L must be a scalar variable " + "of type integer", &fa->var->where); + continue; + } + /* Check if any outer FORALL index name is the same as the current one. */ for (i = 0; i < nvar; i++) { if (fa->var->symtree->n.sym == var_expr[i]->symtree->n.sym) - { - gfc_error ("An outer FORALL construct already has an index " - "with this name %L", &fa->var->where); - } + gfc_error ("An outer FORALL construct already has an index " + "with this name %L", &fa->var->where); } /* Record the current FORALL index. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2c81bf439ad..6a23d906919 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-11-20 Harald Anlauf + + PR fortran/69741 + * gfortran.dg/forall_18.f90: New testcase. + 2016-11-20 Marc Glisse * gcc.dg/tree-ssa/cmpexactdiv.c: New file. diff --git a/gcc/testsuite/gfortran.dg/forall_18.f90 b/gcc/testsuite/gfortran.dg/forall_18.f90 new file mode 100644 index 00000000000..3cfe54763bc --- /dev/null +++ b/gcc/testsuite/gfortran.dg/forall_18.f90 @@ -0,0 +1,16 @@ +! { dg-do compile } +! PR fortran/69741 - improve error message for nonscalar FORALL index variables +! +subroutine check + integer :: ii(2), i + real :: a(3,2) + + forall (ii(1)=1:3, i=1:2) ! { dg-error "scalar variable of type integer" } + a(ii(1),i) = ii(1) * i + end forall + + forall (j=1:3, ii(2)=1:2) ! { dg-error "scalar variable of type integer" } + a(j,ii(2)) = j * ii(2) + end forall + +end subroutine check -- 2.30.2