llvm / llvm/llvm-project

[flang][OpenMP] Selecting an assume variant from a metadirective hits llvm_unreachable in clause lowering

Open
#212,437 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

Flang aborts when a `metadirective` selects an `assume` variant carrying a `holds` clause. The direct spelling lowers fine.

```fortran
subroutine sel_assume(n)
integer :: n
!$omp metadirective when(implementation={vendor(llvm)}: assume holds(n>0)) otherwise(nothing)
print *, n
end subroutine
```

```
$ flang -fopenmp -fopenmp-version=52 -c repro.f90
Unimplemented: holds
UNREACHABLE executed at flang/lib/Lower/OpenMP/Clauses.cpp:1033!
```

Backtrace elided. The frame is reached from `Fortran::lower::omp::makeClause`.

Control, which emits exactly one `llvm.intr.assume`:

```fortran
subroutine plain_assume(n)
integer :: n
!$omp assume holds(n>0)
print *, n
!$omp end assume
end subroutine
```

`genOMP` for `OmpAssumeDirective` reads `holds` from the parse tree and creates `mlir::LLVM::AssumeOp`. Variant lowering instead routes every clause through `make()` in `flang/lib/Lower/OpenMP/Clauses.cpp`, where the `Holds` overload is `llvm_unreachable("Unimplemented: holds")`. Search for that function rather than the line number, which comes from my tree.

- Reproduces at `-fopenmp-version=52` with `otherwise(nothing)` and at `51` with `default(nothing)`, in both the standalone and `begin`/`end` spellings.
- The variant must win selection. A losing `assume` variant compiles.
- `-fsyntax-only` accepts the source, so only lowering fails.
- My builds have assertions enabled. Under `LLVM_UNREACHABLE_OPTIMIZE` a release build is undefined here instead and prints nothing. Untested.

Either the variant should lower like the direct spelling, or a diagnostic should reject it. An unreachable is not an appropriate failure mode for valid input.

Not a recent regression. The `llvm_unreachable` dates to 6d688601 in August 2024, and the abort reproduces on three builds carrying different unrelated local patches, none of which touches that file.

Contributor guide

Open the contributing guide

Research direction

Start in flang/lib/Lower/OpenMP/Clauses.cpp by searching for the Holds overload in makeClause, then compare it with genOMP handling for OmpAssumeDirective. Compile the reproducer with flang -fopenmp -fopenmp-version=52 and check both metadirective spellings. Done means valid selected assume variants no longer reach llvm_unreachable and either lower consistently with direct assume or produce a diagnostic.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.