[Flang][OpenMP] Compilation error of declare reduction directives containing initializer with a shorter character
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
## Summary
When the character length of an `initializer-expr` in an OpenMP declare reduction directive is shorter than that of the declared type, compilation fails.
According to the OpenMP 6.0 specification, there are specific restrictions on declare reduction directives. However, I did not find any explicit restriction concerning the character length of an `initializer-expr` relative to its declared type.
* 7.6.14 `declare_reduction` Directive
> * If the length type parameter is specified for a type, it must be a constant, a colon (:) or an asterisk (*).
> * If a type with a deferred or assumed length parameter is specified in a `declare_reduction` directive, no other `declare_reduction` directive with the same type, the same kind parameters and the same reduction identifier is allowed in the same scope.
### Reproducer
* test.f90
```fortran
!$omp declare reduction (a:character(3):omp_out=omp_in) initializer(omp_priv='0')
print *,'pass'
end
```
* commands
```console
$ flang --version
flang version 23.0.0git (https://github.com/llvm/llvm-project.git 58208a0cc165c23d2fad4ed46950b342156875ac)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/llvm/build/bin
Build config: +assertions
$ flang test.f90 -fopenmp && ./a.out
error: loc("/path/to/test.f90":1:7): 'fir.convert' op invalid type conversion'!fir.ref>' / '!fir.char<1,3>'
error: verification of lowering to FIR failed
```
## Non-problematic Conditions
The issue does not occur under the following conditions:
* Replacing `'0'` with `'0 '` (i.e., padding with spaces to match the declared length of characters).
## 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
pass
```
* 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
```
Contributor guide
Assessment
This issue has not been assessed yet.