27 Commits

Author SHA1 Message Date
Krzysztof Parzyszek
a73bdba2e8
[flang][OpenMP] Update semantic checks for LINEAR clause (#177055)
Fixes https://github.com/llvm/llvm-project/issues/173980.

In particular, make step-simple-modifier be compatible (i.e. not
exclusive) for OpenMP spec versions < 52, and update the modifier
validity checks for the construct on which the clause is located.
2026-01-27 08:35:26 -06:00
Krzysztof Parzyszek
c37c1f77f0
[flang][OpenMP] Move check for ORDERED to check-omp-loop.cpp, NFC (#177054) 2026-01-21 06:40:37 -06:00
Krzysztof Parzyszek
d542fac6b1
[flang] Add traits to more AST nodes (#175578)
Follow-up to PR175211.

There are still a few AST nodes that don't have any of the standard
traits (Wrapper/Tuple/etc). Because of that they require special
handling in the parse tree visitor.

Convert a subset of these nodes to the typical format, and remove the
special cases from the parse tree visitor.

The members of these nodes were frequently used, so instead of
extracting them by hand each time use helper member functions to access
them.
2026-01-20 09:57:35 -06:00
Krish Gupta
804c0345f5
[flang][OpenMP] Fix LINEAR clause validation to report all errors (#175938)
Fixes #175688 

After #175383 was merged, test failures occurred because removing the
early return exposed additional errors that tests weren't expecting.

This PR comprehensively fixes the issue by:

1. **Removes the early return** in check-omp-loop.cpp (line 767) after
detecting a modifier error on DO/SIMD directives. Previously, when a
modifier error was found, the function would return immediately without
checking other restrictions like the scalar requirement. Now all
applicable errors are reported, improving diagnostics.

2. **Updates linear-clause01.f90** to expect both the modifier error AND
the scalar error for Case 1 and Case 2, where arrays are used
incorrectly in LINEAR clauses.

3. **Updates clause-validity01.f90** to use the new OpenMP 5.2 syntax
(`linear(b: val)` instead of `linear(val(b))`). The old syntax triggers
deprecation warnings, which are now caught because we no longer return
early after the modifier error.

Thanks to @ergawy for identifying the clause-validity01.f90 fix needed.

The changes ensure better error reporting for users - they now see all
issues with their LINEAR clauses instead of just the first error.
2026-01-14 12:02:43 -05:00
Muhammad Omair Javaid
f4e74b6e4e Revert "[flang][OpenMP] Fix LINEAR clause validation and test expectations (#175707)"
This reverts commit 6e62d40b7c65a67ac0e5c6e0f462ce2663db98b9.

The change causes test failures clause-validity01.f90 on multiple
builders (links below):

https://lab.llvm.org/buildbot/#/builders/207/builds/12198
https://lab.llvm.org/buildbot/#/builders/140/builds/36994
https://lab.llvm.org/buildbot/#/builders/50/builds/19637
https://lab.llvm.org/buildbot/#/builders/172/builds/18946
https://lab.llvm.org/buildbot/#/builders/29/builds/20278
https://lab.llvm.org/buildbot/#/builders/80/builds/19622
2026-01-14 14:20:34 +05:00
Krish Gupta
6e62d40b7c
[flang][OpenMP] Fix LINEAR clause validation and test expectations (#175707)
Fixes #175688

After #175383 was merged, the test
`Semantics/OpenMP/linear-clause01.f90` was failing because it had an
early return that prevented multiple errors from being reported.

This PR fixes two issues:

1. **Removes the early return** after detecting a modifier error on
DO/SIMD directives. Previously, when a modifier error was found, the
function would return immediately without checking other restrictions
like the scalar requirement. Now all applicable errors are reported.

2. **Updates test expectations** to expect both the modifier error AND
the scalar error for Case 1, where `arg(:)` is an array used with `uval`
modifier on a DO directive.

Thanks to @NimishMishra for catching this during review - arrays should
always be rejected in LINEAR clauses (except for `declare simd` with
`ref` modifier), regardless of whether there are other errors.
2026-01-13 20:17:00 -08:00
Krish Gupta
b76c84e70f
[flang][OpenMP] Fix crash when arrays used in LINEAR clause (#175383)
Closes #171007

Found this crash while testing OpenMP code - turns out putting an array
in a LINEAR clause on SIMD directives causes the compiler to blow up
with "unknown LLVM dialect type" and hit an UNREACHABLE.

The issue is that LINEAR clauses only accept scalar variables (rank 0),
but we weren't checking for that early enough. The invalid array type
would slip through semantic analysis and then crash during MLIR to LLVM
IR translation when it tried to convert the type.

**What changed:**
- Added a rank check in the LINEAR clause validation to catch arrays up
front
- Made an exception for `declare simd` with the REF modifier since
that's actually allowed per spec
- Added tests covering different array types (1D, multi-dim,
assumed-shape)
- Updated existing tests that now catch the new error

Tested with the original reproducer and it now fails cleanly with a
proper error message instead of crashing.
2026-01-12 14:25:55 -06:00
Krzysztof Parzyszek
aa7a95c8e9
[flang][OpenMP] Make function name more accurate, NFC (#172328)
Change `CountGeneratedLoops` to `CountGeneratedNests`, since it's really
the nests that are counted.
2025-12-16 07:30:06 -06:00
Krzysztof Parzyszek
6e01ea4bab
[flang][OpenMP] Generalize checks of loop construct structure (#170735)
For an OpenMP loop construct, count how many loops will effectively be
contained in its associated block. For constructs that are loop-nest
associated this number should be 1. Report cases where this number is
different.

Take into account that the block associated with a loop construct can
contain compiler directives.
2025-12-15 07:20:05 -06:00
Krzysztof Parzyszek
cc25ac424a
[flang][OpenMP] Use DirId() instead of DirName().v, NFC (#171484) 2025-12-09 12:45:45 -06:00
Krzysztof Parzyszek
03c37160a1
[flang][OpenMP] Reject END DO on construct that crosses label-DO (#169714)
In a label-DO construct where two or more loops share the same
teminator, an OpenMP construct must enclose all the loops if an
end-directive is present. E.g.

```
  do 100 i = 1,10
!$omp do
    do 100 j = 1,10
    100 continue
!$omp end do    ! Error, but ok if this line is removed
```

Fixes https://github.com/llvm/llvm-project/issues/169536.
2025-12-05 14:01:24 -06:00
Krzysztof Parzyszek
e73b8036f8
[flang][OpenMP] Extract check into separate function, NFC (#170728) 2025-12-04 14:01:28 -06:00
Krzysztof Parzyszek
04bc0af103
[flang][OpenMP] Expand GetOmpObjectList to all subclasses of OmpClause (#170351)
Use GetOmpObjectList instead of extracting the object list by hand.
2025-12-04 07:37:13 -06:00
Krzysztof Parzyszek
7c33b8247d
[flang][OpenMP] Move two functions to check-omp-loop.cpp, NFC (#170526)
These are checks for clauses that apply to loop constructs.
2025-12-03 12:30:53 -06:00
Pranav Bhandarkar
28fde68501
[Flang] - Enhance testing for strictly-nested teams in target regions. (#168437)
This patch enhances the semantics test for checking that teams
directives are strictly nested inside target directives.

Fixes https://github.com/llvm/llvm-project/issues/153173
2025-11-24 23:36:41 -06:00
Krzysztof Parzyszek
9cff3f51d3
[flang][OpenMP] Tolerate compiler directives in loop constructs (#169346)
PR168884 flagged compiler directives (!dir$ ...) inside OpenMP loop
constructs as errors. This caused some customer applications to fail to
compile (issue 169229).

Downgrade the error to a warning, and gracefully ignore compiler
directives when lowering loop constructs to MLIR.

Fixes https://github.com/llvm/llvm-project/issues/169229
2025-11-24 16:48:27 -06:00
Krzysztof Parzyszek
c2d659b9b8
[flang][OpenMP] Implement loop nest parser (#168884)
Previously, loop constructs were parsed in a piece-wise manner: the
begin directive, the body, and the end directive were parsed separately.
Later on in canonicalization they were all coalesced into a loop
construct. To facilitate that end-loop directives were given a special
treatment, namely they were parsed as OpenMP constructs. As a result
syntax errors caused by misplaced end-loop directives were handled
differently from those cause by misplaced non-loop end directives.

The new loop nest parser constructs the complete loop construct,
removing the need for the canonicalization step. Additionally, it is the
basis for parsing loop-sequence-associated constructs in the future.

It also removes the need for the special treatment of end-loop
directives. While this patch temporarily degrades the error messaging
for misplaced end-loop directives, it enables uniform handling of any
misplaced end-directives in the future.
2025-11-22 12:28:58 -06:00
Ferran Toda
f4ebee0ca9
[Flang][OpenMP] Add semantic support for Loop Sequences and OpenMP loop fuse (#161213)
This patch adds semantics for the `omp fuse` directive in flang, as
specified in OpenMP 6.0. This patch also enables semantic support for
loop sequences which are needed for the fuse directive along with
semantics for the `looprange` clause. These changes are only semantic.
Relevant tests have been added , and previous behavior is retained with
no changes.

---------

Co-authored-by: Ferran Toda <ferran.todacasaban@bsc.es>
Co-authored-by: Krzysztof Parzyszek <Krzysztof.Parzyszek@amd.com>
2025-11-21 08:16:30 -06:00
Krzysztof Parzyszek
e70e9ec3b8
[flang][OpenMP] Store Block in OpenMPLoopConstruct, add access functions (#168078)
Instead of storing a variant with specific types, store parser::Block as
the body. Add two access functions to make the traversal of the nest
simpler.

This will allow storing loop-nest sequences in the future.
2025-11-17 08:02:36 -06:00
Peter Klausler
5cd9f0f655
[flang] Move parse tree tool to Parser/tools.h (#163998)
Move the parse tree utility function
semantics::getDesignatorNameIfDataRef to Parser/tools.h and rename it to
comply with the local style.
2025-10-20 13:20:33 -07:00
CHANDRA GHALE
6dda3b1848
[flang][OpenMP]: Allow orphaned distribute construct (#163546)
If there is a call inside a TEAMS construct, and that call contains a
DISTRIBUTE construct, the DISTRIBUTE region is considered to be enclosed
by the TEAMS region (based on the dynamic extent of the construct).
Currently, Flang diagnoses this as an error, which is incorrect.
For eg :
```
 subroutine f
  !$omp distribute
  do i = 1, 100
    ...
  end do
end subroutine

subroutine g
  !$omp teams
  call f ! this call is ok, distribute enclosed by teams
  !$omp end teams
end subroutine
```
This patch adjusts the nesting check for the OpenMP DISTRIBUTE
directive. It retains the error for DISTRIBUTE directives that are
incorrectly nested lexically but downgrades it to a warning for orphaned
directives to allow dynamic nesting, such as when a subroutine with
DISTRIBUTE is called from within a TEAMS region.

Co-authored-by: Chandra Ghale <ghale@pe31.hpc.amslabs.hpecorp.net>
2025-10-20 20:10:22 +05:30
Krzysztof Parzyszek
d89de09cb1
[flang][OpenMP] Reject blank common blocks more gracefully (#159626)
Parse them as "invalid" OmpObjects, then emit a diagnostic in semantic
checks.
2025-09-22 09:56:31 -05:00
Krzysztof Parzyszek
e75e28ad3c
[flang][OpenMP] Use OmpDirectiveSpecification in Omp[Begin|End]LoopDi… (#159087)
…rective

This makes accessing directive components, such as directive name or the
list of clauses simpler and more uniform across different directives. It
also makes the parser simpler, since it reuses existing parsing
functionality.

The changes are scattered over a number of files, but they all share the
same nature:
- getting the begin/end directive from OpenMPLoopConstruct,
- getting the llvm::omp::Directive enum, and the source location,
- getting the clause list.
2025-09-16 11:38:03 -05:00
Krzysztof Parzyszek
88b71e2048
[flang][OpenMP] Replace OpenMPBlockConstruct with OmpBlockConstruct (#155872)
OpenMPBlockConstruct, somewhat confusingly, represents most but not all
block-associated constructs. It's derived from OmpBlockConstruct, as are
all the remaining block-associated constructs.

It does not correspond to any well-defined group of constructs. It's the
collection of constructs that don't have their own types (and those that
do have their own types do so for their own reasons).

Using the broader OmpBlockConstruct in type-based visitors won't cause
issues, because the specific overloads (for classes derived from it)
will always be preferred.
2025-08-29 07:37:48 -05:00
Krzysztof Parzyszek
e368b5343d
[flang][OpenMP] Make OpenMPCriticalConstruct follow block structure (#152007)
This allows not having the END CRITICAL directive in certain situations.
Update semantic checks and symbol resolution.
2025-08-07 08:10:25 -05:00
Krzysztof Parzyszek
6533ad04ed
[flang][OpenMP] Make all block constructs share the same structure (#150956)
The structure is
- OmpBeginDirective (aka OmpDirectiveSpecification)
- Block
- optional<OmpEndDirective> (aka optional<OmpDirectiveSpecification>)

The OmpBeginDirective and OmpEndDirective are effectively different
names for OmpDirectiveSpecification. They exist to allow the semantic
analyses to distinguish between the beginning and the ending of a block
construct without maintaining additional context.

The actual changes are in the parser: parse-tree.h and openmp-parser.cpp
in particular. The rest is simply changing the way the directive/clause
information is accessed (typically for the simpler).

All standalone and block constructs now use OmpDirectiveSpecification to
store the directive/clause information.
2025-08-01 07:52:59 -05:00
Krzysztof Parzyszek
ba116a8bed
[flang][OpenMP] Split check-omp-structure.cpp into smaller files, NFC (#146359)
Create these new files in flang/lib/Semantics:
  openmp-utils.cpp/.h         - Common utilities
  check-omp-atomic.cpp        - Atomic-related checks
  check-omp-loop.cpp          - Loop constructs/clauses
  check-omp-metadirective.cpp - Metadirective-related checks

Update lists of included headers, std in particular.

---------

Co-authored-by: Jack Styles <jack.styles@arm.com>
2025-07-01 11:12:00 -05:00