Skip to content

Commit 6bc3fff

Browse files
klauslervdonaldson
authored andcommitted
[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
1 parent ff18e97 commit 6bc3fff

File tree

7 files changed

+22
-23
lines changed

7 files changed

+22
-23
lines changed

flang/include/flang/Evaluate/tools.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,11 @@ template <typename A> bool IsAssumedRank(const std::optional<A> &x) {
9191

9292
// Predicate: true when an expression is a coarray (corank > 0)
9393
bool IsCoarray(const ActualArgument &);
94+
bool IsCoarray(const Symbol &);
9495
template <typename A> bool IsCoarray(const A &) { return false; }
9596
template <typename A> bool IsCoarray(const Designator<A> &designator) {
9697
if (const auto *symbol{std::get_if<SymbolRef>(&designator.u)}) {
97-
return symbol->get().Corank() > 0;
98+
return IsCoarray(**symbol);
9899
}
99100
return false;
100101
}
@@ -1051,7 +1052,6 @@ bool IsProcedure(const Symbol &);
10511052
bool IsProcedure(const Scope &);
10521053
bool IsProcedurePointer(const Symbol &);
10531054
bool IsAutomatic(const Symbol &);
1054-
bool IsCoarray(const Symbol &);
10551055
bool IsSaved(const Symbol &); // saved implicitly or explicitly
10561056
bool IsDummy(const Symbol &);
10571057
bool IsFunctionResult(const Symbol &);

flang/lib/Evaluate/tools.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -699,10 +699,12 @@ bool IsAssumedRank(const ActualArgument &arg) {
699699
}
700700

701701
bool IsCoarray(const ActualArgument &arg) {
702-
if (const auto *expr{arg.UnwrapExpr()}) {
703-
return IsCoarray(*expr);
704-
}
705-
return false;
702+
const auto *expr{arg.UnwrapExpr()};
703+
return expr && IsCoarray(*expr);
704+
}
705+
706+
bool IsCoarray(const Symbol &symbol) {
707+
return GetAssociationRoot(symbol).Corank() > 0;
706708
}
707709

708710
bool IsProcedure(const Expr<SomeType> &expr) {
@@ -1193,10 +1195,6 @@ bool IsAutomatic(const Symbol &original) {
11931195
return false;
11941196
}
11951197

1196-
bool IsCoarray(const Symbol &symbol) {
1197-
return GetAssociationRoot(symbol).Corank() > 0;
1198-
}
1199-
12001198
bool IsSaved(const Symbol &original) {
12011199
const Symbol &symbol{GetAssociationRoot(original)};
12021200
const Scope &scope{symbol.owner()};
@@ -1212,7 +1210,7 @@ bool IsSaved(const Symbol &original) {
12121210
return false;
12131211
} else if (scopeKind == Scope::Kind::Module ||
12141212
(scopeKind == Scope::Kind::MainProgram &&
1215-
(symbol.attrs().test(Attr::TARGET) || IsCoarray(symbol)))) {
1213+
(symbol.attrs().test(Attr::TARGET) || evaluate::IsCoarray(symbol)))) {
12161214
// 8.5.16p4
12171215
// In main programs, implied SAVE matters only for pointer
12181216
// initialization targets and coarrays.

flang/lib/Semantics/check-allocate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ bool AllocationCheckerHelper::RunCoarrayRelatedChecks(
541541
CHECK(context.AnyFatalError());
542542
return false;
543543
}
544-
if (IsCoarray(*symbol_)) {
544+
if (evaluate::IsCoarray(*symbol_)) {
545545
if (allocateInfo_.gotTypeSpec) {
546546
// C938
547547
if (const DerivedTypeSpec *

flang/lib/Semantics/check-declarations.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ void CheckHelper::CheckValue(
372372
messages_.Say(
373373
"VALUE attribute may not apply to an assumed-size array"_err_en_US);
374374
}
375-
if (IsCoarray(symbol)) {
375+
if (evaluate::IsCoarray(symbol)) {
376376
messages_.Say("VALUE attribute may not apply to a coarray"_err_en_US);
377377
}
378378
if (IsAllocatable(symbol)) {
@@ -432,7 +432,7 @@ void CheckHelper::CheckAssumedTypeEntity( // C709
432432
"Assumed-type argument '%s' cannot be INTENT(OUT)"_err_en_US,
433433
symbol.name());
434434
}
435-
if (IsCoarray(symbol)) {
435+
if (evaluate::IsCoarray(symbol)) {
436436
messages_.Say(
437437
"Assumed-type argument '%s' cannot be a coarray"_err_en_US,
438438
symbol.name());
@@ -486,7 +486,7 @@ void CheckHelper::CheckObjectEntity(
486486
if (details.isDummy()) {
487487
if (symbol.attrs().test(Attr::INTENT_OUT)) {
488488
if (FindUltimateComponent(symbol, [](const Symbol &x) {
489-
return IsCoarray(x) && IsAllocatable(x);
489+
return evaluate::IsCoarray(x) && IsAllocatable(x);
490490
})) { // C846
491491
messages_.Say(
492492
"An INTENT(OUT) dummy argument may not be, or contain, an ALLOCATABLE coarray"_err_en_US);
@@ -545,7 +545,7 @@ void CheckHelper::CheckObjectEntity(
545545
messages_.Say(
546546
"A dummy argument of an ELEMENTAL procedure may not be ALLOCATABLE"_err_en_US);
547547
}
548-
if (IsCoarray(symbol)) {
548+
if (evaluate::IsCoarray(symbol)) {
549549
messages_.Say(
550550
"A dummy argument of an ELEMENTAL procedure may not be a coarray"_err_en_US);
551551
}
@@ -1448,7 +1448,7 @@ void CheckHelper::CheckVolatile(const Symbol &symbol,
14481448
}
14491449
if (symbol.has<UseDetails>() || symbol.has<HostAssocDetails>()) {
14501450
const Symbol &ultimate{symbol.GetUltimate()};
1451-
if (IsCoarray(ultimate)) {
1451+
if (evaluate::IsCoarray(ultimate)) {
14521452
messages_.Say(
14531453
"VOLATILE attribute may not apply to a coarray accessed by USE or host association"_err_en_US);
14541454
}

flang/lib/Semantics/check-do-forall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class DoConcurrentBodyEnforce {
132132

133133
// Predicate for deallocations caused by intrinsic assignment
134134
static bool DeallocateNonCoarray(const Symbol &component) {
135-
return !IsCoarray(component);
135+
return !evaluate::IsCoarray(component);
136136
}
137137

138138
static bool WillDeallocatePolymorphic(const Symbol &entity,

flang/lib/Semantics/resolve-names.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4978,7 +4978,7 @@ bool DeclarationVisitor::PassesLocalityChecks(
49784978
"Finalizable variable '%s' not allowed in a locality-spec"_err_en_US);
49794979
return false;
49804980
}
4981-
if (IsCoarray(symbol)) { // C1128
4981+
if (evaluate::IsCoarray(symbol)) { // C1128
49824982
SayWithDecl(
49834983
name, symbol, "Coarray '%s' not allowed in a locality-spec"_err_en_US);
49844984
return false;

flang/lib/Semantics/tools.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ class ImageControlStmtHelper {
924924
private:
925925
bool IsCoarrayObject(const parser::AllocateObject &allocateObject) {
926926
const parser::Name &name{GetLastName(allocateObject)};
927-
return name.symbol && IsCoarray(*name.symbol);
927+
return name.symbol && evaluate::IsCoarray(*name.symbol);
928928
}
929929
};
930930

@@ -988,7 +988,7 @@ parser::CharBlock GetImageControlStmtLocation(
988988
bool HasCoarray(const parser::Expr &expression) {
989989
if (const auto *expr{GetExpr(expression)}) {
990990
for (const Symbol &symbol : evaluate::CollectSymbols(*expr)) {
991-
if (IsCoarray(GetAssociationRoot(symbol))) {
991+
if (evaluate::IsCoarray(symbol)) {
992992
return true;
993993
}
994994
}
@@ -1248,7 +1248,8 @@ template class ComponentIterator<ComponentKind::Scope>;
12481248
UltimateComponentIterator::const_iterator FindCoarrayUltimateComponent(
12491249
const DerivedTypeSpec &derived) {
12501250
UltimateComponentIterator ultimates{derived};
1251-
return std::find_if(ultimates.begin(), ultimates.end(), IsCoarray);
1251+
return std::find_if(ultimates.begin(), ultimates.end(),
1252+
[](const Symbol &symbol) { return evaluate::IsCoarray(symbol); });
12521253
}
12531254

12541255
UltimateComponentIterator::const_iterator FindPointerUltimateComponent(
@@ -1288,7 +1289,7 @@ FindPolymorphicAllocatableNonCoarrayUltimateComponent(
12881289
const DerivedTypeSpec &derived) {
12891290
UltimateComponentIterator ultimates{derived};
12901291
return std::find_if(ultimates.begin(), ultimates.end(), [](const Symbol &x) {
1291-
return IsPolymorphicAllocatable(x) && !IsCoarray(x);
1292+
return IsPolymorphicAllocatable(x) && !evaluate::IsCoarray(x);
12921293
});
12931294
}
12941295

0 commit comments

Comments
 (0)