[flang-commits] [PATCH] D157337: [flang] Fix bogus error on recursive ENTRY

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Aug 7 15:00:23 PDT 2023


klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

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.


https://reviews.llvm.org/D157337

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


Index: flang/test/Semantics/global01.f90
===================================================================
--- flang/test/Semantics/global01.f90
+++ flang/test/Semantics/global01.f90
@@ -21,6 +21,13 @@
   integer, intent(in) :: x
 end subroutine
 
+! Regression check: don't emit bogus "Implicit declaration of function 'global7' has a different 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 @@
     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
-
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -7621,9 +7621,13 @@
 
 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(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157337.547964.patch
Type: text/x-patch
Size: 1807 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230807/f6526253/attachment-0001.bin>


More information about the flang-commits mailing list