| Issue |
204240
|
| Summary |
[flang][OpenMP] Implement the ERROR directive
|
| Labels |
flang
|
| Assignees |
cenewcombe
|
| Reporter |
cenewcombe
|
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);
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs