[flang-commits] [flang] 41b5f37 - [flang] Warn about violations of an obscure requirement (15.6.4 p2)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Thu Mar 2 09:42:32 PST 2023


Author: Peter Klausler
Date: 2023-03-02T09:42:27-08:00
New Revision: 41b5f37185503b1c242cd8fd0295e723f44fac2e

URL: https://github.com/llvm/llvm-project/commit/41b5f37185503b1c242cd8fd0295e723f44fac2e
DIFF: https://github.com/llvm/llvm-project/commit/41b5f37185503b1c242cd8fd0295e723f44fac2e.diff

LOG: [flang] Warn about violations of an obscure requirement (15.6.4 p2)

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 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.

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

Added: 
    

Modified: 
    flang/docs/Extensions.md
    flang/lib/Semantics/check-declarations.cpp
    flang/test/Semantics/stmt-func01.f90

Removed: 
    


################################################################################
diff  --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index c9793f89836ec..7f685c72eada3 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -84,6 +84,10 @@ end
   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 with a portability warning.
 
 ## Extensions, deletions, and legacy features supported by default
 

diff  --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 73477867b140e..8321bbc08b7a2 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -1044,6 +1044,15 @@ void CheckHelper::CheckSubprogram(
     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)) {

diff  --git a/flang/test/Semantics/stmt-func01.f90 b/flang/test/Semantics/stmt-func01.f90
index 5682cb97078b5..0f4fed51c1184 100644
--- a/flang/test/Semantics/stmt-func01.f90
+++ b/flang/test/Semantics/stmt-func01.f90
@@ -34,6 +34,7 @@ pure integer function ifunc()
   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 @@ pure function arr()
     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


        


More information about the flang-commits mailing list