llvm / llvm/llvm-project

[Flang][OpenMP] Compilation error for lastprivate procedure pointers in sections constructs

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

Description

## Summary

When a lastprivate clause is used with a sections construct and a procedure pointer is specified in the clause list, compilation fails. I did not find any restrictions on using procedure pointers with the lastprivate clause.

### Reproducer

* test.f90

```fortran
subroutine prc02(i)
integer,intent(inout) :: i
end

program main
interface
subroutine prc02(i)
integer,intent(inout) :: i
end subroutine prc02
end interface
procedure(prc02), pointer :: ptr2
ptr2=>null()
call sub1(ptr2)
print *,'pass'
contains
subroutine sub1(p2)
procedure(prc02),pointer :: p2
integer :: a
a=1
!$omp sections lastprivate(p2)
p2=>prc02
!$omp end sections
call p2(a)
end subroutine sub1
end
```

* commands

```console
$ flang --version
flang version 23.0.0git (https://github.com/llvm/llvm-project.git 578ba5f3039e7a1e4e6f3a82891b3838823e37c2)
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":17:33): 'fir.store' op store value type must match memory reference type
error: verification of lowering to FIR failed
```

## Non-problematic Conditions

The issue does not occur under the following conditions:
* Disabling OpenMP.

## 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

Open the contributing guide

Research direction

Start by compiling the issue's test.f90 reproducer with flang -fopenmp and compare the failing FIR verification with the successful non-OpenMP cases. Trace lowering for the sections construct and its lastprivate procedure pointer; done means the reproducer compiles and runs, printing pass, without the FIR type-mismatch error.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.