llvm / llvm/llvm-project

[Flang][OpenMP] DECLARE TARGET with INDIRECT clause aborts during lowering

Open
#206,900 0 comments 0 reactions 0 assignees View on GitHub
flang:openmp
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

## Description

Flang currently aborts while lowering an OpenMP `DECLARE TARGET` directive that uses the `INDIRECT` clause.

The failing directive is:

```fortran
!$omp declare target enter(func1) indirect(.true.)
```

This is used with a procedure pointer call inside an OpenMP target region:

```fortran
procedure (func), pointer :: ptr1 => func1
character(1) :: val1

!$omp target map(from: val1)
val1 = ptr1()
!$omp end target
```

Here, `ptr1()` indirectly calls `func1()`. Therefore, `func1` is marked with `declare target enter(func1) indirect(.true.)` so that it can be made available on the target device and called indirectly.

## Reproducer

```fortran
! This test checks the lowering of OpenMP Indirect Clause when used with the Declare Target directive

module functions
implicit none

interface
function func() result(i)
character(1) :: i
end function
end interface

contains
function func1() result(i)
!$omp declare target enter(func1) indirect(.true.)
character(1) :: i
i = 'a'
return
end function
end module

program main
use functions
implicit none
procedure (func), pointer :: ptr1=>func1
character(1) :: val1

!$omp target map(from: val1)
val1 = ptr1()
!$omp end target

end program
```

## Command

```bash
flang -fopenmp -fopenmp-version=52 omp-clause-indirect.f90
```

## Actual behavior

Flang emits a `not yet implemented` message and then aborts:

```text
warning: OpenMP support for version 52 in flang is still incomplete
error: ... ClauseProcessor.h:236: not yet implemented: Unhandled clause INDIRECT in DECLARE TARGET construct
LLVM ERROR: aborting
```

## Expected behavior

Flang should not abort.

Ideally, Flang should lower the `INDIRECT` clause on `DECLARE TARGET`

Contributor guide

Open the contributing guide

Research direction

Start by running the supplied Fortran reproducer with `flang -fopenmp -fopenmp-version=52 omp-clause-indirect.f90` and inspect the lowering path for `DECLARE TARGET` and its `INDIRECT` clause. Done means the compiler no longer aborts on this input and, ideally, lowers the clause as expected.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.