[Flang][OpenMP] Compilation error of declare reduction directives containing initializer with a shorter character
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_reductionDirective
- 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_reductiondirective, no otherdeclare_reductiondirective with the same type, the same kind parameters and the same reduction identifier is allowed in the same scope.
Reproducer
- test.f90
!$omp declare reduction (a:character(3):omp_out=omp_in) initializer(omp_priv='0')
print *,'pass'
end
- commands
$ 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>>' / '!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
$ 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
$ 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
@yus3710-fj this seems fixed in the current main. Could you please re-check? Thanks!
@ceseo Thank you for looking into this. As you mentioned, this issue has already been fixed.
$ flang --version
flang version 24.0.0git (https://github.com/llvm/llvm-project.git 9b45aa13c3001e8e7dc981c7dbdc9a98d1bb12e0)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/llvm/build/bin
Build config: +assertions
$ flang test.f90 -fopenmp && ./a.out
pass