llvm / llvm/llvm-project

[flang][OpenMP] Implement the ERROR directive

Open
#204,240 3 comments 0 reactions 1 assignee Claimed by @cenewcombe View on GitHub
flang:frontend flang:ir flang:openmp
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The OpenMP `error` directive is currently parsed and has basic semantic validation, but the actual diagnostic behavior is not implemented. This feature was introduced in OpenMP 5.1 and is described in Section 10.1 of the OpenMP 6.0 specification.

## Spec Summary

The `error` directive causes the compiler to emit a diagnostic:

- **`AT(compilation)`** (default): emit a compile-time diagnostic
- **`AT(execution)`**: emit a runtime diagnostic via `__kmpc_error`
- **`SEVERITY(fatal)`** (default): the diagnostic is an error (compilation fails / runtime abort)
- **`SEVERITY(warning)`**: the diagnostic is a warning (compilation continues / runtime continues)
- **`MESSAGE("text")`** (optional): user-provided diagnostic text

## Current State

| Stage | Status |
|-------|--------|
| Parsing | Done |
| Parse tree / Unparse | Done |
| Semantics | Partial — validates clause structure and rejects `AT(EXECUTION)` in specification parts, but does **not** emit the user-facing compile-time error/warning for `AT(compilation)` |
| Lowering | Not done — hits `TODO("OmpErrorDirective")` |

Existing tests:
- `flang/test/Parser/OpenMP/error-unparse.f90` — parsing round-trip
- `flang/test/Semantics/OpenMP/error.f90` — rejects `AT(EXECUTION)` in spec-part
- `flang/test/Lower/OpenMP/Todo/error.f90` — confirms the TODO fires

## Work Needed

### 1. Semantics: handle `AT(compilation)`

In `OmpStructureChecker::Leave(OmpErrorDirective)`, extract the `AT`, `SEVERITY`, and `MESSAGE` clause values from the directive and emit the appropriate diagnostic:
- `SEVERITY(fatal)` → compile-time error (compilation should fail)
- `SEVERITY(warning)` → compile-time warning (compilation continues)
- Use the `MESSAGE` string as the diagnostic text, or a default if omitted

The `AT(compilation)` case should be fully resolved at semantic analysis time and should not reach lowering.

### 2. Lowering: handle `AT(execution)`

Replace the `TODO` in `genOMP(..., OmpUtilityDirective)` with code that generates a call to the OpenMP runtime function:

```c
void __kmpc_error(ident_t *loc, int severity, const char *message);

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.