https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129038
Bug ID: 129038
Summary: DO CONCURRENT locality spec rejects a function result
variable
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: jvdelisle at gcc dot gnu.org
Target Milestone: ---
Created attachment 66294
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66294&action=edit
Draft patch to fix this.
I found this one while testing a recent pull of Berkeley fiats package.
A function result variable named by the function itself (no RESULT
clause) is rejected in a DO CONCURRENT locality spec. F2023 C1126
only requires "the name of a variable in the innermost executable
construct or scoping unit that includes the DO CONCURRENT statement",
and the result variable is one.
program p
implicit none
integer, allocatable :: r(:)
r = f(4)
print *, r
contains
function f(n)
integer, intent(in) :: n
integer, allocatable :: f(:)
integer i
allocate (f(n))
do concurrent (i=1:n) default(none) shared(f)
f(i) = i
end do
end function
end program
$ gfortran pr.f90
pr.f90:12:48:
12 | do concurrent (i=1:n) default(none) shared(f)
| 1
Error: Expected variable name in SHARED locality spec at (1)
pr.f90:13:7:
12 | do concurrent (i=1:n) default(none) shared(f)
| 2
13 | f(i) = i
| 1~~~~
Error: Variable 'f' at (1) not specified in a locality spec of DO
CONCURRENT at (2) but required due to DEFAULT (NONE)
Expected: the program compiles and prints 1 2 3 4. With RESULT(r)
and shared(r) it already does. LOCAL, LOCAL_INIT and REDUCE reject
the result the same way, as do ENTRY result names.
Found in the fiats neural-network library
(example/concurrent-inferences.f90), which no longer builds with
gfortran.
Fix available -- draft patch attached. Once function results are
accepted, a LOCAL or LOCAL_INIT copy of one exposed several
long-standing problems in how gfortran builds LOCAL copies. The
same patch fixes these; they also fail with ordinary variables on
trunk:
- LOCAL(x) on a module variable: ICE in gfc_finish_var_decl
- LOCAL(x), character(len=n) x: bogus "size of variable 'x' is
too large"
- LOCAL_INIT(x), character(len=*) dummy x, or a deferred-length
character pointer: ICE
- LOCAL(x), automatic array x(n): segfault at run time (the copy
is never allocated)