public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kargl at gcc dot gnu.org" <gcc-bugzilla@gcc.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 [thread overview]
Message-ID: <bug-96255-4-Macsx10ybU@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-96255-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96255
--- 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 wrote:
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96255
> >
> > --- 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 concurrent
> > > section, one gets to
> > >
> > > m = match_forall_header (&head, &mask);
> > >
> > > to match the control portion of the statement.
> >
> > 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.
> >
>
> do current (JUNK HERE)
>
>
> forall (JUNK HERE)
>
> The JUNK HERE is parsed by the same code; namely, match_forall_header().
>
> So, if one fixes do current, then one fixes forall.
>
> 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
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 = (/ (i, i = 1, 10) /)
index = (/ b(1:10:2), b(2:10:2) /)
forall (i = 1:10)
a(index(i)) = 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 = (/ (i, i = 1, 10) /)
index = (/ b(1:10:2), b(2:10:2) /)
forall (integer(2) :: j = 1:10)
a(index(j)) = 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 = (/ (i, i = 1, 10) /)
index = (/ b(1:10:2), b(2:10:2) /)
forall (integer(2) :: i = 1:10) ! i re-declared here.
a(index(i)) = 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
shadow variable '_i'
Someone interesting in completing the patch can start here:
Index: gcc/fortran/match.c
===================================================================
--- 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
+ ([ 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 = false;
+ locus loc;
gfc_gobble_whitespace ();
@@ -2398,12 +2404,74 @@ match_forall_header (gfc_forall_iterator **phead, gfc_
if (gfc_match_char ('(') != MATCH_YES)
return MATCH_NO;
+ /* Check for an optional type-spec. */
+ gfc_clear_ts (&ts);
+ loc = gfc_current_locus;
+ m = gfc_match_type_spec (&ts);
+ if (m == MATCH_YES)
+ {
+ seen_ts = (gfc_match (" ::") == 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 != BT_INTEGER)
+ {
+ gfc_error ("Type-spec at %L must be an INTEGER type", &loc);
+ goto cleanup;
+ }
+ }
+ }
+ else if (m == MATCH_ERROR)
+ goto syntax;
+
m = match_forall_iterator (&new_iter);
if (m == MATCH_ERROR)
goto cleanup;
if (m == 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 = new_iter->var;
+ if (v->ts.type == BT_UNKNOWN)
+ {
+ v->ts.type = v->symtree->n.sym->ts.type = BT_INTEGER;
+ v->ts.kind = v->symtree->n.sym->ts.kind = ts.kind;
+ }
+ else if (v->ts.kind != ts.kind)
+ {
+ name = (char *) alloca (strlen (v->symtree->name) + 2);
+ strcpy (name, "_");
+ strcat (name, v->symtree->name);
+ if (gfc_get_sym_tree (name, NULL, &st, false) != 0)
+ gfc_internal_error ("whoops");
+
+ v = gfc_get_expr ();
+ v->where = gfc_current_locus;
+ v->expr_type = EXPR_VARIABLE;
+ v->ts.type = st->n.sym->ts.type = ts.type;
+ v->ts.kind = st->n.sym->ts.kind = ts.kind;
+ st->n.sym->forall_index = true;
+ v->symtree = 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 = tail = new_iter;
for (;;)
@@ -2417,6 +2485,42 @@ match_forall_header (gfc_forall_iterator **phead, gfc_
if (m == MATCH_YES)
{
+ if (seen_ts)
+ {
+ char *name;
+ gfc_expr *v;
+ gfc_symtree *st;
+
+ v = new_iter->var;
+ if (v->ts.type == BT_UNKNOWN)
+ {
+ v->ts.type = v->symtree->n.sym->ts.type = BT_INTEGER;
+ v->ts.kind = v->symtree->n.sym->ts.kind = ts.kind;
+ }
+ else if (v->ts.kind != ts.kind)
+ {
+ name = (char *) alloca (strlen (v->symtree->name) + 2);
+ strcpy (name, "_");
+ strcat (name, v->symtree->name);
+ if (gfc_get_sym_tree (name, NULL, &st, false) != 0)
+ gfc_internal_error ("whoops");
+
+ v = gfc_get_expr ();
+ v->expr_type = EXPR_VARIABLE;
+ v->ts.type = ts.type;
+ v->ts.kind = ts.kind;
+ v->where = gfc_current_locus;
+ st->n.sym->ts.type = ts.type;
+ st->n.sym->ts.kind = ts.kind;
+ st->n.sym->forall_index = true;
+ v->symtree = 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 = new_iter;
tail = new_iter;
continue;
next prev parent reply other threads:[~2020-07-22 6:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-21 0:47 [Bug fortran/96255] New: [F2018] Implement option type spec for index " jvdelisle at charter dot net
2020-07-21 4:24 ` [Bug fortran/96255] [F2018] Implement optional type spec for index in " kargl at gcc dot gnu.org
2020-07-21 5:53 ` kargl at gcc dot gnu.org
2020-07-21 5:57 ` kargl at gcc dot gnu.org
2020-07-21 14:34 ` dominiq at lps dot ens.fr
2020-07-21 19:41 ` jvdelisle at charter dot net
2020-07-21 19:44 ` jvdelisle at charter dot net
2020-07-21 20:25 ` sgk at troutmask dot apl.washington.edu
2020-07-22 6:29 ` kargl at gcc dot gnu.org [this message]
2020-07-22 18:25 ` kargl at gcc dot gnu.org
2021-11-11 21:01 ` anlauf at gcc dot gnu.org
2023-02-02 20:11 ` Boyce at engineer dot com
2023-02-03 7:25 ` kargl at gcc dot gnu.org
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bug-96255-4-Macsx10ybU@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).