aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Semantics
diff options
context:
space:
mode:
Diffstat (limited to 'flang/lib/Semantics')
-rw-r--r--flang/lib/Semantics/check-acc-structure.cpp7
-rw-r--r--flang/lib/Semantics/check-omp-atomic.cpp2
-rw-r--r--flang/lib/Semantics/check-omp-loop.cpp23
-rw-r--r--flang/lib/Semantics/check-omp-structure.cpp36
-rw-r--r--flang/lib/Semantics/check-omp-structure.h2
-rw-r--r--flang/lib/Semantics/resolve-directives.cpp9
-rw-r--r--flang/lib/Semantics/resolve-names.cpp6
7 files changed, 44 insertions, 41 deletions
diff --git a/flang/lib/Semantics/check-acc-structure.cpp b/flang/lib/Semantics/check-acc-structure.cpp
index 3cd6d6b..5e87b83 100644
--- a/flang/lib/Semantics/check-acc-structure.cpp
+++ b/flang/lib/Semantics/check-acc-structure.cpp
@@ -10,6 +10,7 @@
#include "flang/Common/enum-set.h"
#include "flang/Evaluate/tools.h"
#include "flang/Parser/parse-tree.h"
+#include "flang/Parser/tools.h"
#include "flang/Semantics/symbol.h"
#include "flang/Semantics/tools.h"
#include "flang/Semantics/type.h"
@@ -709,7 +710,8 @@ void AccStructureChecker::CheckMultipleOccurrenceInDeclare(
common::visit(
common::visitors{
[&](const parser::Designator &designator) {
- if (const auto *name = getDesignatorNameIfDataRef(designator)) {
+ if (const auto *name =
+ parser::GetDesignatorNameIfDataRef(designator)) {
if (declareSymbols.contains(&name->symbol->GetUltimate())) {
if (declareSymbols[&name->symbol->GetUltimate()] == clause) {
context_.Warn(common::UsageWarning::OpenAccUsage,
@@ -982,7 +984,8 @@ void AccStructureChecker::Enter(const parser::AccClause::Reduction &reduction) {
common::visit(
common::visitors{
[&](const parser::Designator &designator) {
- if (const auto *name = getDesignatorNameIfDataRef(designator)) {
+ if (const auto *name =
+ parser::GetDesignatorNameIfDataRef(designator)) {
if (name->symbol) {
if (const auto *type{name->symbol->GetType()}) {
if (type->IsNumeric(TypeCategory::Integer) &&
diff --git a/flang/lib/Semantics/check-omp-atomic.cpp b/flang/lib/Semantics/check-omp-atomic.cpp
index 515121a..2707921 100644
--- a/flang/lib/Semantics/check-omp-atomic.cpp
+++ b/flang/lib/Semantics/check-omp-atomic.cpp
@@ -286,7 +286,7 @@ static std::optional<AnalyzedCondStmt> AnalyzeConditionalStmt(
// Extract the evaluate::Expr from ScalarLogicalExpr.
auto getFromLogical{[](const parser::ScalarLogicalExpr &logical) {
// ScalarLogicalExpr is Scalar<Logical<common::Indirection<Expr>>>
- const parser::Expr &expr{logical.thing.thing.value()};
+ auto &expr{parser::UnwrapRef<parser::Expr>(logical)};
return GetEvaluateExpr(expr);
}};
diff --git a/flang/lib/Semantics/check-omp-loop.cpp b/flang/lib/Semantics/check-omp-loop.cpp
index c9d0495..aaaa2d6 100644
--- a/flang/lib/Semantics/check-omp-loop.cpp
+++ b/flang/lib/Semantics/check-omp-loop.cpp
@@ -127,24 +127,23 @@ using namespace Fortran::semantics::omp;
void OmpStructureChecker::HasInvalidDistributeNesting(
const parser::OpenMPLoopConstruct &x) {
- bool violation{false};
const parser::OmpDirectiveName &beginName{x.BeginDir().DirName()};
if (llvm::omp::topDistributeSet.test(beginName.v)) {
// `distribute` region has to be nested
- if (!CurrentDirectiveIsNested()) {
- violation = true;
- } else {
+ if (CurrentDirectiveIsNested()) {
// `distribute` region has to be strictly nested inside `teams`
if (!llvm::omp::bottomTeamsSet.test(GetContextParent().directive)) {
- violation = true;
+ context_.Say(beginName.source,
+ "`DISTRIBUTE` region has to be strictly nested inside `TEAMS` "
+ "region."_err_en_US);
}
+ } else {
+ // If not lexically nested (orphaned), issue a warning.
+ context_.Say(beginName.source,
+ "`DISTRIBUTE` must be dynamically enclosed in a `TEAMS` "
+ "region."_warn_en_US);
}
}
- if (violation) {
- context_.Say(beginName.source,
- "`DISTRIBUTE` region has to be strictly nested inside `TEAMS` "
- "region."_err_en_US);
- }
}
void OmpStructureChecker::HasInvalidLoopBinding(
const parser::OpenMPLoopConstruct &x) {
@@ -486,8 +485,8 @@ void OmpStructureChecker::Leave(const parser::OpenMPLoopConstruct &x) {
common::visit(
common::visitors{
[&](const parser::Designator &designator) {
- if (const auto *name{semantics::getDesignatorNameIfDataRef(
- designator)}) {
+ if (const auto *name{
+ parser::GetDesignatorNameIfDataRef(designator)}) {
checkReductionSymbolInScan(name);
}
},
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index ea6fe43..be10669 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -1535,6 +1535,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPRequiresConstruct &x) {
[&](auto &&s) {
using TypeS = llvm::remove_cvref_t<decltype(s)>;
if constexpr ( //
+ std::is_same_v<TypeS, parser::OmpClause::DeviceSafesync> ||
std::is_same_v<TypeS, parser::OmpClause::DynamicAllocators> ||
std::is_same_v<TypeS, parser::OmpClause::ReverseOffload> ||
std::is_same_v<TypeS, parser::OmpClause::SelfMaps> ||
@@ -1561,20 +1562,11 @@ void OmpStructureChecker::Leave(const parser::OpenMPRequiresConstruct &) {
dirContext_.pop_back();
}
-void OmpStructureChecker::CheckAlignValue(const parser::OmpClause &clause) {
- if (auto *align{std::get_if<parser::OmpClause::Align>(&clause.u)}) {
- if (const auto &v{GetIntValue(align->v)}; v && *v <= 0) {
- context_.Say(clause.source, "The alignment should be positive"_err_en_US);
- }
- }
-}
-
void OmpStructureChecker::Enter(const parser::OpenMPDeclarativeAllocate &x) {
isPredefinedAllocator = true;
const auto &dir{std::get<parser::Verbatim>(x.t)};
const auto &objectList{std::get<parser::OmpObjectList>(x.t)};
PushContextAndClauseSets(dir.source, llvm::omp::Directive::OMPD_allocate);
- const auto &clauseList{std::get<parser::OmpClauseList>(x.t)};
SymbolSourceMap currSymbols;
GetSymbolsInObjectList(objectList, currSymbols);
for (auto &[symbol, source] : currSymbols) {
@@ -1597,9 +1589,6 @@ void OmpStructureChecker::Enter(const parser::OpenMPDeclarativeAllocate &x) {
source.ToString());
}
}
- for (const auto &clause : clauseList.v) {
- CheckAlignValue(clause);
- }
CheckVarIsNotPartOfAnotherVar(dir.source, objectList);
}
@@ -2006,9 +1995,6 @@ void OmpStructureChecker::Enter(const parser::OpenMPExecutableAllocate &x) {
isPredefinedAllocator = true;
const auto &objectList{std::get<std::optional<parser::OmpObjectList>>(x.t)};
- for (const auto &clause : clauseList.v) {
- CheckAlignValue(clause);
- }
if (objectList) {
CheckVarIsNotPartOfAnotherVar(dir.source, *objectList);
}
@@ -2616,7 +2602,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPCriticalConstruct &x) {
auto getNameFromArg{[](const parser::OmpArgument &arg) {
if (auto *object{parser::Unwrap<parser::OmpObject>(arg.u)}) {
if (auto *designator{omp::GetDesignatorFromObj(*object)}) {
- return getDesignatorNameIfDataRef(*designator);
+ return parser::GetDesignatorNameIfDataRef(*designator);
}
}
return static_cast<const parser::Name *>(nullptr);
@@ -3233,7 +3219,6 @@ CHECK_SIMPLE_CLAUSE(AdjustArgs, OMPC_adjust_args)
CHECK_SIMPLE_CLAUSE(AppendArgs, OMPC_append_args)
CHECK_SIMPLE_CLAUSE(MemoryOrder, OMPC_memory_order)
CHECK_SIMPLE_CLAUSE(Bind, OMPC_bind)
-CHECK_SIMPLE_CLAUSE(Align, OMPC_align)
CHECK_SIMPLE_CLAUSE(Compare, OMPC_compare)
CHECK_SIMPLE_CLAUSE(OmpxAttribute, OMPC_ompx_attribute)
CHECK_SIMPLE_CLAUSE(Weak, OMPC_weak)
@@ -3897,6 +3882,19 @@ void OmpStructureChecker::CheckIsLoopIvPartOfClause(
}
}
+void OmpStructureChecker::Enter(const parser::OmpClause::Align &x) {
+ CheckAllowedClause(llvm::omp::Clause::OMPC_align);
+ if (const auto &v{GetIntValue(x.v.v)}) {
+ if (*v <= 0) {
+ context_.Say(GetContext().clauseSource,
+ "The alignment should be positive"_err_en_US);
+ } else if (!llvm::isPowerOf2_64(*v)) {
+ context_.Say(GetContext().clauseSource,
+ "The alignment should be a power of 2"_err_en_US);
+ }
+ }
+}
+
// Restrictions specific to each clause are implemented apart from the
// generalized restrictions.
void OmpStructureChecker::Enter(const parser::OmpClause::Aligned &x) {
@@ -5194,6 +5192,10 @@ void OmpStructureChecker::Enter(
CheckAllowedRequiresClause(llvm::omp::Clause::OMPC_atomic_default_mem_order);
}
+void OmpStructureChecker::Enter(const parser::OmpClause::DeviceSafesync &x) {
+ CheckAllowedRequiresClause(llvm::omp::Clause::OMPC_device_safesync);
+}
+
void OmpStructureChecker::Enter(const parser::OmpClause::DynamicAllocators &x) {
CheckAllowedRequiresClause(llvm::omp::Clause::OMPC_dynamic_allocators);
}
diff --git a/flang/lib/Semantics/check-omp-structure.h b/flang/lib/Semantics/check-omp-structure.h
index 543642ff..4cb0b74 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -347,8 +347,6 @@ private:
void CheckAllowedRequiresClause(llvmOmpClause clause);
bool deviceConstructFound_{false};
- void CheckAlignValue(const parser::OmpClause &);
-
void AddEndDirectiveClauses(const parser::OmpClauseList &clauses);
void EnterDirectiveNest(const int index) { directiveNest_[index]++; }
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 7067ed3..33e9ea5 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -560,7 +560,7 @@ public:
auto getArgument{[&](auto &&maybeClause) {
if (maybeClause) {
// Scalar<Logical<Constant<common::Indirection<Expr>>>>
- auto &parserExpr{maybeClause->v.thing.thing.thing.value()};
+ auto &parserExpr{parser::UnwrapRef<parser::Expr>(*maybeClause)};
evaluate::ExpressionAnalyzer ea{context_};
if (auto &&maybeExpr{ea.Analyze(parserExpr)}) {
if (auto v{omp::GetLogicalValue(*maybeExpr)}) {
@@ -586,6 +586,7 @@ public:
[&](auto &&s) {
using TypeS = llvm::remove_cvref_t<decltype(s)>;
if constexpr ( //
+ std::is_same_v<TypeS, OmpClause::DeviceSafesync> ||
std::is_same_v<TypeS, OmpClause::DynamicAllocators> ||
std::is_same_v<TypeS, OmpClause::ReverseOffload> ||
std::is_same_v<TypeS, OmpClause::SelfMaps> ||
@@ -892,7 +893,7 @@ public:
common::visitors{
[&](const parser::Designator &designator) {
if (const auto *name{
- semantics::getDesignatorNameIfDataRef(designator)}) {
+ parser::GetDesignatorNameIfDataRef(designator)}) {
if (name->symbol) {
name->symbol->set(
ompFlag.value_or(Symbol::Flag::OmpMapStorage));
@@ -1758,7 +1759,7 @@ void AccAttributeVisitor::ResolveAccObject(
common::visitors{
[&](const parser::Designator &designator) {
if (const auto *name{
- semantics::getDesignatorNameIfDataRef(designator)}) {
+ parser::GetDesignatorNameIfDataRef(designator)}) {
if (auto *symbol{ResolveAcc(*name, accFlag, currScope())}) {
AddToContextObjectWithDSA(*symbol, accFlag);
if (dataSharingAttributeFlags.test(accFlag)) {
@@ -3064,7 +3065,7 @@ void OmpAttributeVisitor::ResolveOmpDesignator(
unsigned version{context_.langOptions().OpenMPVersion};
llvm::omp::Directive directive{GetContext().directive};
- const auto *name{semantics::getDesignatorNameIfDataRef(designator)};
+ const auto *name{parser::GetDesignatorNameIfDataRef(designator)};
if (!name) {
// Array sections to be changed to substrings as needed
if (AnalyzeExpr(context_, designator)) {
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 699de41..0af1c94 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -1494,7 +1494,7 @@ bool AccVisitor::Pre(const parser::AccClause::UseDevice &x) {
common::visitors{
[&](const parser::Designator &designator) {
if (const auto *name{
- semantics::getDesignatorNameIfDataRef(designator)}) {
+ parser::GetDesignatorNameIfDataRef(designator)}) {
Symbol *prev{currScope().FindSymbol(name->source)};
if (prev != name->symbol) {
name->symbol = prev;
@@ -1648,7 +1648,7 @@ public:
common::visitors{
[&](const parser::Designator &designator) {
if (const auto *name{
- semantics::getDesignatorNameIfDataRef(designator)}) {
+ parser::GetDesignatorNameIfDataRef(designator)}) {
specPartState_.declareTargetNames.insert(name->source);
}
},
@@ -2016,7 +2016,7 @@ void OmpVisitor::ResolveCriticalName(const parser::OmpArgument &arg) {
if (auto *object{parser::Unwrap<parser::OmpObject>(arg.u)}) {
if (auto *desg{omp::GetDesignatorFromObj(*object)}) {
- if (auto *name{getDesignatorNameIfDataRef(*desg)}) {
+ if (auto *name{parser::GetDesignatorNameIfDataRef(*desg)}) {
if (auto *symbol{FindInScope(globalScope, *name)}) {
if (!symbol->test(Symbol::Flag::OmpCriticalLock)) {
SayWithDecl(*name, *symbol,