[flang-commits] [flang] 0d6f658 - [flang] Catch recursive call to non_recursive ENTRY (#182971)

via flang-commits flang-commits at lists.llvm.org
Thu Feb 26 07:01:23 PST 2026


Author: Peter Klausler
Date: 2026-02-26T07:01:18-08:00
New Revision: 0d6f6584622fee13f003bc4be8fe21532163ba40

URL: https://github.com/llvm/llvm-project/commit/0d6f6584622fee13f003bc4be8fe21532163ba40
DIFF: https://github.com/llvm/llvm-project/commit/0d6f6584622fee13f003bc4be8fe21532163ba40.diff

LOG: [flang] Catch recursive call to non_recursive ENTRY (#182971)

The check for a recursive call to a non-recursive subprogram doesn't
allow for the case of an alternate ENTRY point.

Added: 
    

Modified: 
    flang/lib/Semantics/expression.cpp
    flang/test/Semantics/call01.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index 81603b8c20ce3..49c092b306e25 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -3316,6 +3316,12 @@ void ExpressionAnalyzer::CheckBadExplicitType(
 
 void ExpressionAnalyzer::CheckForBadRecursion(
     parser::CharBlock callSite, const semantics::Symbol &proc) {
+  if (const Symbol *mainEntry{GetMainEntry(&proc)}) {
+    if (mainEntry != &proc) {
+      CheckForBadRecursion(callSite, *mainEntry);
+      return;
+    }
+  }
   if (const auto *scope{proc.scope()}) {
     if (scope->sourceRange().Contains(callSite)) {
       parser::Message *msg{nullptr};

diff  --git a/flang/test/Semantics/call01.f90 b/flang/test/Semantics/call01.f90
index 6849c5f6500b1..000fe2e857a3d 100644
--- a/flang/test/Semantics/call01.f90
+++ b/flang/test/Semantics/call01.f90
@@ -4,11 +4,14 @@
 non_recursive function f01(n) result(res)
   integer, value :: n
   integer :: res
+  entry f01b(n) result(res)
   if (n <= 0) then
     res = n
   else
     !ERROR: NON_RECURSIVE procedure 'f01' cannot call itself
     res = n * f01(n-1) ! 15.6.2.1(3)
+    !ERROR: NON_RECURSIVE procedure 'f01b' cannot call itself
+    res = n * f01b(n-1) ! 15.6.2.1(3)
   end if
 end function
 


        


More information about the flang-commits mailing list