diff --git a/flang/include/flang/Parser/openmp-utils.h b/flang/include/flang/Parser/openmp-utils.h index d97a0ca8e2a7e..2e4fa4093b87c 100644 --- a/flang/include/flang/Parser/openmp-utils.h +++ b/flang/include/flang/Parser/openmp-utils.h @@ -39,7 +39,6 @@ struct ConstructId { } MAKE_CONSTR_ID(OmpDeclareVariantDirective, D::OMPD_declare_variant); -MAKE_CONSTR_ID(OmpErrorDirective, D::OMPD_error); MAKE_CONSTR_ID(OpenMPDeclarativeAllocate, D::OMPD_allocate); MAKE_CONSTR_ID(OpenMPDeclarativeAssumes, D::OMPD_assumes); MAKE_CONSTR_ID(OpenMPDeclareMapperConstruct, D::OMPD_declare_mapper); @@ -60,10 +59,6 @@ struct DirectiveNameScope { return name; } - static OmpDirectiveName GetOmpDirectiveName(const OmpNothingDirective &x) { - return MakeName(x.source, llvm::omp::Directive::OMPD_nothing); - } - static OmpDirectiveName GetOmpDirectiveName(const OmpBeginLoopDirective &x) { return x.DirName(); } @@ -99,7 +94,6 @@ struct DirectiveNameScope { if constexpr (std::is_base_of_v) { return std::get(x.t).DirName(); } else if constexpr (std::is_same_v || - std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v || diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index adb176c2828d6..7968f5e43fe50 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -4843,17 +4843,13 @@ struct OmpMetadirectiveDirective { // nothing-directive -> // NOTHING // since 5.1 struct OmpNothingDirective { - using EmptyTrait = std::true_type; - COPY_AND_ASSIGN_BOILERPLATE(OmpNothingDirective); - CharBlock source; + WRAPPER_CLASS_BOILERPLATE(OmpNothingDirective, OmpDirectiveSpecification); }; // Ref: OpenMP [5.2:216-218] // ERROR AT(compilation|execution) SEVERITY(fatal|warning) MESSAGE("msg-str) struct OmpErrorDirective { - TUPLE_CLASS_BOILERPLATE(OmpErrorDirective); - CharBlock source; - std::tuple t; + WRAPPER_CLASS_BOILERPLATE(OmpErrorDirective, OmpDirectiveSpecification); }; struct OpenMPUtilityConstruct { diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index a7229c80eafab..9b4bef49109fc 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -1279,9 +1279,6 @@ TYPE_PARSER(sourced(construct( // 2.1 (variable | /common-block/ | array-sections) TYPE_PARSER(construct(nonemptyList(Parser{}))) -TYPE_PARSER(sourced(construct( - verbatim("ERROR"_tok), Parser{}))) - // --- Parsers for directives and constructs -------------------------- static inline constexpr auto IsDirective(llvm::omp::Directive dir) { @@ -1368,13 +1365,19 @@ struct LooselyStructuredBlockParser { } }; -TYPE_PARSER(sourced(construct("NOTHING" >> ok))) +TYPE_PARSER(construct( + predicated(Parser{}, + IsDirective(llvm::omp::Directive::OMPD_error)) >= + Parser{})) -TYPE_PARSER(sourced(construct( - sourced(construct( - sourced(Parser{}))) || - sourced(construct( - sourced(Parser{})))))) +TYPE_PARSER(construct( + predicated(Parser{}, + IsDirective(llvm::omp::Directive::OMPD_nothing)) >= + Parser{})) + +TYPE_PARSER( // + sourced(construct(Parser{})) || + sourced(construct(Parser{}))) TYPE_PARSER(construct( predicated(Parser{}, diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp index 30a2ab5db968b..c083bd073bead 100644 --- a/flang/lib/Parser/unparse.cpp +++ b/flang/lib/Parser/unparse.cpp @@ -2621,13 +2621,18 @@ class UnparseVisitor { return false; } void Unparse(const OmpErrorDirective &x) { - Word("!$OMP ERROR "); - Walk(x.t); + BeginOpenMP(); + Word("!$OMP "); + Walk(x.v); Put("\n"); + EndOpenMP(); } void Unparse(const OmpNothingDirective &x) { - Word("!$OMP NOTHING"); + BeginOpenMP(); + Word("!$OMP "); + Walk(x.v); Put("\n"); + EndOpenMP(); } void Unparse(const OpenMPSectionConstruct &x) { if (auto &&dirSpec{ diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp index 1efb2ca5b6389..ac603d8546237 100644 --- a/flang/lib/Semantics/check-omp-structure.cpp +++ b/flang/lib/Semantics/check-omp-structure.cpp @@ -611,14 +611,6 @@ template struct DirectiveSpellingVisitor { checker_(GetDirName(x.t).source, Directive::OMPD_dispatch); return false; } - bool Pre(const parser::OmpErrorDirective &x) { - checker_(std::get(x.t).source, Directive::OMPD_error); - return false; - } - bool Pre(const parser::OmpNothingDirective &x) { - checker_(x.source, Directive::OMPD_nothing); - return false; - } bool Pre(const parser::OpenMPExecutableAllocate &x) { checker_(std::get(x.t).source, Directive::OMPD_allocate); return false; @@ -1761,8 +1753,17 @@ void OmpStructureChecker::Leave(const parser::OpenMPDeclareTargetConstruct &x) { } void OmpStructureChecker::Enter(const parser::OmpErrorDirective &x) { - const auto &dir{std::get(x.t)}; - PushContextAndClauseSets(dir.source, llvm::omp::Directive::OMPD_error); + const parser::OmpDirectiveName &dirName{x.v.DirName()}; + PushContextAndClauseSets(dirName.source, dirName.v); +} + +void OmpStructureChecker::Enter(const parser::OmpNothingDirective &x) { + const parser::OmpDirectiveName &dirName{x.v.DirName()}; + PushContextAndClauseSets(dirName.source, dirName.v); +} + +void OmpStructureChecker::Leave(const parser::OmpNothingDirective &x) { + dirContext_.pop_back(); } void OmpStructureChecker::Enter(const parser::OpenMPDispatchConstruct &x) { diff --git a/flang/lib/Semantics/check-omp-structure.h b/flang/lib/Semantics/check-omp-structure.h index 6de69e1a8e4f1..7c76cf610a1af 100644 --- a/flang/lib/Semantics/check-omp-structure.h +++ b/flang/lib/Semantics/check-omp-structure.h @@ -120,6 +120,8 @@ class OmpStructureChecker void Leave(const parser::OpenMPDispatchConstruct &); void Enter(const parser::OmpErrorDirective &); void Leave(const parser::OmpErrorDirective &); + void Enter(const parser::OmpNothingDirective &); + void Leave(const parser::OmpNothingDirective &); void Enter(const parser::OpenMPExecutableAllocate &); void Leave(const parser::OpenMPExecutableAllocate &); void Enter(const parser::OpenMPAllocatorsConstruct &);