See attached patch. A DO CONCURRENT in the fiats example
concurrent-inferences.f90 names the enclosing function, which has no
RESULT clause, in SHARED, and every gfortran with locality specs
rejects it. resolve_locality_spec accepted only FL_VARIABLE symbols.
It now also accepts a function result variable, using the test that
gfc_check_vardef_context uses, so ENTRY results are accepted too.
Accepting results let LOCAL and LOCAL_INIT copies of them reach
gfc_trans_concurrent_locality_spec. Testing those turned up bugs in
how the copies are built that also hit other variables on trunk: an
ICE for module variables and for some character variables, a bogus
"too large" error for character(len=n), and a segfault for automatic
arrays, whose copy was never allocated. The new tests need all of
them, so they are fixed here as well.
Start with resolve_locality_spec in resolve.cc, the fix for the PR
itself. Then gfc_trans_concurrent_locality_spec in trans-stmt.cc: the
copy of a result becomes an ordinary variable, every copy drops its
module and use_assoc, and LOCAL_INIT of a result swaps the outer and
inner symbol so the read goes through the real symbol.
The next two hunks there emit a DECL_EXPR for a variable-length string
and give a heap-allocated array copy the outer array's type, so the
bounds computed on entry are used, and record a free in the new
cleanup field. The after_body loop emits it, and gfc_trans_forall_1
moves the cycle label above that call so CYCLE cannot skip the free.
The trans-decl.cc hunk keeps gfc_get_symbol_decl from chaining a
string length decl a second time when the copy is built. In the
tests, do_concurrent_17 covers results and module variables, 18 the
diagnostics, 19 character copies and 20 array copies.
Regression tested on x86_64.
OK for mainline?
Regards,
Jerry
---
fortran: [PR129038] Function results in DO CONCURRENT locality specs
A function result named by the function itself was rejected in a DO
CONCURRENT locality spec, because only FL_VARIABLE symbols were
accepted, although F2023 C1126 allows any variable of the scoping unit.
Accept a result variable, ENTRY results included, with the test that
gfc_check_vardef_context uses. The LOCAL copy of a result is an
ordinary variable, and LOCAL_INIT reads the outer value through the
real symbol, because gfc_conv_variable finds ENTRY results by address.
LOCAL copies of results exposed bugs that also hit other variables. A
copy of a module variable kept its module and hit an assert in
gfc_finish_var_decl. A copy of a variable-length string got no
DECL_EXPR, and finishing its length decl a second time corrupted the
decl chain. A heap-allocated array copy was never allocated; it now
takes the outer array's type, is allocated each iteration and freed
after the body, which now follows the CYCLE label.
Assisted-by: Claude Opus 5.5
PR fortran/129038
gcc/fortran/ChangeLog:
* resolve.cc (resolve_locality_spec): Accept a function result
variable.
* trans-decl.cc (gfc_get_symbol_decl): Do not finish a string
length decl that already has a context.
* trans-stmt.cc (struct symbol_and_tree_t): Add result, module
and cleanup.
(gfc_trans_concurrent_locality_spec): Save and restore result and
module, and emit cleanup after the body. Make the copy of a
function result an ordinary variable, and clear module and
use_assoc of every copy. Emit a DECL_EXPR for a variable-length
string copy. Give a heap-allocated array copy the outer array's
type, allocate it and free it in the cleanup. For LOCAL_INIT of
a function result, read through the outer symbol.
(gfc_trans_forall_1): Emit the cycle label before resetting the
locality variables.
gcc/testsuite/ChangeLog:
* gfortran.dg/do_concurrent_17.f90: New test.
* gfortran.dg/do_concurrent_18.f90: New test.
* gfortran.dg/do_concurrent_19.f90: New test.
* gfortran.dg/do_concurrent_20.f90: New test.
>From 253179d5f13593140be6304901726badcc395131 Mon Sep 17 00:00:00 2001
From: Jerry DeLisle <[email protected]>
Date: Wed, 25 Nov 2026 14:33:02 -0800
Subject: [PATCH] fortran: [PR129038] Function results in DO CONCURRENT
locality specs
A function result named by the function itself was rejected in a DO
CONCURRENT locality spec, because only FL_VARIABLE symbols were
accepted, although F2023 C1126 allows any variable of the scoping unit.
Accept a result variable, ENTRY results included, with the test that
gfc_check_vardef_context uses. The LOCAL copy of a result is an
ordinary variable, and LOCAL_INIT reads the outer value through the
real symbol, because gfc_conv_variable finds ENTRY results by address.
LOCAL copies of results exposed bugs that also hit other variables. A
copy of a module variable kept its module and hit an assert in
gfc_finish_var_decl. A copy of a variable-length string got no
DECL_EXPR, and finishing its length decl a second time corrupted the
decl chain. A heap-allocated array copy was never allocated; it now
takes the outer array's type, is allocated each iteration and freed
after the body, which now follows the CYCLE label.
Assisted-by: Claude Opus 5.5
PR fortran/129038
gcc/fortran/ChangeLog:
* resolve.cc (resolve_locality_spec): Accept a function result
variable.
* trans-decl.cc (gfc_get_symbol_decl): Do not finish a string
length decl that already has a context.
* trans-stmt.cc (struct symbol_and_tree_t): Add result, module
and cleanup.
(gfc_trans_concurrent_locality_spec): Save and restore result and
module, and emit cleanup after the body. Make the copy of a
function result an ordinary variable, and clear module and
use_assoc of every copy. Emit a DECL_EXPR for a variable-length
string copy. Give a heap-allocated array copy the outer array's
type, allocate it and free it in the cleanup. For LOCAL_INIT of
a function result, read through the outer symbol.
(gfc_trans_forall_1): Emit the cycle label before resetting the
locality variables.
gcc/testsuite/ChangeLog:
* gfortran.dg/do_concurrent_17.f90: New test.
* gfortran.dg/do_concurrent_18.f90: New test.
* gfortran.dg/do_concurrent_19.f90: New test.
* gfortran.dg/do_concurrent_20.f90: New test.
---
gcc/fortran/resolve.cc | 4 +-
gcc/fortran/trans-decl.cc | 3 +-
gcc/fortran/trans-stmt.cc | 100 ++++++++++++-
.../gfortran.dg/do_concurrent_17.f90 | 137 ++++++++++++++++++
.../gfortran.dg/do_concurrent_18.f90 | 23 +++
.../gfortran.dg/do_concurrent_19.f90 | 82 +++++++++++
.../gfortran.dg/do_concurrent_20.f90 | 101 +++++++++++++
7 files changed, 443 insertions(+), 7 deletions(-)
create mode 100644 gcc/testsuite/gfortran.dg/do_concurrent_17.f90
create mode 100644 gcc/testsuite/gfortran.dg/do_concurrent_18.f90
create mode 100644 gcc/testsuite/gfortran.dg/do_concurrent_19.f90
create mode 100644 gcc/testsuite/gfortran.dg/do_concurrent_20.f90
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 55b8e6a42c7..125d0874a89 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -8964,7 +8964,9 @@ resolve_locality_spec (gfc_code *code, gfc_namespace *ns)
continue;
if (expr->expr_type != EXPR_VARIABLE
- || expr->symtree->n.sym->attr.flavor != FL_VARIABLE
+ || (expr->symtree->n.sym->attr.flavor != FL_VARIABLE
+ && !(expr->symtree->n.sym->attr.flavor == FL_PROCEDURE
+ && expr->symtree->n.sym->result == expr->symtree->n.sym))
|| (expr->ref
&& (expr->ref->type != REF_ARRAY
|| expr->ref->u.ar.type != AR_FULL
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 8f0ce29bc53..792e490c413 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -2089,7 +2089,8 @@ gfc_get_symbol_decl (gfc_symbol * sym)
of their associated target. */
if (sym->ts.type == BT_CHARACTER
&& TREE_CODE (length) != INTEGER_CST
- && TREE_CODE (sym->ts.u.cl->backend_decl) != INDIRECT_REF)
+ && TREE_CODE (sym->ts.u.cl->backend_decl) != INDIRECT_REF
+ && !(DECL_P (length) && DECL_CONTEXT (length)))
{
length = fold_convert (gfc_charlen_type_node, length);
gfc_finish_var_decl (length, sym);
diff --git a/gcc/fortran/trans-stmt.cc b/gcc/fortran/trans-stmt.cc
index 6f1aa674b7e..02955cff89e 100644
--- a/gcc/fortran/trans-stmt.cc
+++ b/gcc/fortran/trans-stmt.cc
@@ -5347,8 +5347,11 @@ gfc_trans_pointer_assign_need_temp (gfc_expr * expr1, gfc_expr * expr2,
struct symbol_and_tree_t
{
gfc_symbol *sym;
+ gfc_symbol *result;
+ const char *module;
gfc_expr *value;
tree decl;
+ tree cleanup;
symbol_attribute attr;
};
@@ -5374,8 +5377,12 @@ gfc_trans_concurrent_locality_spec (bool after_body, stmtblock_t *body,
{
for (unsigned i = 0; i < saved_decls->size (); i++)
{
+ if ((*saved_decls)[i].cleanup)
+ gfc_add_expr_to_block (body, (*saved_decls)[i].cleanup);
(*saved_decls)[i].sym->backend_decl = (*saved_decls)[i].decl;
(*saved_decls)[i].sym->attr = (*saved_decls)[i].attr;
+ (*saved_decls)[i].sym->result = (*saved_decls)[i].result;
+ (*saved_decls)[i].sym->module = (*saved_decls)[i].module;
(*saved_decls)[i].sym->value = (*saved_decls)[i].value;
}
return;
@@ -5411,8 +5418,11 @@ gfc_trans_concurrent_locality_spec (bool after_body, stmtblock_t *body,
gfc_symbol *sym = el->expr->symtree->n.sym;
(*saved_decls)[cnt].sym = sym;
(*saved_decls)[cnt].attr = sym->attr;
+ (*saved_decls)[cnt].result = sym->result;
+ (*saved_decls)[cnt].module = sym->module;
(*saved_decls)[cnt].value = sym->value;
(*saved_decls)[cnt].decl = sym->backend_decl;
+ (*saved_decls)[cnt].cleanup = NULL_TREE;
if (sym->attr.dimension && sym->as->type == AS_ASSUMED_SHAPE)
{
@@ -5424,6 +5434,19 @@ gfc_trans_concurrent_locality_spec (bool after_body, stmtblock_t *body,
}
gfc_symbol outer_sym = *sym;
+ bool result_var = sym->attr.function && sym->result == sym;
+
+ /* The decl that holds the outer array's type. */
+ tree outer_decl = sym->backend_decl;
+ if (result_var && sym->attr.dimension)
+ {
+ tree parent_decl = DECL_CONTEXT (current_function_decl);
+ int parent_flag = (sym->backend_decl == parent_decl
+ || (sym->attr.entry
+ && sym->ns->proc_name->backend_decl
+ == parent_decl));
+ outer_decl = gfc_get_fake_result_decl (sym, parent_flag);
+ }
/* Create the inner local variable. */
sym->backend_decl = NULL;
@@ -5432,6 +5455,16 @@ gfc_trans_concurrent_locality_spec (bool after_body, stmtblock_t *body,
sym->attr.value = 0;
sym->attr.dummy = 0;
sym->attr.optional = 0;
+ sym->attr.use_assoc = 0;
+ sym->module = NULL;
+
+ /* The local copy of a function result is an ordinary variable. */
+ if (result_var)
+ {
+ sym->attr.flavor = FL_VARIABLE;
+ sym->attr.function = 0;
+ sym->result = NULL;
+ }
{
/* Slightly ugly hack for adding the decl via add_decl_as_local. */
@@ -5447,6 +5480,40 @@ gfc_trans_concurrent_locality_spec (bool after_body, stmtblock_t *body,
sym->ns->proc_name = saved_proc_name;
}
+ /* A variable-length string is allocated by its DECL_EXPR. */
+ tree decl = sym->backend_decl;
+ if (sym->ts.type == BT_CHARACTER
+ && !INTEGER_CST_P (sym->ts.u.cl->backend_decl)
+ && !POINTER_TYPE_P (TREE_TYPE (decl)))
+ {
+ gfc_trans_vla_type_sizes (sym, body);
+ gfc_add_expr_to_block (body,
+ build1_loc (input_location, DECL_EXPR,
+ TREE_TYPE (sym->backend_decl),
+ sym->backend_decl));
+ }
+
+ /* A heap-allocated array copy takes the type, and with it the
+ bounds, of the outer array and gets new data each iteration. */
+ if (POINTER_TYPE_P (TREE_TYPE (decl))
+ && GFC_ARRAY_TYPE_P (TREE_TYPE (decl))
+ && outer_decl
+ && POINTER_TYPE_P (TREE_TYPE (outer_decl))
+ && GFC_ARRAY_TYPE_P (TREE_TYPE (outer_decl)))
+ {
+ tree ptype = TREE_TYPE (outer_decl);
+ tree etype = gfc_get_element_type (TREE_TYPE (ptype));
+ tree nelem = fold_convert (gfc_array_index_type,
+ GFC_TYPE_ARRAY_SIZE (ptype));
+ tree size = fold_build2_loc (input_location, MULT_EXPR,
+ gfc_array_index_type, nelem,
+ fold_convert (gfc_array_index_type,
+ TYPE_SIZE_UNIT (etype)));
+ TREE_TYPE (decl) = ptype;
+ gfc_add_modify (body, decl, gfc_call_malloc (body, ptype, size));
+ (*saved_decls)[cnt].cleanup = gfc_call_free (decl);
+ }
+
symbol_attribute attr = gfc_expr_attr (el->expr);
if (type == LOCALITY_LOCAL
&& !attr.pointer
@@ -5463,10 +5530,32 @@ gfc_trans_concurrent_locality_spec (bool after_body, stmtblock_t *body,
st.n.sym = &outer_sym;
gfc_expr expr = *el->expr;
expr.symtree = &st;
+ gfc_expr *lhs = el->expr, *rhs = &expr;
+ gfc_symbol inner_sym;
+ if (result_var)
+ {
+ /* Read the result through SYM, which gfc_conv_variable
+ looks up in the ENTRY list by address. */
+ inner_sym = *sym;
+ st.n.sym = &inner_sym;
+ lhs = &expr;
+ rhs = el->expr;
+ sym->backend_decl = outer_sym.backend_decl;
+ sym->attr = outer_sym.attr;
+ sym->result = outer_sym.result;
+ sym->module = outer_sym.module;
+ }
tree t = (attr.pointer
- ? gfc_trans_pointer_assignment (el->expr, &expr)
- : gfc_trans_assignment (el->expr, &expr, false, false,
+ ? gfc_trans_pointer_assignment (lhs, rhs)
+ : gfc_trans_assignment (lhs, rhs, false, false,
false, false));
+ if (result_var)
+ {
+ sym->backend_decl = inner_sym.backend_decl;
+ sym->attr = inner_sym.attr;
+ sym->result = inner_sym.result;
+ sym->module = inner_sym.module;
+ }
gfc_add_expr_to_block (body, t);
}
cnt++;
@@ -5749,15 +5838,16 @@ gfc_trans_forall_1 (gfc_code * code, forall_info * nested_forall_info)
tmp = gfc_trans_code (code->block->next);
gfc_add_expr_to_block (&body, tmp);
- /* Reset locality variables. */
- gfc_trans_concurrent_locality_spec (true, &body, &saved_decls,
- code->ext.concur.locality);
if (TREE_USED (cycle_label))
{
tmp = build1_v (LABEL_EXPR, cycle_label);
gfc_add_expr_to_block (&body, tmp);
}
+ /* Reset locality variables. */
+ gfc_trans_concurrent_locality_spec (true, &body, &saved_decls,
+ code->ext.concur.locality);
+
tmp = gfc_finish_block (&body);
nested_forall_info->do_concurrent = true;
tmp = gfc_trans_nested_forall_loop (nested_forall_info, tmp, 1);
diff --git a/gcc/testsuite/gfortran.dg/do_concurrent_17.f90 b/gcc/testsuite/gfortran.dg/do_concurrent_17.f90
new file mode 100644
index 00000000000..7bdeb8bac61
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/do_concurrent_17.f90
@@ -0,0 +1,137 @@
+! { dg-do run }
+!
+! PR 129038
+
+module m
+ implicit none
+ integer :: x = 42
+contains
+ function sh(n)
+ integer, intent(in) :: n
+ integer, allocatable :: sh(:)
+ integer i
+ allocate (sh(n))
+ do concurrent (i=1:n) default(none) shared(sh)
+ sh(i) = i
+ end do
+ end function
+
+ integer function red(n)
+ integer, intent(in) :: n
+ integer i
+ red = 0
+ do concurrent (i=1:n) reduce(+:red)
+ red = red + i
+ end do
+ end function
+
+ integer function loc(a)
+ integer, intent(out) :: a(:)
+ integer i
+ loc = 7
+ do concurrent (i=1:size(a)) local(loc)
+ loc = 2*i
+ a(i) = loc
+ end do
+ end function
+
+ function loci(a)
+ integer, intent(out) :: a(:)
+ integer loci(2)
+ integer i
+ loci = [10, 20]
+ do concurrent (i=1:size(a)) local_init(loci)
+ loci(1) = loci(1) + i
+ a(i) = sum (loci)
+ end do
+ end function
+
+ integer function host(n)
+ integer, intent(in) :: n
+ host = 0
+ call s
+ contains
+ subroutine s
+ integer i
+ do concurrent (i=1:n) default(none) reduce(+:host)
+ host = host + i
+ end do
+ end subroutine
+ end function
+
+ function ent(a)
+ integer, intent(out) :: a(:)
+ integer ent, ent2
+ integer i
+ ent = 5
+ do concurrent (i=1:size(a)) local(ent)
+ ent = 3*i
+ a(i) = ent
+ end do
+ return
+ entry ent2(a)
+ ent2 = 0
+ do concurrent (i=1:size(a)) default(none) shared(a) reduce(+:ent2)
+ a(i) = i
+ ent2 = ent2 + i
+ end do
+ end function
+
+ function eli(a)
+ integer, intent(out) :: a(:)
+ integer eli
+ real eli2
+ integer i
+ eli = 7
+ do concurrent (i=1:size(a)) local_init(eli)
+ eli = eli + i
+ a(i) = eli
+ end do
+ return
+ entry eli2(a)
+ eli2 = 2.5
+ do concurrent (i=1:size(a)) local_init(eli2)
+ eli2 = eli2 + i
+ a(i) = nint (2*eli2)
+ end do
+ end function
+
+ subroutine modvar(a)
+ integer, intent(out) :: a(:)
+ integer i
+ do concurrent (i=1:size(a)) local(x)
+ x = i
+ a(i) = x
+ end do
+ end subroutine
+end module
+
+program p
+ use m
+ implicit none
+ integer a(3), i
+ if (any (sh(4) /= [1,2,3,4])) stop 1
+ if (red(10) /= 55) stop 2
+ if (loc(a) /= 7) stop 3
+ if (any (a /= [2,4,6])) stop 4
+ if (any (loci(a) /= [10,20])) stop 5
+ if (any (a /= [31,32,33])) stop 6
+ if (host(4) /= 10) stop 7
+ if (ent(a) /= 5) stop 8
+ if (any (a /= [3,6,9])) stop 9
+ if (ent2(a) /= 6) stop 10
+ if (any (a /= [1,2,3])) stop 11
+ call modvar(a)
+ if (x /= 42) stop 12
+ if (any (a /= [1,2,3])) stop 13
+ do concurrent (i=1:3) local_init(x)
+ x = x + i
+ a(i) = x
+ end do
+ if (x /= 42) stop 14
+ if (any (a /= [43,44,45])) stop 15
+ if (eli(a) /= 7) stop 16
+ if (any (a /= [8,9,10])) stop 17
+ if (eli2(a) /= 2.5) stop 18
+ if (any (a /= [7,9,11])) stop 19
+end program
diff --git a/gcc/testsuite/gfortran.dg/do_concurrent_18.f90 b/gcc/testsuite/gfortran.dg/do_concurrent_18.f90
new file mode 100644
index 00000000000..41c46d18e77
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/do_concurrent_18.f90
@@ -0,0 +1,23 @@
+! { dg-do compile }
+!
+! PR 129038
+
+module m
+contains
+ function f()
+ integer f(3)
+ integer i
+ do concurrent (i=1:3) default(none) ! { dg-error "not specified in a locality spec" }
+ f(i) = i ! { dg-error "not specified in a locality spec" }
+ end do
+ end function
+
+ function g()
+ integer, allocatable :: g(:)
+ integer i
+ allocate (g(3))
+ do concurrent (i=1:3) local(g) ! { dg-error "ALLOCATABLE attribute not permitted" }
+ g(i) = i
+ end do
+ end function
+end module
diff --git a/gcc/testsuite/gfortran.dg/do_concurrent_19.f90 b/gcc/testsuite/gfortran.dg/do_concurrent_19.f90
new file mode 100644
index 00000000000..4af25144af1
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/do_concurrent_19.f90
@@ -0,0 +1,82 @@
+! { dg-do run }
+!
+! PR 129038
+
+module m
+ implicit none
+contains
+ subroutine auto(n, a)
+ integer, intent(in) :: n
+ character(len=1), intent(out) :: a(3)
+ character(len=n) x
+ integer i
+ x = 'abc'
+ do concurrent (i=1:3) local(x)
+ x = repeat (achar (iachar ('0') + i), n)
+ a(i) = x(1:1)
+ end do
+ if (x /= 'abc') stop 1
+ do concurrent (i=1:3) local_init(x)
+ x(2:2) = achar (iachar ('0') + i)
+ a(i) = x(2:2)
+ if (x(1:1) /= 'a' .or. x(3:3) /= 'c') error stop 2
+ end do
+ if (x /= 'abc') stop 3
+ end subroutine
+
+ subroutine assumed(x, a)
+ character(len=*), intent(inout) :: x
+ character(len=1), intent(out) :: a(3)
+ integer i
+ do concurrent (i=1:3) local_init(x)
+ x(1:1) = achar (iachar ('0') + i)
+ a(i) = x(1:1)
+ if (x(2:) /= 'bc') error stop 4
+ end do
+ if (x /= 'abc') stop 5
+ end subroutine
+
+ function c(s)
+ character(len=1), intent(out) :: s(:)
+ character(len=3) c, d
+ integer i
+ c = 'abc'
+ do concurrent (i=1:size(s)) local_init(c)
+ c(2:2) = achar (iachar ('0') + i)
+ s(i) = c(2:2)
+ if (c(1:1) /= 'a' .or. c(3:3) /= 'c') error stop 6
+ end do
+ return
+ entry d(s)
+ d = 'xyz'
+ do concurrent (i=1:size(s)) local(d)
+ d = 'q' // achar (iachar ('0') + i) // 'q'
+ s(i) = d(2:2)
+ end do
+ end function
+end module
+
+program p
+ use m
+ implicit none
+ character(len=1) a(3)
+ character(len=3) :: y = 'abc'
+ character(len=:), pointer :: q
+ character(len=4), target :: t1 = 'abcd', t2 = 'wxyz'
+ integer i
+ call auto (3, a)
+ if (any (a /= ['1','2','3'])) stop 7
+ call assumed (y, a)
+ if (any (a /= ['1','2','3'])) stop 8
+ if (c(a) /= 'abc') stop 9
+ if (any (a /= ['1','2','3'])) stop 10
+ if (d(a) /= 'xyz') stop 11
+ if (any (a /= ['1','2','3'])) stop 12
+ q => t1
+ do concurrent (i=1:3) local_init(q)
+ a(i) = q(i:i)
+ q => t2
+ end do
+ if (.not. associated (q, t1)) stop 13
+ if (any (a /= ['a','b','c'])) stop 14
+end program
diff --git a/gcc/testsuite/gfortran.dg/do_concurrent_20.f90 b/gcc/testsuite/gfortran.dg/do_concurrent_20.f90
new file mode 100644
index 00000000000..9abbb3896b4
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/do_concurrent_20.f90
@@ -0,0 +1,101 @@
+! { dg-do run }
+!
+! PR 129038
+
+module m
+ implicit none
+ type t
+ integer a, b
+ end type
+contains
+ subroutine auto(n, m, r)
+ integer n, m, r(3), i
+ integer x(0:n, 2:m)
+ x = -1
+ n = n + 5
+ do concurrent (i=1:3) local(x)
+ x = i
+ r(i) = sum (x) + 100*size (x) + 1000*lbound (x, 2)
+ end do
+ if (any (x /= -1)) stop 1
+ do concurrent (i=1:3) local_init(x)
+ x(0, 2) = i
+ r(i) = r(i) + 10000*sum (x)
+ end do
+ if (any (x /= -1)) stop 2
+ end subroutine
+
+ subroutine adjustable(n, a, r)
+ integer n, a(n), r(3), i
+ do concurrent (i=1:3) local_init(a)
+ a(1) = a(1) + i
+ r(i) = sum (a)
+ end do
+ if (any (a /= [1, 2])) stop 3
+ end subroutine
+
+ subroutine chars(n, r)
+ integer n, i
+ character(len=1) r(3)
+ character(len=n) c(n)
+ c = repeat ('a', n)
+ do concurrent (i=1:3) local_init(c)
+ c(1)(1:1) = achar (iachar ('0') + i)
+ if (c(2) /= repeat ('a', n)) error stop 4
+ r(i) = c(1)(1:1)
+ end do
+ if (any (c /= repeat ('a', n))) stop 5
+ end subroutine
+
+ subroutine cyc(n, r)
+ integer n, r(4), i
+ type(t) x(n)
+ r = 0
+ do concurrent (i=1:4) local(x)
+ x = t(i, -i)
+ if (mod (i, 2) == 0) cycle
+ r(i) = sum (x%a)
+ end do
+ end subroutine
+
+ function f(n, r)
+ integer, intent(in) :: n
+ integer, intent(out) :: r(3)
+ integer f(n), g(n)
+ integer i
+ f = 7
+ do concurrent (i=1:3) local_init(f)
+ f(1) = f(1) + i
+ r(i) = sum (f)
+ end do
+ return
+ entry g(n, r)
+ g = 4
+ do concurrent (i=1:3) local(g)
+ g = i
+ r(i) = sum (g)
+ end do
+ end function
+end module
+
+program p
+ use m
+ implicit none
+ integer r(4), a(2), n
+ character(len=1) s(3)
+ n = 2
+ call auto (n, 4, r)
+ if (n /= 7) stop 6
+ if (any (r(1:3) /= [-67091, -57082, -47073])) stop 7
+ a = [1, 2]
+ call adjustable (2, a, r)
+ if (any (r(1:3) /= [4, 5, 6])) stop 8
+ call chars (3, s)
+ if (any (s /= ['1','2','3'])) stop 9
+ call cyc (3, r)
+ if (any (r /= [3, 0, 9, 0])) stop 10
+ if (any (f(2, r) /= 7)) stop 11
+ if (any (r(1:3) /= [15, 16, 17])) stop 12
+ if (any (g(3, r) /= 4)) stop 13
+ if (any (r(1:3) /= [3, 6, 9])) stop 14
+end program
--
2.56.1