Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions flang/lib/Parser/openmp-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,27 @@ static bool IsReservedName(const Name &name) {
TYPE_PARSER( //
construct<OmpReservedIdentifier>(predicated(name, IsReservedName)))

// Parse x(...)(...) as a substring instead of a function reference.
TYPE_PARSER( //
construct<OmpLocator>(functionReference / !lookAhead("("_tok)) ||
construct<OmpLocator>(Parser<OmpReservedIdentifier>{}))
struct LocatorParser {
using resultType = OmpLocator;
using Token = TokenStringMatch<false, false>;

std::optional<resultType> Parse(ParseState &state) const {
// Parse x(...)(...) as a substring instead of a function reference.
auto funcRef{functionReference / !lookAhead("("_tok)};
if (auto &&result{attempt(funcRef).Parse(state)}) {
return std::move(*result);
}
for (llvm::StringRef n : llvm::omp::getReservedLocatorNames()) {
auto match{Token(n.data(), n.size())};
if (auto &&result{attempt(match >= name).Parse(state)}) {
return OmpReservedIdentifier(std::move(*result));
}
}
return std::nullopt;
}
};

TYPE_PARSER(construct<OmpLocator>(LocatorParser{}))

TYPE_PARSER( //
construct<OmpObject>(Parser<OmpLocator>{}) ||
Expand Down
15 changes: 5 additions & 10 deletions flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,16 +649,6 @@ bool OmpStructureChecker::HasRequires(llvm::omp::Clause req) {
DEREF(unit.symbol()).details());
}

void OmpStructureChecker::Enter(const parser::OmpLocator &x) {
if (auto *reserved{parser::Unwrap<parser::OmpReservedIdentifier>(x.u)}) {
std::string name{parser::ToLowerCaseLetters(reserved->v.source.ToString())};
if (!llvm::is_contained(llvm::omp::getReservedLocatorNames(), name)) {
context_.Say(reserved->v.source, "'%s' is not a valid locator"_err_en_US,
parser::ToUpperCaseLetters(name));
}
}
}

void OmpStructureChecker::CheckArgumentObjectKind(const parser::OmpClause &x) {
unsigned version{context_.langOptions().OpenMPVersion};
llvm::omp::Directive dirId{GetContext().directive};
Expand Down Expand Up @@ -3229,6 +3219,11 @@ void OmpStructureChecker::Enter(const parser::OpenMPCriticalConstruct &x) {
if (auto *object{parser::Unwrap<parser::OmpObject>(arg.u)}) {
if (auto *designator{GetDesignatorFromObj(*object)}) {
return parser::GetDesignatorNameIfDataRef(*designator);
} else if (auto *locator{std::get_if<parser::OmpLocator>(&object->u)}) {
if (auto *res{
std::get_if<parser::OmpReservedIdentifier>(&locator->u)}) {
return &res->v;
}
}
}
return static_cast<const parser::Name *>(nullptr);
Expand Down
1 change: 0 additions & 1 deletion flang/lib/Semantics/check-omp-structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ class OmpStructureChecker : public OmpStructureCheckerBase {
void Enter(const parser::OpenMPCriticalConstruct &);
void Enter(const parser::OpenMPAtomicConstruct &);

void Enter(const parser::OmpLocator &x);
void Enter(const parser::OmpClauseList &);
void Leave(const parser::OmpClauseList &);
void Enter(const parser::OmpClause &);
Expand Down
52 changes: 31 additions & 21 deletions flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2186,29 +2186,39 @@ void OmpVisitor::ProcessReductionSpecifier(
}

void OmpVisitor::ResolveCriticalName(const parser::OmpArgument &arg) {
auto &globalScope{[&]() -> Scope & {
for (Scope *s{&currScope()};; s = &s->parent()) {
if (s->IsTopLevel()) {
return *s;
}
}
llvm_unreachable("Cannot find global scope");
}()};
auto *object{parser::Unwrap<parser::OmpObject>(arg.u)};
if (!object) {
return;
}

if (auto *object{parser::Unwrap<parser::OmpObject>(arg.u)}) {
if (auto *desg{parser::omp::GetDesignatorFromObj(*object)}) {
if (auto *name{parser::GetDesignatorNameIfDataRef(*desg)}) {
if (auto *symbol{FindInScope(globalScope, *name)}) {
if (!symbol->test(Symbol::Flag::OmpCriticalLock)) {
SayWithDecl(*name, *symbol,
"CRITICAL construct name '%s' conflicts with a previous declaration"_warn_en_US,
name->ToString());
}
} else {
name->symbol = &MakeSymbol(globalScope, name->source, Attrs{});
name->symbol->set(Symbol::Flag::OmpCriticalLock);
}
const parser::Name *name{common::visit( //
common::visitors{//
[&](const parser::Designator &x) -> const parser::Name * {
return parser::GetDesignatorNameIfDataRef(x);
},
[&](const parser::OmpLocator &x) -> const parser::Name * {
if (auto *res{std::get_if<parser::OmpReservedIdentifier>(&x.u)}) {
return &res->v;
}
return nullptr;
},
[&](const parser::Name &) -> const parser::Name * { return nullptr; },
[&](const parser::OmpObject::Invalid &) -> const parser::Name * {
return nullptr;
}},
object->u)};

if (name) {
if (auto *symbol{FindInScope(context().globalScope(), *name)}) {
if (!symbol->test(Symbol::Flag::OmpCriticalLock)) {
SayWithDecl(*name, *symbol,
"CRITICAL construct name '%s' conflicts with a previous declaration"_warn_en_US,
name->ToString());
}
} else {
name->symbol =
&MakeSymbol(context().globalScope(), name->source, Attrs{});
name->symbol->set(Symbol::Flag::OmpCriticalLock);
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions flang/test/Semantics/OpenMP/reserved-locator.f90

This file was deleted.