[flang-commits] [flang] 37d6c1c - [flang] Fix bogus error on recursive ENTRY

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Tue Aug 8 11:26:11 PDT 2023


Author: Peter Klausler
Date: 2023-08-08T11:14:58-07:00
New Revision: 37d6c1cc7d4dd3a8a47ba62254bc88521bd50d66

URL: https://github.com/llvm/llvm-project/commit/37d6c1cc7d4dd3a8a47ba62254bc88521bd50d66
DIFF: https://github.com/llvm/llvm-project/commit/37d6c1cc7d4dd3a8a47ba62254bc88521bd50d66.diff

LOG: [flang] Fix bogus error on recursive ENTRY

An incorrect "Implicit declaration of function '...' has a different result type
than in previous declaration" is being emitted for ENTRY names used
recursively.  The predicate used to check for recursive use only allowed
for scopes of functions, not ENTRYs.

Fixes llvm-test-suite/Fortran/gfortran/regression/whole_file_9.f90.

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

Added: 
    

Modified: 
    flang/lib/Semantics/resolve-names.cpp
    flang/test/Semantics/global01.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index b6e0bf19730c3e..db3a68fbc0f65a 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -7633,9 +7633,13 @@ void ResolveNamesVisitor::NoteExecutablePartCall(
 
 static bool IsLocallyImplicitGlobalSymbol(
     const Symbol &symbol, const parser::Name &localName) {
-  return symbol.owner().IsGlobal() &&
-      (!symbol.scope() ||
-          !symbol.scope()->sourceRange().Contains(localName.source));
+  if (symbol.owner().IsGlobal()) {
+    const auto *subp{symbol.detailsIf<SubprogramDetails>()};
+    const Scope *scope{
+        subp && subp->entryScope() ? subp->entryScope() : symbol.scope()};
+    return !(scope && scope->sourceRange().Contains(localName.source));
+  }
+  return false;
 }
 
 static bool TypesMismatchIfNonNull(

diff  --git a/flang/test/Semantics/global01.f90 b/flang/test/Semantics/global01.f90
index 752c902c2c7213..ab3edf9ef805f4 100644
--- a/flang/test/Semantics/global01.f90
+++ b/flang/test/Semantics/global01.f90
@@ -21,6 +21,13 @@ subroutine global5(x)
   integer, intent(in) :: x
 end subroutine
 
+! Regression check: don't emit bogus "Implicit declaration of function 'global7' has a 
diff erent result type than in previous declaration"
+recursive function global6()
+  integer global6, z, n
+entry global7(n) result(z)
+  if (n > 0) z = global7(n-1)
+end function
+
 program test
   interface
     !WARNING: The global subprogram 'global1' is not compatible with its local procedure declaration (incompatible dummy argument #1: incompatible dummy data object types: INTEGER(4) vs REAL(4))
@@ -40,6 +47,11 @@ subroutine global4(x) ! not PURE, but that's ok
     pure subroutine global5(x)
       integer, intent(in) :: x
     end subroutine
+    function global6()
+      integer global6
+    end function
+    function global7(n) result(z)
+      integer n, z
+    end function
   end interface
 end
-


        


More information about the flang-commits mailing list