[flang-commits] [PATCH] D145100: [flang] Warn about violations of an obscure requirement (15.6.4 p2)
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Wed Mar 1 11:49:05 PST 2023
klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
The Fortran 2018 standard, perhaps as an attempt to prevent ambiguity
in older compilers, requires that a statement function appear in an
explicit type declaration statement if its name is also accessible
from a host scope. F18 <https://reviews.llvm.org/F18> processes the specification parts of inner
procedures first, so we don't need this requirement to prevent
ambiguity, and can only really check it retrospectively after name
resolution. Emit a portability warning when appropriate.
https://reviews.llvm.org/D145100
Files:
flang/docs/Extensions.md
flang/lib/Semantics/check-declarations.cpp
flang/test/Semantics/stmt-func01.f90
Index: flang/test/Semantics/stmt-func01.f90
===================================================================
--- flang/test/Semantics/stmt-func01.f90
+++ flang/test/Semantics/stmt-func01.f90
@@ -34,6 +34,7 @@
integer :: sf9
!ERROR: Defining expression of statement function 'sf9' cannot be converted to its result type INTEGER(4)
sf9(n) = "bad"
+ sf10 = 1.
contains
real function explicit(x,y)
integer, intent(in) :: x
@@ -44,4 +45,8 @@
real :: arr(2)
arr = [1., 2.]
end function
+ subroutine foo
+ !PORTABILITY: An implicitly typed statement function should not appear when the same symbol is available in its host scope
+ sf10(x) = 2.*x
+ end subroutine
end
Index: flang/lib/Semantics/check-declarations.cpp
===================================================================
--- flang/lib/Semantics/check-declarations.cpp
+++ flang/lib/Semantics/check-declarations.cpp
@@ -1044,6 +1044,15 @@
if (auto msg{evaluate::CheckStatementFunction(
symbol, *stmtFunction, context_.foldingContext())}) {
SayWithDeclaration(symbol, std::move(*msg));
+ } else if (details.result().flags().test(Symbol::Flag::Implicit)) {
+ // 15.6.4 p2 weird requirement
+ if (const Symbol *
+ host{symbol.owner().parent().FindSymbol(symbol.name())}) {
+ evaluate::AttachDeclaration(
+ messages_.Say(symbol.name(),
+ "An implicitly typed statement function should not appear when the same symbol is available in its host scope"_port_en_US),
+ *host);
+ }
}
}
if (IsElementalProcedure(symbol)) {
Index: flang/docs/Extensions.md
===================================================================
--- flang/docs/Extensions.md
+++ flang/docs/Extensions.md
@@ -84,6 +84,10 @@
scope" -- i.e., not scoped by `BLOCK` constructs.
As most (but not all) compilers implement `BLOCK` scoping of construct
names, so does f18, with a portability warning.
+* 15.6.4 paragraph 2 prohibits an implicitly typed statement function
+ from sharing the same name as a symbol in its scope's host, if it
+ has one.
+ We accept this usage witha portability warning.
## Extensions, deletions, and legacy features supported by default
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145100.501612.patch
Type: text/x-patch
Size: 2250 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230301/33bf168f/attachment-0001.bin>
More information about the flang-commits
mailing list