[flang-commits] [flang] [flang][OpenMP] Support omx/ompx extension sentinels (PR #218475)
Krzysztof Parzyszek via flang-commits
flang-commits at lists.llvm.org
Wed Aug 26 11:51:45 PDT 2026
================
@@ -2833,7 +2849,23 @@ static constexpr llvm::omp::DirectiveSet GetAllDirectives() {
TYPE_PARSER(construct<OpenMPMisplacedEndDirective>(
OmpEndDirectiveParser{GetAllDirectives()}))
-TYPE_PARSER(startOmpLine >>
- sourced(construct<OpenMPInvalidDirective>(
- maybe("BEGIN"_sptok) >> !OmpDirectiveNameParser{} >> SkipTo<'\n'>{})))
+// A string following an OpenMP sentinel that is not a recognized directive.
+// When it follows an implementation-defined extension sentinel (!$omx / !$ompx)
+// the node is flagged (true) so that semantics ignores it with a warning rather
+// than reporting an error, allowing portable use of vendor extensions
+// (OpenMP 5.2, section 3.1).
+//
+// This is a fallback that is attempted before the enclosing program unit is
+// reparsed as an execution-part construct, so the standard "!$omp" branch uses
+// the strict "_id" spelling: it must not prefix-match the "!$omp" that begins
+// "!$ompx" line, otherwise a valid extension directive such as "!$ompx barrier"
+// would be misreported as an invalid "!$omp" directive instead of being handled
+// as a real construct.
+TYPE_PARSER(skipStuffBeforeStatement >>
+ ((ompxSentinel >>
+ sourced(construct<OpenMPInvalidDirective>(maybe("BEGIN"_sptok) >>
+ !OmpDirectiveNameParser{} >> SkipTo<'\n'>{} >> pure(true)))) ||
+ ("!$OMP"_id >>
+ sourced(construct<OpenMPInvalidDirective>(maybe("BEGIN"_sptok) >>
+ !OmpDirectiveNameParser{} >> SkipTo<'\n'>{} >> pure(false))))))
----------------
kparzysz wrote:
```suggestion
static constexpr auto skipUnrecognized{
maybe("BEGIN"_sptok) >> !OmpDirectiveNameParser{} >> SkipTo<'\n'>{}};
static constexpr auto unrecognizedExtension{ompxSentinel >>
construct<OpenMPInvalidDirective>(skipUnrecognized >> pure(true))};
static constexpr auto invalidDirective{"!$OMP"_id >>
construct<OpenMPInvalidDirective>(skipUnrecognized >> pure(false))};
TYPE_PARSER(sourced(
skipStuffBeforeStatement >> (unrecognizedExtension || invalidDirective)))
```
https://github.com/llvm/llvm-project/pull/218475
More information about the flang-commits
mailing list