| Issue |
244081
|
| Summary |
[flang][OpenACC] ALLOCATABLE or POINTER do-variable in an OpenACC loop fails FIR verification
|
| Labels |
flang
|
| Assignees |
|
| Reporter |
eugeneepshteyn
|
An OpenACC loop whose do-variable is an ALLOCATABLE or POINTER scalar integer fails lowering. The program is conforming (F2023 C1121 only requires the do-variable to be a variable of type integer). The same loop lowers without errors when the do-variable is a plain `integer :: i`, or when the `!$acc` directive is removed.
```fortran
subroutine alloc_iv(a, n)
integer :: n
real :: a(n)
integer, allocatable :: i
allocate(i)
!$acc parallel loop
do i = 1, n
a(i) = 1.0
end do
end subroutine
```
```console
$ flang -fc1 -fopenacc -emit-hlfir alloc_iv.f90
error: loc("alloc_iv.f90":6:9): 'fir.store' op store value type must match memory reference type
error: verification of lowering to FIR failed
```
Reproduced at main 0aa8e13a94c7 (2026-11-18), and also before 240591. The same happens with `integer, pointer :: i`, and with an implicit loop (a plain `do` inside `!$acc kernels`). DO CONCURRENT with an allocatable index lowers without this error, because its index is a construct entity.
Two things go wrong in `flang/lib/Lower/OpenACC.cpp`:
- `getTypeFromIvTypeSize` builds the induction variable's type from `Symbol::size()`. For an allocatable or pointer, that is the size of the descriptor, 24 bytes (`-fdebug-dump-symbols` shows `i, ALLOCATABLE size=24 ... INTEGER(4)`). So the `acc.loop` induction variable becomes `i192`, and since 240591 every loop control is converted to `i192` as well. The type should come from the declared type of the do-variable.
- The induction variable is privatized and stored through the descriptor rather than through the integer it describes. With `-mmlir --mlir-print-ir-after-failure`, the failing operation is `"fir.store"(%arg2, %32#0) : (i192, !fir.ref<!fir.box<!fir.heap<i32>>>) -> ()`; the pointer case is the same with `!fir.box<!fir.ptr<i32>>`.
(This issue was filed with the help of AI)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs