@@ -1480,12 +1480,10 @@ class OmpVisitor : public virtual DeclarationVisitor {
14801480 static bool NeedsScope (const parser::OmpClause &);
14811481
14821482 bool Pre (const parser::OmpMetadirectiveDirective &x) { //
1483- metaDirective_ = &x;
14841483 ++metaLevel_;
14851484 return true ;
14861485 }
14871486 void Post (const parser::OmpMetadirectiveDirective &) { //
1488- metaDirective_ = nullptr ;
14891487 --metaLevel_;
14901488 }
14911489
@@ -1583,7 +1581,8 @@ class OmpVisitor : public virtual DeclarationVisitor {
15831581 AddOmpSourceRange (x.source );
15841582 ProcessReductionSpecifier (
15851583 std::get<Indirection<parser::OmpReductionSpecifier>>(x.t ).value (),
1586- std::get<std::optional<parser::OmpClauseList>>(x.t ), x);
1584+ std::get<std::optional<parser::OmpClauseList>>(x.t ),
1585+ declaratives_.back ());
15871586 return false ;
15881587 }
15891588 bool Pre (const parser::OmpMapClause &);
@@ -1692,9 +1691,11 @@ class OmpVisitor : public virtual DeclarationVisitor {
16921691 // can implicitly declare variables instead of only using the
16931692 // ones already declared in the Fortran sources.
16941693 SkipImplicitTyping (true );
1694+ declaratives_.push_back (&x);
16951695 return true ;
16961696 }
16971697 void Post (const parser::OpenMPDeclarativeConstruct &) {
1698+ declaratives_.pop_back ();
16981699 SkipImplicitTyping (false );
16991700 messageHandler ().set_currStmtSource (std::nullopt );
17001701 }
@@ -1736,15 +1737,14 @@ class OmpVisitor : public virtual DeclarationVisitor {
17361737private:
17371738 void ProcessMapperSpecifier (const parser::OmpMapperSpecifier &spec,
17381739 const parser::OmpClauseList &clauses);
1739- template <typename T>
17401740 void ProcessReductionSpecifier (const parser::OmpReductionSpecifier &spec,
17411741 const std::optional<parser::OmpClauseList> &clauses,
1742- const T & wholeConstruct);
1742+ const parser::OpenMPDeclarativeConstruct * wholeConstruct);
17431743
17441744 void ResolveCriticalName (const parser::OmpArgument &arg);
17451745
17461746 int metaLevel_{0 };
1747- const parser::OmpMetadirectiveDirective *metaDirective_{ nullptr } ;
1747+ std::vector< const parser::OpenMPDeclarativeConstruct *> declaratives_ ;
17481748};
17491749
17501750bool OmpVisitor::NeedsScope (const parser::OmpBlockConstruct &x) {
@@ -1869,11 +1869,10 @@ std::string MangleDefinedOperator(const parser::CharBlock &name) {
18691869 return " op" + name.ToString ();
18701870}
18711871
1872- template <typename T>
18731872void OmpVisitor::ProcessReductionSpecifier (
18741873 const parser::OmpReductionSpecifier &spec,
18751874 const std::optional<parser::OmpClauseList> &clauses,
1876- const T &wholeOmpConstruct ) {
1875+ const parser::OpenMPDeclarativeConstruct *construct ) {
18771876 const parser::Name *name{nullptr };
18781877 parser::CharBlock mangledName;
18791878 UserReductionDetails reductionDetailsTemp;
@@ -1960,7 +1959,7 @@ void OmpVisitor::ProcessReductionSpecifier(
19601959 PopScope ();
19611960 }
19621961
1963- reductionDetails->AddDecl (&wholeOmpConstruct );
1962+ reductionDetails->AddDecl (construct );
19641963
19651964 if (!symbol) {
19661965 symbol = &MakeSymbol (mangledName, Attrs{}, std::move (*reductionDetails));
@@ -2025,8 +2024,7 @@ bool OmpVisitor::Pre(const parser::OmpDirectiveSpecification &x) {
20252024 if (maybeArgs && maybeClauses) {
20262025 const parser::OmpArgument &first{maybeArgs->v .front ()};
20272026 if (auto *spec{std::get_if<parser::OmpReductionSpecifier>(&first.u )}) {
2028- CHECK (metaDirective_);
2029- ProcessReductionSpecifier (*spec, maybeClauses, *metaDirective_);
2027+ ProcessReductionSpecifier (*spec, maybeClauses, declaratives_.back ());
20302028 }
20312029 }
20322030 break ;
0 commit comments