public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: PR69741: Bad error in formal with array scalar loop counters
       [not found] ` <20161119011833.GA27406@troutmask.apl.washington.edu>
@ 2016-11-19 14:42   ` Harald Anlauf
  2016-11-19 14:44     ` Harald Anlauf
  0 siblings, 1 reply; 3+ messages in thread
From: Harald Anlauf @ 2016-11-19 14:42 UTC (permalink / raw)
  To: kargl; +Cc: Steve Kargl, fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1962 bytes --]

Hi Steve, all,

On 11/19/16 02:18, Steve Kargl wrote:
> The error message is still not clear.  42 is a scalar integer.  Why
> not use the language in the standard?
> 
> C739 (R753) The index-name shall be a named scalar variable of type integer.

I had adjusted the error message to the same appearing in resolve.c
in another place, but you are absolutely right.  The attached patch
takes this into account.  The testcase is derived from the PR.

>>
>> Whoever wants to take this one.
>>
> 
> Ever thought about getting a commit bit and getting more involved
> in gfortran development?  I know 4 or 5 other gentlemen that would
> welcome you with open arms.
> 

Thanks.

During the stabilization phase of gcc-6 I tried to understand more
of the internals of gfortran.  However, most of the time I just got
lost.  I therefore decided to tackle a few simple things.

I don't have the resources to follow the development continuously,
especially when there are changes to ABI or module format.  So it
makes more sense for me to wait till the dust settles.

I'll try to find some time during the current stage 3 to check
whether there are regressions affecting my codes, but no promises.

Harald


2016-11-19  Harald Anlauf  <anlauf@gmx.de>

	PR fortran/69741
	* resolve.c (gfc_resolve_forall): Check for non-scalar index
	variables.

2016-11-19  Harald Anlauf  <anlauf@gmx.de>

	PR fortran/69741
	* gfortran.dg/forall_18.f90: New testcase.

Index: gfortran.dg/forall_18.f90
===================================================================
--- gfortran.dg/forall_18.f90	(revision 0)
+++ gfortran.dg/forall_18.f90	(revision 0)
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! PR 69741 - improve error message for non-scalar FORALL index variables
+!
+subroutine check
+  integer :: ii(2), i, j
+  real :: a(3,2)
+
+  forall (ii(1)=1:3, ii(2)=1:2) ! { dg-error "scalar variable of type
integer" }
+     a(ii(1),ii(2)) = ii(1) * ii(2)
+  end forall
+
+end subroutine check


[-- Attachment #2: patch-pr69741-resolve.c --]
[-- Type: text/x-csrc, Size: 667 bytes --]

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 242607)
+++ gcc/fortran/resolve.c	(working copy)
@@ -9668,6 +9668,13 @@
      and stride. The FORALL index can not appear in start, end or stride.  */
   for (fa = code->ext.forall_iterator; fa; fa = fa->next)
     {
+      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++)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PR69741: Bad error in formal with array scalar loop counters
  2016-11-19 14:42   ` PR69741: Bad error in formal with array scalar loop counters Harald Anlauf
@ 2016-11-19 14:44     ` Harald Anlauf
  2016-11-20 19:02       ` Steve Kargl
  0 siblings, 1 reply; 3+ messages in thread
From: Harald Anlauf @ 2016-11-19 14:44 UTC (permalink / raw)
  To: kargl; +Cc: Steve Kargl, fortran, gcc-patches

Sorry, forgot to mention: regtested on i686-pc-linux-gnu

Harald

On 11/19/16 15:42, Harald Anlauf wrote:
> Hi Steve, all,
> 
> On 11/19/16 02:18, Steve Kargl wrote:
>> The error message is still not clear.  42 is a scalar integer.  Why
>> not use the language in the standard?
>>
>> C739 (R753) The index-name shall be a named scalar variable of type integer.
> 
> I had adjusted the error message to the same appearing in resolve.c
> in another place, but you are absolutely right.  The attached patch
> takes this into account.  The testcase is derived from the PR.
> 
>>>
>>> Whoever wants to take this one.
>>>
>>
>> Ever thought about getting a commit bit and getting more involved
>> in gfortran development?  I know 4 or 5 other gentlemen that would
>> welcome you with open arms.
>>
> 
> Thanks.
> 
> During the stabilization phase of gcc-6 I tried to understand more
> of the internals of gfortran.  However, most of the time I just got
> lost.  I therefore decided to tackle a few simple things.
> 
> I don't have the resources to follow the development continuously,
> especially when there are changes to ABI or module format.  So it
> makes more sense for me to wait till the dust settles.
> 
> I'll try to find some time during the current stage 3 to check
> whether there are regressions affecting my codes, but no promises.
> 
> Harald
> 
> 
> 2016-11-19  Harald Anlauf  <anlauf@gmx.de>
> 
> 	PR fortran/69741
> 	* resolve.c (gfc_resolve_forall): Check for non-scalar index
> 	variables.
> 
> 2016-11-19  Harald Anlauf  <anlauf@gmx.de>
> 
> 	PR fortran/69741
> 	* gfortran.dg/forall_18.f90: New testcase.
> 
> Index: gfortran.dg/forall_18.f90
> ===================================================================
> --- gfortran.dg/forall_18.f90	(revision 0)
> +++ gfortran.dg/forall_18.f90	(revision 0)
> @@ -0,0 +1,12 @@
> +! { dg-do compile }
> +! PR 69741 - improve error message for non-scalar FORALL index variables
> +!
> +subroutine check
> +  integer :: ii(2), i, j
> +  real :: a(3,2)
> +
> +  forall (ii(1)=1:3, ii(2)=1:2) ! { dg-error "scalar variable of type
> integer" }
> +     a(ii(1),ii(2)) = ii(1) * ii(2)
> +  end forall
> +
> +end subroutine check
> 


-- 
Harald Anlauf
Dieburger Str. 17
60386 Frankfurt
Tel.: (069) 4014 8318

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PR69741: Bad error in formal with array scalar loop counters
  2016-11-19 14:44     ` Harald Anlauf
@ 2016-11-20 19:02       ` Steve Kargl
  0 siblings, 0 replies; 3+ messages in thread
From: Steve Kargl @ 2016-11-20 19:02 UTC (permalink / raw)
  To: Harald Anlauf; +Cc: kargl, fortran, gcc-patches

On Sat, Nov 19, 2016 at 03:44:12PM +0100, Harald Anlauf wrote:
> > 
> > 2016-11-19  Harald Anlauf  <anlauf@gmx.de>
> > 
> > 	PR fortran/69741
> > 	* resolve.c (gfc_resolve_forall): Check for non-scalar index
> > 	variables.
> > 
> > 2016-11-19  Harald Anlauf  <anlauf@gmx.de>
> > 
> > 	PR fortran/69741
> > 	* gfortran.dg/forall_18.f90: New testcase.
> > 

Here's the patch that I committed.

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 242624)
+++ gcc/fortran/resolve.c	(working copy)
@@ -9647,16 +9647,15 @@ gfc_resolve_forall (gfc_code *code, gfc_
   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_
       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.  */
Index: gcc/testsuite/gfortran.dg/forall_18.f90
===================================================================
--- gcc/testsuite/gfortran.dg/forall_18.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/forall_18.f90	(working copy)
@@ -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
-- 
Steve

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-11-20 19:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <582F8FF4.2070405@gmx.de>
     [not found] ` <20161119011833.GA27406@troutmask.apl.washington.edu>
2016-11-19 14:42   ` PR69741: Bad error in formal with array scalar loop counters Harald Anlauf
2016-11-19 14:44     ` Harald Anlauf
2016-11-20 19:02       ` Steve Kargl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).