Issue 242970
Summary [flang] DO CONCURRENT REDUCE rejects a BLOCK-scoped variable as 'not a variable'
Labels flang
Assignees
Reporter certik
    ## Summary

Flang rejects a scalar real variable declared in a `BLOCK` when it appears in the `REDUCE` locality specifier of an enclosed `DO CONCURRENT` loop. The diagnostic says the declared variable "is not a variable".

The same reduction passes Flang's semantic checks when `ss` is declared at program scope instead. No outer `DO CONCURRENT` is needed to reproduce this.

## Minimal reproducer

Save as `mre.f90`:

```fortran
program test
    implicit none
    block
        real :: ss
        ss = 0.0
 do concurrent (integer :: i = 1:4) reduce(+:ss)
            ss = ss + real(i)
        end do
        print *, ss
        if (ss /= 10.0) error stop 1
    end block
end program
```

## Actual behavior

```console
$ flang -fsyntax-only mre.f90
```

Flang exits with status 1 and reports:

```text
mre.f90:6:53: error: 'ss' may not appear in a locality-spec because it is not definable
        do concurrent (integer :: i = 1:4) reduce(+:ss)
 ^^
mre.f90:6:53: error: because: 'ss' is not a variable
mre.f90:4:17: Declaration of 'ss'
        real :: ss
 ^^
```

## Expected behavior and comparison

Accept the block-scoped reduction variable, as for the program-scoped control case. Running the program should print `10.0` and exit successfully.

Verified with:

```console
$ gfortran -std=f2023 mre.f90 -o mre
$ ./mre
 10.0000000
```

Both compilation and execution exit with status 0 using GNU Fortran 16.1.0.

For the Flang control case, move `real :: ss` immediately after `implicit none`, outside the `BLOCK`, leaving the reduction unchanged. `flang -fsyntax-only` then exits with status 0.

## Environment

```text
flang version 24.0.0git (https://github.com/llvm/llvm-project.git e8e9abb11b3d199d861900858a7b42dcaabe4de3)
Target: arm64-apple-darwin24.6.0
Thread model: posix

GNU Fortran (conda-forge gcc 16.1.0-3) 16.1.0
```

Originally encountered compiling the CPU Fortran implementation in `certik/qwen3.8-27B`, in `conv1d_silu_split_norm_bf16` in `src-fortran/dense_kernels.f90`. The application has a block-local reduction variable inside an outer concurrent loop, but the outer loop is unnecessary for this failure.

AI assistance: GitHub Copilot CLI was used to reduce the application failure and prepare this report. The MRE, compiler diagnostics, GFortran result, and Flang control case were verified locally.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to