[Flang][OpenMP] DEFAULT(NONE) diagnostic points at nested directive instead of variable reference
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
## Description
When a variable that violates `DEFAULT(NONE)` is referenced inside a nested
OpenMP construct, Flang reports the error on the nested directive rather than
on the offending variable reference.
This reproducer contains no loops, so the behavior is independent of
predetermined loop-variable handling.
## Reproducer
```fortran
program default_none_diagnostic_location
implicit none
integer :: value
!$omp parallel default(none)
!$omp critical
print *, value
!$omp end critical
!$omp end parallel
end program default_none_diagnostic_location
```
## Command
```console
$ flang-new -fopenmp -fopenmp-version=50 -fsyntax-only repro.f90
```
## Actual behavior
Flang emits one error, but points to the `critical` directive:
```text
repro.f90:6:9: error: The DEFAULT(NONE) clause requires that 'value' must be listed in a data-sharing attribute clause
!$omp critical
^^^^^^^^
```
## Desired behavior
Flang should still emit exactly one `DEFAULT(NONE)` error, but it should point
to the offending `value` reference on line 7:
```text
print *, value
^^^^^
```
Pointing to the variable reference makes it clear which use requires an
explicit data-sharing attribute. The `critical` directive itself is not the
source of the violation.
## Version
Reproduced with LLVM commit:
```text
af2ddf42e4499169f8d96d1ff928f3d92bbcc9a2
```
The behavior also persists after unrelated changes to predetermined
loop-variable handling.
## Possible cause
`OmpAttributeVisitor::CreateImplicitSymbols()` uses
`dirContext.directiveSource` when a nested context already has a data-sharing
attribute:
```cpp
} else if (dsa.any() || crayPtrDSA.any()) {
defaultNoneError(dirContext.directiveSource, symbol);
} else if (dirDepth == (int)dirContext_.size() - 1) {
defaultNoneError(name.source, symbol);
}
```
Using `dirContext.directiveSource` causes the diagnostic to be attached to the
nested OpenMP directive. The original `name.source` contains the location of
the offending variable reference.
Contributor guide
Research direction
Start at OmpAttributeVisitor::CreateImplicitSymbols(), especially the DEFAULT(NONE) diagnostic branches described in the issue. Run flang-new with the supplied OpenMP reproducer and verify that the single error points to the value reference rather than the nested critical directive. Done means preserving one diagnostic while reporting the requested source location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fortran
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100