[flang-commits] [PATCH] D143835: [flang] Associate entities are variables

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Sat Feb 11 17:20:34 PST 2023


klausler created this revision.
klausler added a reviewer: clementval.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

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.)


https://reviews.llvm.org/D143835

Files:
  flang/lib/Evaluate/tools.cpp


Index: flang/lib/Evaluate/tools.cpp
===================================================================
--- flang/lib/Evaluate/tools.cpp
+++ flang/lib/Evaluate/tools.cpp
@@ -78,8 +78,11 @@
 // 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()};
@@ -1251,15 +1254,10 @@
 }
 
 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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143835.496727.patch
Type: text/x-patch
Size: 1479 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230212/3b49a3e3/attachment-0001.bin>


More information about the flang-commits mailing list