[flang-commits] [PATCH] D91209: [flang] Fix CheckSpecificationExpr handling of associated names

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue Nov 10 14:55:30 PST 2020


klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added subscribers: llvm-commits, jdoerfert.
Herald added a project: LLVM.
klausler requested review of this revision.

Avoid a spurious error message about a dummy procedure reference
in a specification expression by restructuring the handling of
use-associated and host-associated symbols.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91209

Files:
  flang/lib/Evaluate/check-expression.cpp
  flang/test/Semantics/spec-expr.f90


Index: flang/test/Semantics/spec-expr.f90
===================================================================
--- flang/test/Semantics/spec-expr.f90
+++ flang/test/Semantics/spec-expr.f90
@@ -173,3 +173,12 @@
     real, dimension((param + 2)) :: realField
   end type dtype
 end subroutine s15
+
+! Regression test: don't get confused by host association
+subroutine s16(n)
+  integer :: n
+ contains
+  subroutine inner(r)
+    real, dimension(n) :: r
+  end subroutine
+end subroutine s16
Index: flang/lib/Evaluate/check-expression.cpp
===================================================================
--- flang/lib/Evaluate/check-expression.cpp
+++ flang/lib/Evaluate/check-expression.cpp
@@ -258,30 +258,29 @@
   Result operator()(const CoarrayRef &) const { return "coindexed reference"; }
 
   Result operator()(const semantics::Symbol &symbol) const {
-    if (semantics::IsNamedConstant(symbol)) {
+    const auto &ultimate{symbol.GetUltimate()};
+    if (semantics::IsNamedConstant(ultimate) || ultimate.owner().IsModule() ||
+        ultimate.owner().IsSubmodule()) {
       return std::nullopt;
-    } else if (scope_.IsDerivedType() && IsVariableName(symbol)) { // C750, C754
+    } else if (scope_.IsDerivedType() &&
+        IsVariableName(ultimate)) { // C750, C754
       return "derived type component or type parameter value not allowed to "
              "reference variable '"s +
-          symbol.name().ToString() + "'";
-    } else if (IsDummy(symbol)) {
-      if (symbol.attrs().test(semantics::Attr::OPTIONAL)) {
+          ultimate.name().ToString() + "'";
+    } else if (IsDummy(ultimate)) {
+      if (ultimate.attrs().test(semantics::Attr::OPTIONAL)) {
         return "reference to OPTIONAL dummy argument '"s +
-            symbol.name().ToString() + "'";
-      } else if (symbol.attrs().test(semantics::Attr::INTENT_OUT)) {
+            ultimate.name().ToString() + "'";
+      } else if (ultimate.attrs().test(semantics::Attr::INTENT_OUT)) {
         return "reference to INTENT(OUT) dummy argument '"s +
-            symbol.name().ToString() + "'";
-      } else if (symbol.has<semantics::ObjectEntityDetails>()) {
+            ultimate.name().ToString() + "'";
+      } else if (ultimate.has<semantics::ObjectEntityDetails>()) {
         return std::nullopt;
       } else {
         return "dummy procedure argument";
       }
-    } else if (symbol.has<semantics::UseDetails>() ||
-        symbol.has<semantics::HostAssocDetails>() ||
-        symbol.owner().kind() == semantics::Scope::Kind::Module) {
-      return std::nullopt;
     } else if (const auto *object{
-                   symbol.detailsIf<semantics::ObjectEntityDetails>()}) {
+                   ultimate.detailsIf<semantics::ObjectEntityDetails>()}) {
       // TODO: what about EQUIVALENCE with data in COMMON?
       // TODO: does this work for blank COMMON?
       if (object->commonBlock()) {
@@ -290,11 +289,11 @@
     }
     for (const semantics::Scope *s{&scope_}; !s->IsGlobal();) {
       s = &s->parent();
-      if (s == &symbol.owner()) {
+      if (s == &ultimate.owner()) {
         return std::nullopt;
       }
     }
-    return "reference to local entity '"s + symbol.name().ToString() + "'";
+    return "reference to local entity '"s + ultimate.name().ToString() + "'";
   }
 
   Result operator()(const Component &x) const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91209.304331.patch
Type: text/x-patch
Size: 3355 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20201110/5cf545fe/attachment.bin>


More information about the flang-commits mailing list