[flang-commits] [flang] 7fbabe6 - [flang] Avoid bogus error for specification expression

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Feb 11 15:57:13 PST 2022


Author: Peter Klausler
Date: 2022-02-11T15:57:06-08:00
New Revision: 7fbabe6ee4213d172c7552becd9b074e18a24c6f

URL: https://github.com/llvm/llvm-project/commit/7fbabe6ee4213d172c7552becd9b074e18a24c6f
DIFF: https://github.com/llvm/llvm-project/commit/7fbabe6ee4213d172c7552becd9b074e18a24c6f.diff

LOG: [flang] Avoid bogus error for specification expression

When a scope's symbol has characteriztics whose specification
expressions depend on other non-constant symbols in the same scope,
f18 rightfully emits an error.  However, in the case of usage in
specification expressions involving host association, the program is not
invalid.  This can arise, for example, in the case of an internal
function whose result's attributes use host-associated variables.

Differential Revision: https://reviews.llvm.org/D119565

Added: 
    

Modified: 
    flang/lib/Evaluate/check-expression.cpp
    flang/lib/Semantics/check-declarations.cpp
    flang/test/Semantics/resolve69.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/check-expression.cpp b/flang/lib/Evaluate/check-expression.cpp
index 1bb33b62151e3..64b118a54aa79 100644
--- a/flang/lib/Evaluate/check-expression.cpp
+++ b/flang/lib/Evaluate/check-expression.cpp
@@ -526,18 +526,14 @@ class CheckSpecificationExprHelper
       } else {
         return "dummy procedure argument";
       }
+    } else if (&symbol.owner() != &scope_ || &ultimate.owner() != &scope_) {
+      return std::nullopt; // host association is in play
     } else if (const auto *object{
                    ultimate.detailsIf<semantics::ObjectEntityDetails>()}) {
       if (object->commonBlock()) {
         return std::nullopt;
       }
     }
-    for (const semantics::Scope *s{&scope_}; !s->IsGlobal();) {
-      s = &s->parent();
-      if (s == &ultimate.owner()) {
-        return std::nullopt;
-      }
-    }
     return "reference to local entity '"s + ultimate.name().ToString() + "'";
   }
 

diff  --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index dcb8cd3834039..fdbbcaba55ae6 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -34,7 +34,6 @@ using characteristics::Procedure;
 class CheckHelper {
 public:
   explicit CheckHelper(SemanticsContext &c) : context_{c} {}
-  CheckHelper(SemanticsContext &c, const Scope &s) : context_{c}, scope_{&s} {}
 
   SemanticsContext &context() { return context_; }
   void Check() { Check(context_.globalScope()); }

diff  --git a/flang/test/Semantics/resolve69.f90 b/flang/test/Semantics/resolve69.f90
index e3f00e2bb27ac..ee3e21a6a8709 100644
--- a/flang/test/Semantics/resolve69.f90
+++ b/flang/test/Semantics/resolve69.f90
@@ -64,3 +64,15 @@ Program d5
   line%value = 'ok'
   Print *,Trim(line%value)
 End Program
+
+!Not errors.
+subroutine outer
+  integer n
+ contains
+  character(n) function inner1()
+    inner1 = ''
+  end function inner1
+  function inner2()
+    real inner2(n)
+  end function inner2
+end subroutine outer


        


More information about the flang-commits mailing list