[flang-commits] [flang] [flang] Insert NAMELIST variables into symbol table during Pre (PR #179599)

John Otken via flang-commits flang-commits at lists.llvm.org
Tue Feb 3 18:58:55 PST 2026


https://github.com/jotken updated https://github.com/llvm/llvm-project/pull/179599

>From 9fb7f581bb3deb4c5bfff18a03a97b75b4e12067 Mon Sep 17 00:00:00 2001
From: John Otken <john.otken at hpe.com>
Date: Tue, 3 Feb 2026 20:49:39 -0600
Subject: [PATCH] [flang] Insert NAMELIST variables into symbol table during
 Pre

Call ResolveName for each variable in a NAMELIST in Pre().  This generates errors for two
requirements in section 8.9 of the fortran standard.  Briefly, objects shall have their
declared type specified by previous statements or implicit rules.  If an object is typed
by the implicit rules, any subsequent type statement shall confirm the implied type.

Update test resolve40 s5 so that subsequent type statement confirms namelist implied type.

Co-authored-by: John Otken john.otken at hpe.com
---
 flang/lib/Semantics/resolve-names.cpp | 4 ++++
 flang/test/Semantics/resolve40.f90    | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index db84cc40c4283..efada9d6b5767 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -7195,6 +7195,10 @@ bool DeclarationVisitor::Pre(const parser::NamelistStmt::Group &x) {
     groupSymbol = &MakeSymbol(groupName, NamelistDetails{});
     groupSymbol->ReplaceName(groupName.source);
   }
+  // insert namelist variables into the symbol table
+  for (const auto &name : std::get<std::list<parser::Name>>(x.t)) {
+    ResolveName(name);
+  }
   // Name resolution of group items is deferred to FinishNamelists()
   // so that host association is handled correctly.
   GetDeferredDeclarationState(true)->namelistGroups.emplace_back(&x);
diff --git a/flang/test/Semantics/resolve40.f90 b/flang/test/Semantics/resolve40.f90
index 16b825250695e..466d704e9a46a 100644
--- a/flang/test/Semantics/resolve40.f90
+++ b/flang/test/Semantics/resolve40.f90
@@ -39,8 +39,8 @@ subroutine s4b
 end
 
 subroutine s5
-  namelist /nl/x
-  integer x
+  namelist /nl/i
+  integer i
 end
 
 subroutine s6



More information about the flang-commits mailing list