From 65de6787e22918b9de900fa2cedc4f1a612ceb06 Mon Sep 17 00:00:00 2001 From: "Jinxin (Brian) Yang" Date: Mon, 12 Aug 2019 16:08:10 -0700 Subject: [PATCH] [flang] [OpenMP] parse tree changes for Critical Construct (flang-compiler/f18#641) Simple changes: add source provenance for directive itself and renaming Original-commit: flang-compiler/f18@9246d266b0b5854db4f1f8beaf47cac80fcf7f0d Reviewed-on: https://github.com/flang-compiler/f18/pull/641 --- flang/lib/parser/dump-parse-tree.h | 6 +++--- flang/lib/parser/openmp-grammar.h | 20 +++++++++---------- flang/lib/parser/parse-tree.h | 14 ++++++++----- flang/lib/parser/unparse.cc | 20 +++++++++---------- .../test/semantics/omp-clause-validity01.f90 | 8 ++++++++ 5 files changed, 39 insertions(+), 29 deletions(-) diff --git a/flang/lib/parser/dump-parse-tree.h b/flang/lib/parser/dump-parse-tree.h index ab3a55e0e2ba..2f9fe06f37fc 100644 --- a/flang/lib/parser/dump-parse-tree.h +++ b/flang/lib/parser/dump-parse-tree.h @@ -452,6 +452,8 @@ public: NODE(parser::OmpClause, Untied) NODE(parser::OmpClause, UseDevicePtr) NODE(parser::OmpClause, IsDevicePtr) + NODE(parser, OmpCriticalDirective) + NODE(parser::OmpCriticalDirective, Hint) NODE(parser, OmpDeclareTargetMapType) NODE_ENUM(parser::OmpDeclareTargetMapType, Type) NODE(parser, OmpDefaultClause) @@ -466,7 +468,7 @@ public: NODE(parser, OmpDependSinkVecLength) NODE(parser, OmpEndAtomic) NODE(parser, OmpEndBlockDirective) - NODE(parser, OmpEndCritical) + NODE(parser, OmpEndCriticalDirective) NODE(parser, OmpEndDo) NODE(parser, OmpEndDoSimd) NODE(parser, OmpEndParallelSections) @@ -517,8 +519,6 @@ public: NODE(parser, OpenMPCancellationPointConstruct) NODE(parser, OpenMPConstruct) NODE(parser, OpenMPCriticalConstruct) - NODE(parser, OpenMPCriticalConstructDirective) - NODE(parser::OpenMPCriticalConstructDirective, Hint) NODE(parser, OpenMPDeclarativeConstruct) NODE(parser, OpenMPDeclareReductionConstruct) NODE(parser, OpenMPDeclareSimdConstruct) diff --git a/flang/lib/parser/openmp-grammar.h b/flang/lib/parser/openmp-grammar.h index e1cf5f91877b..5f541b919f6a 100644 --- a/flang/lib/parser/openmp-grammar.h +++ b/flang/lib/parser/openmp-grammar.h @@ -444,18 +444,18 @@ TYPE_PARSER(construct(Parser{}) || construct(Parser{})) // OMP CRITICAL -TYPE_PARSER(startOmpLine >> "END CRITICAL"_tok >> - construct(maybe(parenthesized(name))) / endOmpLine) - -TYPE_PARSER( - sourced(construct( - "CRITICAL" >> maybe(parenthesized(name)), - maybe("HINT" >> construct( - parenthesized(constantExpr))))) / +TYPE_PARSER(startOmpLine >> + sourced(construct( + verbatim("END CRITICAL"_tok), maybe(parenthesized(name)))) / + endOmpLine) +TYPE_PARSER(sourced(construct(verbatim("CRITICAL"_tok), + maybe(parenthesized(name)), + maybe("HINT" >> construct( + parenthesized(constantExpr))))) / endOmpLine) + TYPE_PARSER(construct( - Parser{}, block, - Parser{})) + Parser{}, block, Parser{})) // Declare Simd construct TYPE_PARSER( diff --git a/flang/lib/parser/parse-tree.h b/flang/lib/parser/parse-tree.h index ccd4a4219ce2..4a2eaac02042 100644 --- a/flang/lib/parser/parse-tree.h +++ b/flang/lib/parser/parse-tree.h @@ -3556,16 +3556,20 @@ struct OpenMPDeclarativeConstruct { }; // CRITICAL [Name] END CRITICAL [Name] -WRAPPER_CLASS(OmpEndCritical, std::optional); -struct OpenMPCriticalConstructDirective { - TUPLE_CLASS_BOILERPLATE(OpenMPCriticalConstructDirective); +struct OmpCriticalDirective { + TUPLE_CLASS_BOILERPLATE(OmpCriticalDirective); WRAPPER_CLASS(Hint, ConstantExpr); CharBlock source; - std::tuple, std::optional> t; + std::tuple, std::optional> t; +}; +struct OmpEndCriticalDirective { + TUPLE_CLASS_BOILERPLATE(OmpEndCriticalDirective); + CharBlock source; + std::tuple> t; }; struct OpenMPCriticalConstruct { TUPLE_CLASS_BOILERPLATE(OpenMPCriticalConstruct); - std::tuple t; + std::tuple t; }; // END ATOMIC diff --git a/flang/lib/parser/unparse.cc b/flang/lib/parser/unparse.cc index 77388d26641e..ff4f286fdcb6 100644 --- a/flang/lib/parser/unparse.cc +++ b/flang/lib/parser/unparse.cc @@ -2166,29 +2166,27 @@ public: Walk(std::get>(x.t), "!$OMP END ATOMIC\n"); EndOpenMP(); } - void Unparse(const OmpEndCritical &x) { - Walk(" (", x.v, ")"); - EndOpenMP(); - } - void Unparse(const OpenMPCriticalConstructDirective &x) { + void Unparse(const OmpCriticalDirective &x) { BeginOpenMP(); Word("!$OMP CRITICAL"); Walk(" (", std::get>(x.t), ")"); - Walk(" HINT(", - std::get>(x.t), + Walk(" HINT(", std::get>(x.t), ")"); Put("\n"); EndOpenMP(); } - void Unparse(const OpenMPCriticalConstruct &x) { - Walk(std::get(x.t)); - Walk(std::get(x.t), ""); + void Unparse(const OmpEndCriticalDirective &x) { BeginOpenMP(); Word("!$OMP END CRITICAL"); - Walk(std::get(x.t)); + Walk(" (", std::get>(x.t), ")"); Put("\n"); EndOpenMP(); } + void Unparse(const OpenMPCriticalConstruct &x) { + Walk(std::get(x.t)); + Walk(std::get(x.t), ""); + Walk(std::get(x.t)); + } void Unparse(const OpenMPDeclareTargetSpecifier::WithClause &x) { Walk(x.maptype), Put("("), Walk(x.names), Put(")"); } diff --git a/flang/test/semantics/omp-clause-validity01.f90 b/flang/test/semantics/omp-clause-validity01.f90 index 59c15f3083a4..17d942f4865a 100644 --- a/flang/test/semantics/omp-clause-validity01.f90 +++ b/flang/test/semantics/omp-clause-validity01.f90 @@ -301,4 +301,12 @@ !$omp flush (c) !$omp cancel DO !$omp cancellation point parallel + +! 2.13.2 critical Construct + + !ERROR: Internal: no symbol found for 'first' + !$omp critical (first) + a = 3.14 + !ERROR: Internal: no symbol found for 'first' + !$omp end critical (first) end program