From 2cd95504df575d129b0c23327962695d47dc25fd Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Tue, 10 May 2022 13:42:08 -0700 Subject: [PATCH] [flang] Allow local variables and function result inquiries in specification expressions 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 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/flang/lib/Evaluate/check-expression.cpp b/flang/lib/Evaluate/check-expression.cpp index 13b48a2..789e0a2 100644 --- a/flang/lib/Evaluate/check-expression.cpp +++ b/flang/lib/Evaluate/check-expression.cpp @@ -114,7 +114,8 @@ bool IsConstantExprHelper::operator()( // been rewritten into DescriptorInquiry operations. if (const auto *intrinsic{std::get_if(&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 { -- 2.7.4