[PATCH] D93345: [flang] Handle undeclared names in EQUIVALENCE statements

Pete Steinfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 16 10:47:16 PST 2020


PeteSteinfeld updated this revision to Diff 312258.
PeteSteinfeld added a comment.

Responses to review comments.  I moved the state variable indicating if we're
resolving names in an EQUIVALENCE statement to the class ScopeHandler and used
the existing FindInScope() function to limit name loopups to the current scope
rather than inventing a new interface.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93345/new/

https://reviews.llvm.org/D93345

Files:
  flang/lib/Semantics/resolve-names.cpp
  flang/test/Semantics/equivalence01.f90


Index: flang/test/Semantics/equivalence01.f90
===================================================================
--- flang/test/Semantics/equivalence01.f90
+++ flang/test/Semantics/equivalence01.f90
@@ -197,3 +197,20 @@
   end interface
 
 end subroutine s16
+
+module m17
+  real :: dupName
+contains
+  real function f17a()
+    implicit none
+    real :: y
+    !ERROR: No explicit type declared for 'dupname'
+    equivalence (dupName, y) 
+  end function f17a
+  real function f17b()
+    real :: y
+    ! The following implicitly declares an object called "dupName" local to 
+    ! the function f17b().  OK since there's no "implicit none
+    equivalence (dupName, y) 
+  end function f17b
+end module m17
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -594,6 +594,7 @@
 
   bool inExecutionPart_{false};
   bool inSpecificationPart_{false};
+  bool inEquivalenceStmt_{false};
   std::set<SourceName> specPartForwardRefs_;
 
 private:
@@ -2018,7 +2019,11 @@
     }
     return FindSymbol(scope.parent(), name);
   } else {
-    return Resolve(name, scope.FindSymbol(name.source));
+    // In EQUIVALENCE statements only resolve names in the local scope, see
+    // 19.5.1.4, paragraph 2, item (10)
+    return Resolve(name,
+        inEquivalenceStmt_ ? FindInScope(scope, name)
+                           : scope.FindSymbol(name.source));
   }
 }
 
@@ -4341,15 +4346,17 @@
 
 bool DeclarationVisitor::Pre(const parser::EquivalenceStmt &x) {
   // save equivalence sets to be processed after specification part
-  CheckNotInBlock("EQUIVALENCE"); // C1107
-  for (const std::list<parser::EquivalenceObject> &set : x.v) {
-    equivalenceSets_.push_back(&set);
+  if (CheckNotInBlock("EQUIVALENCE")) { // C1107
+    for (const std::list<parser::EquivalenceObject> &set : x.v) {
+      equivalenceSets_.push_back(&set);
+    }
   }
   return false; // don't implicitly declare names yet
 }
 
 void DeclarationVisitor::CheckEquivalenceSets() {
   EquivalenceSets equivSets{context()};
+  inEquivalenceStmt_ = true;
   for (const auto *set : equivalenceSets_) {
     const auto &source{set->front().v.value().source};
     if (set->size() <= 1) { // R871
@@ -4366,6 +4373,7 @@
     }
     equivSets.FinishSet(source);
   }
+  inEquivalenceStmt_ = false;
   for (auto &set : equivSets.sets()) {
     if (!set.empty()) {
       currScope().add_equivalenceSet(std::move(set));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93345.312258.patch
Type: text/x-patch
Size: 2533 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201216/c2abb523/attachment.bin>


More information about the llvm-commits mailing list