From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C8B90383E835; Wed, 22 Jul 2020 06:29:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C8B90383E835 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1595399345; bh=R88gu1ixDLawrKWJ4DpvsDUj6NLs1Pyt6in4g27Mld8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VUy5XT5RcATNBafTKhSLp/R4hjVKG2jQ1u21V7v/qsF++Qu3UsA2WgnqrWU1F835K AJMwKa3SMujzNqUkqvCS1+1u1t7moRykSTaRWqxDJybkWtpLWZJhGA1RLOA6mVtKWh g2lzBjijurMrLgzmOEgaSOCD6JNP0okIaINIeBoY= From: "kargl at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/96255] [F2018] Implement optional type spec for index in DO CONCURRENT Date: Wed, 22 Jul 2020 06:29:05 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: kargl at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P4 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Jul 2020 06:29:05 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96255 --- Comment #7 from kargl at gcc dot gnu.org --- (In reply to Steve Kargl from comment #6) > On Tue, Jul 21, 2020 at 07:44:16PM +0000, jvdelisle at charter dot net wr= ote: > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96255 > >=20 > > --- Comment #5 from jvdelisle at charter dot net --- > > (In reply to kargl from comment #2) > > > This issue depends on the fix for FORALL. In gfc_match_do in the con= current > > > section, one gets to=20 > > >=20 > > > m =3D match_forall_header (&head, &mask); > > >=20 > > > to match the control portion of the statement. > >=20 > > Although we need to support forall, it is interesting that the standards > > committe i going to deprecate it, if they have not done so already. Not > > encouraged to be used for sure. Also they will be adding features to DO > > CONCUURENT which look useful to me. > >=20 >=20 > do current (JUNK HERE) >=20 >=20 > forall (JUNK HERE) >=20 > The JUNK HERE is parsed by the same code; namely, match_forall_header(). >=20 > So, if one fixes do current, then one fixes forall. >=20 > PS: J3 has an interesting discussion that suggests that do current > is also broken. IMHO, J3 has done no one any good with adding type specs to FORALL and DO CONCURRENT. There are three situations with=20 FORALL (and by extension DO CONCURRENT). 1) The control variable is declared in the outer scope and a type spec is not used. This is what gfortran currently assumes. subroutine sub1 implicit none integer i, index(10), a(10), b(10) b =3D (/ (i, i =3D 1, 10) /) index =3D (/ b(1:10:2), b(2:10:2) /) forall (i =3D 1:10) a(index(i)) =3D b(i) end forall print '(10I3)', a print '(10I3)', b print '(10I3)', index end subroutine sub1 2) The control variable appears only in the FORALL construct and a type spec is used. Here, we can simply set the type spec of the control variable. subroutine sub2 implicit none integer i, index(10), a(10), b(10) b =3D (/ (i, i =3D 1, 10) /) index =3D (/ b(1:10:2), b(2:10:2) /) forall (integer(2) :: j =3D 1:10) a(index(j)) =3D b(j) end forall print '(10I3)', a print '(10I3)', b print '(10I3)', index end subroutine sub2 3) The control variable is declared in the outer scope and a type spec is specified in the FORALL construct. The control variable is a statement entity (meaning FORALL should have its own namespace, but it does not have one). This now shadows the variable in the outer scope. If the kind type parameters are the same, we're ok because we can ignore the type spec. If the kind type parameters are different, gfortran needs to create a shadow variable. subroutine sub3 implicit none integer i, index(10), a(10), b(10) ! i declared here. b =3D (/ (i, i =3D 1, 10) /) index =3D (/ b(1:10:2), b(2:10:2) /) forall (integer(2) :: i =3D 1:10) ! i re-declared here. a(index(i)) =3D b(i) end forall print '(10I3)', a print '(10I3)', b print '(10I3)', index end subroutine sub3 The following diff permits the above cases with one caveat. In case 3), when gfortran parses the body of the FORALL construct, the 'i' in 'index(i)' and 'b(i)' is the 'i' from the outer scope. It is not the newly created shadow variable '_i'. AFAICT, we need to walk the gfc_code list in resolve.c:(gfc_resolve_forall) and update the 'i' to the=20 shadow variable '_i' Someone interesting in completing the patch can start here: Index: gcc/fortran/match.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gcc/fortran/match.c (revision 280157) +++ gcc/fortran/match.c (working copy) @@ -2381,7 +2381,10 @@ cleanup: } -/* Match the header of a FORALL statement. */ +/* Match the header of a FORALL statement. In F2008 and F2018, the form of + the header is=20 + ([ type-spec :: ] concurrent-control-list [, scalar-mask-expr ] ) + where type-spec is INTEGER. */ static match match_forall_header (gfc_forall_iterator **phead, gfc_expr **mask) @@ -2389,6 +2392,9 @@ match_forall_header (gfc_forall_iterator **phead, gfc_ gfc_forall_iterator *head, *tail, *new_iter; gfc_expr *msk; match m; + gfc_typespec ts; + bool seen_ts =3D false; + locus loc; gfc_gobble_whitespace (); @@ -2398,12 +2404,74 @@ match_forall_header (gfc_forall_iterator **phead, g= fc_ if (gfc_match_char ('(') !=3D MATCH_YES) return MATCH_NO; + /* Check for an optional type-spec. */ + gfc_clear_ts (&ts); + loc =3D gfc_current_locus; + m =3D gfc_match_type_spec (&ts); + if (m =3D=3D MATCH_YES) + { + seen_ts =3D (gfc_match (" ::") =3D=3D MATCH_YES); + + if (seen_ts) + { + if (!gfc_notify_std (GFC_STD_F2008, "FORALL or DO CONCURRENT " + "construct includes type specification " + "at %L", &loc)) + goto cleanup; + + if (ts.type !=3D BT_INTEGER) + { + gfc_error ("Type-spec at %L must be an INTEGER type", &loc); + goto cleanup; + } + } + } + else if (m =3D=3D MATCH_ERROR) + goto syntax; + m =3D match_forall_iterator (&new_iter); if (m =3D=3D MATCH_ERROR) goto cleanup; if (m =3D=3D MATCH_NO) goto syntax; + if (seen_ts) + { + char *name; + gfc_expr *v; + gfc_symtree *st; + + /* If the control variable does not have a type and type spec, then + update the type spec in both the variable and symtree. Otherwise, + create a new private symbol. */ + v =3D new_iter->var; + if (v->ts.type =3D=3D BT_UNKNOWN) + { + v->ts.type =3D v->symtree->n.sym->ts.type =3D BT_INTEGER; + v->ts.kind =3D v->symtree->n.sym->ts.kind =3D ts.kind; + } + else if (v->ts.kind !=3D ts.kind) + { + name =3D (char *) alloca (strlen (v->symtree->name) + 2); + strcpy (name, "_"); + strcat (name, v->symtree->name); + if (gfc_get_sym_tree (name, NULL, &st, false) !=3D 0) + gfc_internal_error ("whoops"); + + v =3D gfc_get_expr (); + v->where =3D gfc_current_locus; + v->expr_type =3D EXPR_VARIABLE; + v->ts.type =3D st->n.sym->ts.type =3D ts.type; + v->ts.kind =3D st->n.sym->ts.kind =3D ts.kind; + st->n.sym->forall_index =3D true; + v->symtree =3D st; + gfc_replace_expr (new_iter->var, v); + } + gfc_convert_type (new_iter->start, &ts, 1); + gfc_convert_type (new_iter->end, &ts, 1); + gfc_convert_type (new_iter->stride, &ts, 1); + } + head =3D tail =3D new_iter; for (;;) @@ -2417,6 +2485,42 @@ match_forall_header (gfc_forall_iterator **phead, gf= c_ if (m =3D=3D MATCH_YES) { + if (seen_ts) + { + char *name; + gfc_expr *v; + gfc_symtree *st; + + v =3D new_iter->var; + if (v->ts.type =3D=3D BT_UNKNOWN) + { + v->ts.type =3D v->symtree->n.sym->ts.type =3D BT_INTEGER; + v->ts.kind =3D v->symtree->n.sym->ts.kind =3D ts.kind; + } + else if (v->ts.kind !=3D ts.kind) + { + name =3D (char *) alloca (strlen (v->symtree->name) + 2); + strcpy (name, "_"); + strcat (name, v->symtree->name); + if (gfc_get_sym_tree (name, NULL, &st, false) !=3D 0) + gfc_internal_error ("whoops"); + + v =3D gfc_get_expr (); + v->expr_type =3D EXPR_VARIABLE; + v->ts.type =3D ts.type; + v->ts.kind =3D ts.kind; + v->where =3D gfc_current_locus; + st->n.sym->ts.type =3D ts.type; + st->n.sym->ts.kind =3D ts.kind; + st->n.sym->forall_index =3D true; + v->symtree =3D st; + gfc_replace_expr (new_iter->var, v); + } + gfc_convert_type (new_iter->start, &ts, 1); + gfc_convert_type (new_iter->end, &ts, 1); + gfc_convert_type (new_iter->stride, &ts, 1); + } + tail->next =3D new_iter; tail =3D new_iter; continue;=