[flang-commits] [flang] 1ee6f7a - [flang] Rearrange prototype & code placement of IsCoarray()
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Tue Nov 30 15:26:42 PST 2021
Author: Peter Klausler
Date: 2021-11-30T15:26:34-08:00
New Revision: 1ee6f7add1ca824de4337991304ff737b953a968
URL: https://github.com/llvm/llvm-project/commit/1ee6f7add1ca824de4337991304ff737b953a968
DIFF: https://github.com/llvm/llvm-project/commit/1ee6f7add1ca824de4337991304ff737b953a968.diff
LOG: [flang] Rearrange prototype & code placement of IsCoarray()
A quick fix last week to the shared library build caused
the predicate IsCoarray(const Symbol &) to be moved from
Semantics to Evaluate. This patch completes that move in
a way that properly combines the existing IsCoarray() tests
for expressions and other object with the test for a symbol.
Differential Revision: https://reviews.llvm.org/D114806
Added:
Modified:
flang/include/flang/Evaluate/tools.h
flang/lib/Evaluate/tools.cpp
flang/lib/Semantics/check-allocate.cpp
flang/lib/Semantics/check-declarations.cpp
flang/lib/Semantics/check-do-forall.cpp
flang/lib/Semantics/resolve-names.cpp
flang/lib/Semantics/tools.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index 5fcc74594b60b..79196257979b0 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -91,10 +91,11 @@ template <typename A> bool IsAssumedRank(const std::optional<A> &x) {
// Predicate: true when an expression is a coarray (corank > 0)
bool IsCoarray(const ActualArgument &);
+bool IsCoarray(const Symbol &);
template <typename A> bool IsCoarray(const A &) { return false; }
template <typename A> bool IsCoarray(const Designator<A> &designator) {
if (const auto *symbol{std::get_if<SymbolRef>(&designator.u)}) {
- return symbol->get().Corank() > 0;
+ return IsCoarray(**symbol);
}
return false;
}
@@ -1051,7 +1052,6 @@ bool IsProcedure(const Symbol &);
bool IsProcedure(const Scope &);
bool IsProcedurePointer(const Symbol &);
bool IsAutomatic(const Symbol &);
-bool IsCoarray(const Symbol &);
bool IsSaved(const Symbol &); // saved implicitly or explicitly
bool IsDummy(const Symbol &);
bool IsFunctionResult(const Symbol &);
diff --git a/flang/lib/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp
index 4e8054f4f6f5f..b5300fcc739af 100644
--- a/flang/lib/Evaluate/tools.cpp
+++ b/flang/lib/Evaluate/tools.cpp
@@ -699,10 +699,12 @@ bool IsAssumedRank(const ActualArgument &arg) {
}
bool IsCoarray(const ActualArgument &arg) {
- if (const auto *expr{arg.UnwrapExpr()}) {
- return IsCoarray(*expr);
- }
- return false;
+ const auto *expr{arg.UnwrapExpr()};
+ return expr && IsCoarray(*expr);
+}
+
+bool IsCoarray(const Symbol &symbol) {
+ return GetAssociationRoot(symbol).Corank() > 0;
}
bool IsProcedure(const Expr<SomeType> &expr) {
@@ -1193,10 +1195,6 @@ bool IsAutomatic(const Symbol &original) {
return false;
}
-bool IsCoarray(const Symbol &symbol) {
- return GetAssociationRoot(symbol).Corank() > 0;
-}
-
bool IsSaved(const Symbol &original) {
const Symbol &symbol{GetAssociationRoot(original)};
const Scope &scope{symbol.owner()};
@@ -1212,7 +1210,7 @@ bool IsSaved(const Symbol &original) {
return false;
} else if (scopeKind == Scope::Kind::Module ||
(scopeKind == Scope::Kind::MainProgram &&
- (symbol.attrs().test(Attr::TARGET) || IsCoarray(symbol)))) {
+ (symbol.attrs().test(Attr::TARGET) || evaluate::IsCoarray(symbol)))) {
// 8.5.16p4
// In main programs, implied SAVE matters only for pointer
// initialization targets and coarrays.
diff --git a/flang/lib/Semantics/check-allocate.cpp b/flang/lib/Semantics/check-allocate.cpp
index 456d5949a3a22..8a3a23ad4f8c2 100644
--- a/flang/lib/Semantics/check-allocate.cpp
+++ b/flang/lib/Semantics/check-allocate.cpp
@@ -541,7 +541,7 @@ bool AllocationCheckerHelper::RunCoarrayRelatedChecks(
CHECK(context.AnyFatalError());
return false;
}
- if (IsCoarray(*symbol_)) {
+ if (evaluate::IsCoarray(*symbol_)) {
if (allocateInfo_.gotTypeSpec) {
// C938
if (const DerivedTypeSpec *
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 6b52de57fc373..1295d5bad4580 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -372,7 +372,7 @@ void CheckHelper::CheckValue(
messages_.Say(
"VALUE attribute may not apply to an assumed-size array"_err_en_US);
}
- if (IsCoarray(symbol)) {
+ if (evaluate::IsCoarray(symbol)) {
messages_.Say("VALUE attribute may not apply to a coarray"_err_en_US);
}
if (IsAllocatable(symbol)) {
@@ -432,7 +432,7 @@ void CheckHelper::CheckAssumedTypeEntity( // C709
"Assumed-type argument '%s' cannot be INTENT(OUT)"_err_en_US,
symbol.name());
}
- if (IsCoarray(symbol)) {
+ if (evaluate::IsCoarray(symbol)) {
messages_.Say(
"Assumed-type argument '%s' cannot be a coarray"_err_en_US,
symbol.name());
@@ -486,7 +486,7 @@ void CheckHelper::CheckObjectEntity(
if (details.isDummy()) {
if (symbol.attrs().test(Attr::INTENT_OUT)) {
if (FindUltimateComponent(symbol, [](const Symbol &x) {
- return IsCoarray(x) && IsAllocatable(x);
+ return evaluate::IsCoarray(x) && IsAllocatable(x);
})) { // C846
messages_.Say(
"An INTENT(OUT) dummy argument may not be, or contain, an ALLOCATABLE coarray"_err_en_US);
@@ -545,7 +545,7 @@ void CheckHelper::CheckObjectEntity(
messages_.Say(
"A dummy argument of an ELEMENTAL procedure may not be ALLOCATABLE"_err_en_US);
}
- if (IsCoarray(symbol)) {
+ if (evaluate::IsCoarray(symbol)) {
messages_.Say(
"A dummy argument of an ELEMENTAL procedure may not be a coarray"_err_en_US);
}
@@ -1448,7 +1448,7 @@ void CheckHelper::CheckVolatile(const Symbol &symbol,
}
if (symbol.has<UseDetails>() || symbol.has<HostAssocDetails>()) {
const Symbol &ultimate{symbol.GetUltimate()};
- if (IsCoarray(ultimate)) {
+ if (evaluate::IsCoarray(ultimate)) {
messages_.Say(
"VOLATILE attribute may not apply to a coarray accessed by USE or host association"_err_en_US);
}
diff --git a/flang/lib/Semantics/check-do-forall.cpp b/flang/lib/Semantics/check-do-forall.cpp
index 1532dea61ac58..42a2ee6e2dead 100644
--- a/flang/lib/Semantics/check-do-forall.cpp
+++ b/flang/lib/Semantics/check-do-forall.cpp
@@ -132,7 +132,7 @@ class DoConcurrentBodyEnforce {
// Predicate for deallocations caused by intrinsic assignment
static bool DeallocateNonCoarray(const Symbol &component) {
- return !IsCoarray(component);
+ return !evaluate::IsCoarray(component);
}
static bool WillDeallocatePolymorphic(const Symbol &entity,
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 8ad0f5ab27d8b..679af0be8660a 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -4978,7 +4978,7 @@ bool DeclarationVisitor::PassesLocalityChecks(
"Finalizable variable '%s' not allowed in a locality-spec"_err_en_US);
return false;
}
- if (IsCoarray(symbol)) { // C1128
+ if (evaluate::IsCoarray(symbol)) { // C1128
SayWithDecl(
name, symbol, "Coarray '%s' not allowed in a locality-spec"_err_en_US);
return false;
diff --git a/flang/lib/Semantics/tools.cpp b/flang/lib/Semantics/tools.cpp
index 0be899c9fedea..e4d1e2f09d67e 100644
--- a/flang/lib/Semantics/tools.cpp
+++ b/flang/lib/Semantics/tools.cpp
@@ -924,7 +924,7 @@ class ImageControlStmtHelper {
private:
bool IsCoarrayObject(const parser::AllocateObject &allocateObject) {
const parser::Name &name{GetLastName(allocateObject)};
- return name.symbol && IsCoarray(*name.symbol);
+ return name.symbol && evaluate::IsCoarray(*name.symbol);
}
};
@@ -988,7 +988,7 @@ parser::CharBlock GetImageControlStmtLocation(
bool HasCoarray(const parser::Expr &expression) {
if (const auto *expr{GetExpr(expression)}) {
for (const Symbol &symbol : evaluate::CollectSymbols(*expr)) {
- if (IsCoarray(GetAssociationRoot(symbol))) {
+ if (evaluate::IsCoarray(symbol)) {
return true;
}
}
@@ -1248,7 +1248,8 @@ template class ComponentIterator<ComponentKind::Scope>;
UltimateComponentIterator::const_iterator FindCoarrayUltimateComponent(
const DerivedTypeSpec &derived) {
UltimateComponentIterator ultimates{derived};
- return std::find_if(ultimates.begin(), ultimates.end(), IsCoarray);
+ return std::find_if(ultimates.begin(), ultimates.end(),
+ [](const Symbol &symbol) { return evaluate::IsCoarray(symbol); });
}
UltimateComponentIterator::const_iterator FindPointerUltimateComponent(
@@ -1288,7 +1289,7 @@ FindPolymorphicAllocatableNonCoarrayUltimateComponent(
const DerivedTypeSpec &derived) {
UltimateComponentIterator ultimates{derived};
return std::find_if(ultimates.begin(), ultimates.end(), [](const Symbol &x) {
- return IsPolymorphicAllocatable(x) && !IsCoarray(x);
+ return IsPolymorphicAllocatable(x) && !evaluate::IsCoarray(x);
});
}
More information about the flang-commits
mailing list