[flang-commits] [flang] 3af8830 - [flang] Associate entities are variables
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Tue Feb 14 07:51:04 PST 2023
Author: Peter Klausler
Date: 2023-02-14T07:50:45-08:00
New Revision: 3af88305e443eb0a7930b5d7f2e26a609b65e556
URL: https://github.com/llvm/llvm-project/commit/3af88305e443eb0a7930b5d7f2e26a609b65e556
DIFF: https://github.com/llvm/llvm-project/commit/3af88305e443eb0a7930b5d7f2e26a609b65e556.diff
LOG: [flang] Associate entities are variables
A more precise reading of the standard for associate entities, like "x"
in ASSOCIATE(x => selector), shows that the utility predicates used for
determining their status as variables should treat them as variables
(not necessarily definable), whatever the selector is. Currently
the cases where the selector is an expression or a designator with a
vector subscript are not properly considered to be variables.
(See Fortran 2018, 11.1.3.3 paragraph 5.)
Differential Revision: https://reviews.llvm.org/D143835
Added:
Modified:
flang/lib/Evaluate/tools.cpp
Removed:
################################################################################
diff --git a/flang/lib/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp
index bf530f857b652..a39493b60b678 100644
--- a/flang/lib/Evaluate/tools.cpp
+++ b/flang/lib/Evaluate/tools.cpp
@@ -78,8 +78,11 @@ std::optional<DataRef> ExtractSubstringBase(const Substring &substring) {
// IsVariable()
auto IsVariableHelper::operator()(const Symbol &symbol) const -> Result {
- const Symbol &root{GetAssociationRoot(symbol)};
- return !IsNamedConstant(root) && root.has<semantics::ObjectEntityDetails>();
+ // ASSOCIATE(x => expr) -- x counts as a variable, but undefinable
+ const Symbol &ultimate{symbol.GetUltimate()};
+ return !IsNamedConstant(ultimate) &&
+ (ultimate.has<semantics::ObjectEntityDetails>() ||
+ ultimate.has<semantics::AssocEntityDetails>());
}
auto IsVariableHelper::operator()(const Component &x) const -> Result {
const Symbol &comp{x.GetLastSymbol()};
@@ -1263,15 +1266,10 @@ const Symbol *GetMainEntry(const Symbol *symbol) {
}
bool IsVariableName(const Symbol &original) {
- const Symbol &symbol{ResolveAssociations(original)};
- if (symbol.has<ObjectEntityDetails>()) {
- return !IsNamedConstant(symbol);
- } else if (const auto *assoc{symbol.detailsIf<AssocEntityDetails>()}) {
- const auto &expr{assoc->expr()};
- return expr && IsVariable(*expr) && !HasVectorSubscript(*expr);
- } else {
- return false;
- }
+ const Symbol &ultimate{original.GetUltimate()};
+ return !IsNamedConstant(ultimate) &&
+ (ultimate.has<ObjectEntityDetails>() ||
+ ultimate.has<AssocEntityDetails>());
}
bool IsPureProcedure(const Symbol &original) {
More information about the flang-commits
mailing list