[flang] Allow local variables and function result inquiries in specification expressions
authorPeter Klausler <pklausler@nvidia.com>
Tue, 10 May 2022 20:42:08 +0000 (13:42 -0700)
committerPeter Klausler <pklausler@nvidia.com>
Tue, 10 May 2022 23:47:03 +0000 (16:47 -0700)
Inquiries into the bounds, size, and length of local variables (and function results)
are acceptable specification expressions.  A recent change allowed them for dummy
arguments that are not OPTIONAL or INTENT(OUT), but didn't address other object
entities.

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

flang/lib/Evaluate/check-expression.cpp

index 13b48a2..789e0a2 100644 (file)
@@ -114,7 +114,8 @@ bool IsConstantExprHelper<INVARIANT>::operator()(
   // been rewritten into DescriptorInquiry operations.
   if (const auto *intrinsic{std::get_if<SpecificIntrinsic>(&call.proc().u)}) {
     if (intrinsic->name == "kind" ||
-        intrinsic->name == IntrinsicProcTable::InvalidName) {
+        intrinsic->name == IntrinsicProcTable::InvalidName ||
+        call.arguments().empty() || !call.arguments()[0]) {
       // kind is always a constant, and we avoid cascading errors by considering
       // invalid calls to intrinsics to be constant
       return true;
@@ -539,7 +540,11 @@ public:
         return std::nullopt;
       }
     }
-    return "reference to local entity '"s + ultimate.name().ToString() + "'";
+    if (inInquiry_) {
+      return std::nullopt;
+    } else {
+      return "reference to local entity '"s + ultimate.name().ToString() + "'";
+    }
   }
 
   Result operator()(const Component &x) const {