llvm / llvm/llvm-project

[Flang][OpenMP] Incorrect semantic error for a reduction identifier whose name is the same as an intrinsic procedure

Open
#191,927 1 comment 0 reactions 0 assignees View on GitHub
flang:frontend flang:openmp
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

## Summary

When accessibility is specified for a reduction identifier whose name is the same as an intrinsic procedure, Flang emits an incorrect semantic error.

* 7.6.14 `declare_reduction` Directive
> If the specified reduction identifier is the same as the name of a user-defined operator or an extended operator, or the same as a generic name that is one of the allowed intrinsic procedures, and if the operator or procedure name appears in an accessibility statement in the same module, the accessibility of the corresponding `declare_reduction` directive is determined by the accessibility attribute of the statement.

### Reproducer

* test.f90

```fortran
module mod
implicit none
!$omp declare reduction (IOR:real:omp_out=omp_in) &
!$omp initializer(omp_priv=0.0)
public :: IOR
end

print *, "pass"
end
```

* commands

```console
$ flang --version
flang version 23.0.0git (https://github.com/llvm/llvm-project.git 5347264191e74840adc740db1aa41b7a9d33670a)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/llvm/build/bin
Build config: +assertions
$ flang test.f90 -fopenmp && ./a.out
error: Semantic errors in test.f90
test.f90:5:13: error: No explicit type declared for 'ior'
public :: IOR
^^^
```

My understanding is that this should be accepted, as the following non-OpenMP program is accepted.

```fortran
module mod
implicit none
public :: IOR
contains
function IOR(omp_in) result(omp_out)
real :: omp_in, omp_out
omp_out=omp_in
end function IOR
end

print *, "pass"
end
```

## Non-problematic Conditions

The issue does not occur under the following conditions:
* Changing the name of the reduction identifier (e.g., from `IOR` to `A`).
* Note that other compilers report semantic errors. (See below.)

## Other Compilers

* GFortran
```console
$ gfortran --version
GNU Fortran (GCC) 15.2.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gfortran test.f90 -fopenmp && ./a.out
test.f90:5:15:

5 | public :: IOR
| 1
Error: Symbol 'ior' at (1) has no IMPLICIT type
```
* If the identifier is renamed:
```console
$ gfortran test2.f90 -fopenmp && ./a.out
test2.f90:5:13:

5 | public :: A
| 1
Error: Symbol 'a' at (1) has no IMPLICIT type
```

* Intel Fortran
```console
$ ifx --version
ifx (IFX) 2025.3.2 20260112
Copyright (C) 1985-2026 Intel Corporation. All rights reserved.

$ ifx -O0 test.f90 -qopenmp && ./a.out
pass
```
* If the identifier is renamed:
```console
$ ifx -O0 test2.f90 -qopenmp && ./a.out
test2.f90(5): error #6404: This name does not have a type, and must have an explicit type. [A]
public :: A
------------^
compilation aborted for test2.f90 (code 1)
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the semantic error with the provided test.f90 and the flang -fopenmp command. Trace Flang's handling of accessibility statements for an OpenMP declare reduction whose identifier matches the intrinsic IOR; done means the reproducer compiles and runs, printing pass without the incorrect type error.

Written by the indexing model from the issue text.

Assessment

Tech stack
fortran
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.