[flang-commits] [flang] [flang] Handle useless NAMELIST in interface block (PR #175214)

via flang-commits flang-commits at lists.llvm.org
Fri Jan 9 09:45:01 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

NAMELIST has no useful purpose in an interface block, but it's allowed.  Fix a crash due to our deferred handling of NAMELIST groups in the execution part (which doesn't exist in an interface block).

Fixes https://github.com/llvm/llvm-project/issues/175207.

---
Full diff: https://github.com/llvm/llvm-project/pull/175214.diff


2 Files Affected:

- (modified) flang/lib/Semantics/resolve-names.cpp (+3) 
- (added) flang/test/Semantics/bug175207.f90 (+10) 


``````````diff
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index ae251476ed591..148cc439efa88 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -9872,6 +9872,9 @@ void ResolveNamesVisitor::FinishSpecificationPart(
   misparsedStmtFuncFound_ = false;
   funcResultStack().CompleteFunctionResultType();
   CheckImports();
+  if (inInterfaceBlock()) {
+    FinishNamelists(); // NAMELIST is useless in an interface, but allowed
+  }
   for (auto &pair : currScope()) {
     auto &symbol{*pair.second};
     if (inInterfaceBlock()) {
diff --git a/flang/test/Semantics/bug175207.f90 b/flang/test/Semantics/bug175207.f90
new file mode 100644
index 0000000000000..63696dfac0b63
--- /dev/null
+++ b/flang/test/Semantics/bug175207.f90
@@ -0,0 +1,10 @@
+!RUN: %python %S/test_errors.py %s %flang_fc1
+interface
+  subroutine sub(x)
+    real x
+    namelist /useless/x ! ok, but don't crash
+    !ERROR: 'sub' is not a variable
+    namelist /bad/sub
+  end
+end interface
+end

``````````

</details>


https://github.com/llvm/llvm-project/pull/175214


More information about the flang-commits mailing list