Skip to content

Commit fc12467

Browse files
authored
[flang][OpenMP] Stop tracking metadirective level in name resolution (#159945)
This was checked in the visitor for OmpDirectiveSpecification, and is not necessary anymore: the early exit (in case of not being inside of a METADIRECTIVE) performs the same actions as the code that was skipped, except it does so through a different sequence of function calls. The net result ends up being the same in either case. The processing of the mapper and reduction specifiers inside of OmpDirectiveSpecification is necesary for the declare directives on WHEN/OTHERWISE clauses, so it's the early exit that needs to be removed. In fact, when the DECLARE_MAPPER/REDUCTION use OmpDirectiveSpecification, this processing will automatically take over the handling of the contained specifiers.
1 parent 78d0b1a commit fc12467

File tree

1 file changed

+15
-31
lines changed

1 file changed

+15
-31
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,14 +1479,6 @@ class OmpVisitor : public virtual DeclarationVisitor {
14791479
static bool NeedsScope(const parser::OmpBlockConstruct &);
14801480
static bool NeedsScope(const parser::OmpClause &);
14811481

1482-
bool Pre(const parser::OmpMetadirectiveDirective &x) { //
1483-
++metaLevel_;
1484-
return true;
1485-
}
1486-
void Post(const parser::OmpMetadirectiveDirective &) { //
1487-
--metaLevel_;
1488-
}
1489-
14901482
bool Pre(const parser::OpenMPRequiresConstruct &x) {
14911483
AddOmpSourceRange(x.source);
14921484
return true;
@@ -1579,10 +1571,11 @@ class OmpVisitor : public virtual DeclarationVisitor {
15791571

15801572
bool Pre(const parser::OpenMPDeclareReductionConstruct &x) {
15811573
AddOmpSourceRange(x.source);
1574+
parser::OmpClauseList empty(std::list<parser::OmpClause>{});
1575+
auto &maybeClauses{std::get<std::optional<parser::OmpClauseList>>(x.t)};
15821576
ProcessReductionSpecifier(
15831577
std::get<Indirection<parser::OmpReductionSpecifier>>(x.t).value(),
1584-
std::get<std::optional<parser::OmpClauseList>>(x.t),
1585-
declaratives_.back());
1578+
maybeClauses ? *maybeClauses : empty, declaratives_.back());
15861579
return false;
15871580
}
15881581
bool Pre(const parser::OmpMapClause &);
@@ -1738,12 +1731,11 @@ class OmpVisitor : public virtual DeclarationVisitor {
17381731
void ProcessMapperSpecifier(const parser::OmpMapperSpecifier &spec,
17391732
const parser::OmpClauseList &clauses);
17401733
void ProcessReductionSpecifier(const parser::OmpReductionSpecifier &spec,
1741-
const std::optional<parser::OmpClauseList> &clauses,
1734+
const parser::OmpClauseList &clauses,
17421735
const parser::OpenMPDeclarativeConstruct *wholeConstruct);
17431736

17441737
void ResolveCriticalName(const parser::OmpArgument &arg);
17451738

1746-
int metaLevel_{0};
17471739
std::vector<const parser::OpenMPDeclarativeConstruct *> declaratives_;
17481740
};
17491741

@@ -1871,7 +1863,7 @@ std::string MangleDefinedOperator(const parser::CharBlock &name) {
18711863

18721864
void OmpVisitor::ProcessReductionSpecifier(
18731865
const parser::OmpReductionSpecifier &spec,
1874-
const std::optional<parser::OmpClauseList> &clauses,
1866+
const parser::OmpClauseList &clauses,
18751867
const parser::OpenMPDeclarativeConstruct *construct) {
18761868
const parser::Name *name{nullptr};
18771869
parser::CharBlock mangledName;
@@ -1999,39 +1991,31 @@ void OmpVisitor::ResolveCriticalName(const parser::OmpArgument &arg) {
19991991

20001992
bool OmpVisitor::Pre(const parser::OmpDirectiveSpecification &x) {
20011993
AddOmpSourceRange(x.source);
2002-
if (metaLevel_ == 0) {
2003-
// Not in METADIRECTIVE.
2004-
return true;
2005-
}
20061994

2007-
// If OmpDirectiveSpecification (which contains clauses) is a part of
2008-
// METADIRECTIVE, some semantic checks may not be applicable.
2009-
// Disable the semantic analysis for it in such cases to allow the compiler
2010-
// to parse METADIRECTIVE without flagging errors.
2011-
auto &maybeArgs{std::get<std::optional<parser::OmpArgumentList>>(x.t)};
2012-
auto &maybeClauses{std::get<std::optional<parser::OmpClauseList>>(x.t)};
1995+
const parser::OmpArgumentList &args{x.Arguments()};
1996+
const parser::OmpClauseList &clauses{x.Clauses()};
20131997

20141998
switch (x.DirId()) {
20151999
case llvm::omp::Directive::OMPD_declare_mapper:
2016-
if (maybeArgs && maybeClauses) {
2017-
const parser::OmpArgument &first{maybeArgs->v.front()};
2000+
if (!args.v.empty()) {
2001+
const parser::OmpArgument &first{args.v.front()};
20182002
if (auto *spec{std::get_if<parser::OmpMapperSpecifier>(&first.u)}) {
2019-
ProcessMapperSpecifier(*spec, *maybeClauses);
2003+
ProcessMapperSpecifier(*spec, clauses);
20202004
}
20212005
}
20222006
break;
20232007
case llvm::omp::Directive::OMPD_declare_reduction:
2024-
if (maybeArgs && maybeClauses) {
2025-
const parser::OmpArgument &first{maybeArgs->v.front()};
2008+
if (!args.v.empty()) {
2009+
const parser::OmpArgument &first{args.v.front()};
20262010
if (auto *spec{std::get_if<parser::OmpReductionSpecifier>(&first.u)}) {
2027-
ProcessReductionSpecifier(*spec, maybeClauses, declaratives_.back());
2011+
ProcessReductionSpecifier(*spec, clauses, declaratives_.back());
20282012
}
20292013
}
20302014
break;
20312015
default:
20322016
// Default processing.
2033-
Walk(maybeArgs);
2034-
Walk(maybeClauses);
2017+
Walk(args);
2018+
Walk(clauses);
20352019
break;
20362020
}
20372021
return false;

0 commit comments

Comments
 (0)