[flang-commits] [flang] [Flang] Fix statement-function shadowing to avoid false unresolved-symbol internal error (PR #189360)

CHANDRA GHALE via flang-commits flang-commits at lists.llvm.org
Mon Mar 30 08:57:16 PDT 2026


https://github.com/chandraghale updated https://github.com/llvm/llvm-project/pull/189360

>From 8d920eb9856542ab51950e9dafe339813eea7d50 Mon Sep 17 00:00:00 2001
From: Chandra Ghale <ghale at pe34genoa.hpc.amslabs.hpecorp.net>
Date: Mon, 30 Mar 2026 06:22:44 -0500
Subject: [PATCH] Fix statement-function shadowing to avoid false
 unresolved-symbol internal error

---
 flang/lib/Semantics/resolve-names.cpp |  1 +
 flang/test/Semantics/stmt-func02.f90  |  2 ++
 flang/test/Semantics/stmt-func03.f90  | 28 +++++++++++++++++++++++++++
 3 files changed, 31 insertions(+)
 create mode 100644 flang/test/Semantics/stmt-func03.f90

diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 164a9bedcc393..d2c4fde6f6c1a 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -4657,6 +4657,7 @@ bool SubprogramVisitor::HandleStmtFunction(const parser::StmtFunctionStmt &x) {
           "Name '%s' from host scope should have a type declaration before its local statement function definition"_port_en_US,
           name.source);
       MakeSymbol(name, Attrs{}, UnknownDetails{});
+      name.symbol = nullptr;
     } else if (auto *entity{ultimate.detailsIf<EntityDetails>()};
                entity && !ultimate.has<ProcEntityDetails>()) {
       resultType = entity->type();
diff --git a/flang/test/Semantics/stmt-func02.f90 b/flang/test/Semantics/stmt-func02.f90
index 10166a0abf7b1..d2c408b4dbb82 100644
--- a/flang/test/Semantics/stmt-func02.f90
+++ b/flang/test/Semantics/stmt-func02.f90
@@ -25,10 +25,12 @@ subroutine test1
   end
   subroutine test2
     !PORTABILITY: Name 'rf' from host scope should have a type declaration before its local statement function definition [-Wstatement-function-extensions]
+    !PORTABILITY: An implicitly typed statement function should not appear when the same symbol is available in its host scope [-Wstatement-function-extensions]
     rf(x) = 1.
   end
   subroutine test2b
     !PORTABILITY: Name 'rf2' from host scope should have a type declaration before its local statement function definition [-Wstatement-function-extensions]
+    !PORTABILITY: An implicitly typed statement function should not appear when the same symbol is available in its host scope [-Wstatement-function-extensions]
     rf2(x) = 1.
   end
   subroutine test3
diff --git a/flang/test/Semantics/stmt-func03.f90 b/flang/test/Semantics/stmt-func03.f90
new file mode 100644
index 0000000000000..c12ae5fc5439b
--- /dev/null
+++ b/flang/test/Semantics/stmt-func03.f90
@@ -0,0 +1,28 @@
+! RUN: %flang_fc1 -fsyntax-only -pedantic %s 2>&1 | FileCheck %s
+! CHECK-NOT: error:
+! CHECK-NOT: Internal:
+program main
+  integer :: passed, failed
+  passed = 0
+  failed = 0
+  call internal_sub()
+  call exit(failed)
+contains
+  subroutine internal_sub()
+    integer :: i, result
+    ! Host-associated sibling internal function name should be shadowed
+    ! by this statement function definition.
+    stmt_function(i) = i * 2
+    i = 1
+    result = stmt_function(i)
+    if (result .eq. 2) then
+      passed = passed + 1
+    else
+      failed = failed + 1
+    end if
+  end subroutine internal_sub
+  integer function stmt_function(arg)
+    integer :: arg
+    stmt_function = arg * 3
+  end function stmt_function
+end program main



More information about the flang-commits mailing list