[flang-commits] [PATCH] D119565: [flang] Avoid bogus error for specification expression
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Fri Feb 11 10:51:33 PST 2022
klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
klausler requested review of this revision.
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.
https://reviews.llvm.org/D119565
Files:
flang/lib/Evaluate/check-expression.cpp
flang/lib/Semantics/check-declarations.cpp
flang/test/Semantics/resolve69.f90
Index: flang/test/Semantics/resolve69.f90
===================================================================
--- flang/test/Semantics/resolve69.f90
+++ flang/test/Semantics/resolve69.f90
@@ -64,3 +64,15 @@
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
Index: flang/lib/Semantics/check-declarations.cpp
===================================================================
--- flang/lib/Semantics/check-declarations.cpp
+++ flang/lib/Semantics/check-declarations.cpp
@@ -34,7 +34,6 @@
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()); }
Index: flang/lib/Evaluate/check-expression.cpp
===================================================================
--- flang/lib/Evaluate/check-expression.cpp
+++ flang/lib/Evaluate/check-expression.cpp
@@ -526,18 +526,14 @@
} 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() + "'";
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119565.407952.patch
Type: text/x-patch
Size: 1880 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220211/21e97e71/attachment.bin>
More information about the flang-commits
mailing list