[Flang][OpenMP] Compilation error for UDR with allocatable/pointer/array variables
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
## Summary
Flang fails to generate LLVM IR when a User-Defined Reduction (UDR) is applied to allocatable or pointer variables.
### Reproducer
* test.f90
```fortran
program main
implicit none
!$omp declare reduction (a : integer : omp_out = omp_out+ omp_in + 1) &
!$omp initializer(omp_priv = 1)
integer, pointer :: k
integer, target :: t
integer :: i
k => t
k = 0
!$omp parallel do reduction(a : k)
do i = 1, 10
k = k + 1
end do
!$omp end parallel do
print *, 'ok'
end
```
* test2.f90
```fortran
program main
implicit none
!$omp declare reduction (a : integer : omp_out = omp_out+ omp_in + 1) &
!$omp initializer(omp_priv = 1)
integer, allocatable :: k
integer :: i
allocate(k)
k = 0
!$omp parallel do reduction(a : k)
do i = 1, 10
k = k + 1
end do
!$omp end parallel do
print *, 'ok'
end
```
* commands
```console
$ flang --version
flang version 23.0.0git (https://github.com/llvm/llvm-project.git abc37e6aef740b0af087331e6db807b916f559f5)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/llvm/build/bin
Build config: +assertions
$ flang test.f90 -fopenmp && ./a.out
Attribute 'align 8' applied to incompatible type!
call void @llvm.memcpy.p0.i32.i32(ptr align 8 %3, i32 align 8 1, i32 24, i1 false)
Intrinsic has incorrect argument type!
ptr @llvm.memcpy.p0.i32.i32
error: failed to create the LLVM module
$ flang test2.f90 -fopenmp && ./a.out
Attribute 'align 8' applied to incompatible type!
call void @llvm.memcpy.p0.i32.i32(ptr align 8 %4, i32 align 8 1, i32 24, i1 false)
Intrinsic has incorrect argument type!
ptr @llvm.memcpy.p0.i32.i32
Intrinsic has incorrect argument type!
ptr @llvm.memcpy.i32.p0.i32
error: failed to create the LLVM module
```
## Non-problematic Conditions
The issue does not occur under the following conditions:
* Using intrinsic operators (e.g., `+`) as reduction identifiers.
## 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:10:33:
10 | !$omp parallel do reduction(a : k)
| 1
Error: POINTER object 'k' in REDUCTION clause at (1)
$ gfortran test2.f90 -fopenmp && ./a.out
ok
```
* 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
ok
$ ifx -O0 test2.f90 -qopenmp && ./a.out
ok
```
Contributor guide
Research direction
Start by compiling test.f90 and test2.f90 with flang -fopenmp and inspect the generated LLVM IR and reported verification errors. Trace the Flang OpenMP user-defined reduction path involved for allocatable and pointer variables; done means both reproducers generate valid LLVM IR and complete as expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fortran
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100