[flang-commits] [flang] [flang] Don't defer namelist processing under -pedantic (PR #188854)

via flang-commits flang-commits at lists.llvm.org
Thu Mar 26 14:51:13 PDT 2026


https://github.com/ivanrodriguez3753 created https://github.com/llvm/llvm-project/pull/188854

Implementation started on the following PR by @jotken: https://github.com/llvm/llvm-project/pull/179599
This PR applies the suggested comments, namely, put this restriction behind `-pedantic` flag (or `-Wno-namelist-no-defer` if you want to enable this without everything else under `-pedantic`). 

There were 3 other tests using namelists and -pedantic, so this new message caused them to fail. Disable on those tests using `-Wno-namelist-no-defer`. 

>From 0462da4d67d6c98ff2c12d5c18b0678590177c0e Mon Sep 17 00:00:00 2001
From: Ivan Rodriguez <ivan.rodriguez at hpe.com>
Date: Thu, 26 Mar 2026 16:43:47 -0500
Subject: [PATCH 1/2] Don't defer namelist processing under -pedantic

---
 flang/include/flang/Support/Fortran-features.h |  2 +-
 flang/lib/Semantics/resolve-names.cpp          |  8 ++++++++
 flang/test/Semantics/io16.f90                  |  2 +-
 flang/test/Semantics/namelist02.f90            |  2 +-
 flang/test/Semantics/namelist03.f90            | 14 ++++++++++++++
 flang/test/Semantics/pointer01.f90             |  2 +-
 6 files changed, 26 insertions(+), 4 deletions(-)
 create mode 100644 flang/test/Semantics/namelist03.f90

diff --git a/flang/include/flang/Support/Fortran-features.h b/flang/include/flang/Support/Fortran-features.h
index f2bd0d21f25b6..1e0e14ed21ce2 100644
--- a/flang/include/flang/Support/Fortran-features.h
+++ b/flang/include/flang/Support/Fortran-features.h
@@ -84,7 +84,7 @@ ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,
     HostAssociatedIntentOutInSpecExpr, NonVolatilePointerToVolatile,
     RealConstantWidening, VolatileOrAsynchronousTemporary, UnusedVariable,
     UsedUndefinedVariable, BadValueInDeadCode, AssumedTypeSizeDummy,
-    MisplacedIgnoreTKR, NamelistParameter, ImpureFinalInPure)
+    MisplacedIgnoreTKR, NamelistParameter, ImpureFinalInPure, NamelistNoDefer)
 
 using LanguageFeatures = EnumSet<LanguageFeature, LanguageFeature_enumSize>;
 using UsageWarnings = EnumSet<UsageWarning, UsageWarning_enumSize>;
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index b6907cc792d76..a658d6c1cd077 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -7239,6 +7239,14 @@ bool DeclarationVisitor::Pre(const parser::NamelistStmt::Group &x) {
     groupSymbol = &MakeSymbol(groupName, NamelistDetails{});
     groupSymbol->ReplaceName(groupName.source);
   }
+  // don't defer namelist processing with -pedantic
+  if(context().ShouldWarn(common::UsageWarning::NamelistNoDefer)) {
+    context().Warn(common::UsageWarning::NamelistNoDefer, "Namelist processing not deferred"_port_en_US);
+    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/io16.f90 b/flang/test/Semantics/io16.f90
index 7d721d2ba40dc..de00988ae30ce 100644
--- a/flang/test/Semantics/io16.f90
+++ b/flang/test/Semantics/io16.f90
@@ -1,4 +1,4 @@
-! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
+! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic -Wno-namelist-no-defer
 subroutine assumedRank(x, y)
   real x(..), y(*)
   !PORTABILITY: Assumed-rank object 'x' should not be a namelist group item [-Wassumed-rank-io-item]
diff --git a/flang/test/Semantics/namelist02.f90 b/flang/test/Semantics/namelist02.f90
index efe1f0204abd1..cdbd78c4db6a8 100644
--- a/flang/test/Semantics/namelist02.f90
+++ b/flang/test/Semantics/namelist02.f90
@@ -1,4 +1,4 @@
-! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic -Werror
+! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic -Werror -Wno-namelist-no-defer
 
 module m
   implicit none
diff --git a/flang/test/Semantics/namelist03.f90 b/flang/test/Semantics/namelist03.f90
new file mode 100644
index 0000000000000..d37a0fda2f6e7
--- /dev/null
+++ b/flang/test/Semantics/namelist03.f90
@@ -0,0 +1,14 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
+! Namelist processing deferred under -pedantic. Therefore,
+! x should be implicitly (default) typed as a real, and i
+! should be implicitly typed as an integer (because it starts
+! with i-n). Both should print a type error at their explicit
+! declarations which must agree with their implicit typing.
+subroutine s 
+  !PORTABILITY: Namelist processing not deferred [-Wnamelist-no-defer]
+  namelist /nl/ x, i 
+  !ERROR: The type of 'x' has already been implicitly declared as REAL(4)
+  integer :: x 
+  !ERROR: The type of 'i' has already been implicitly declared as INTEGER(4)
+  real :: i
+end subroutine 
diff --git a/flang/test/Semantics/pointer01.f90 b/flang/test/Semantics/pointer01.f90
index 79d6016a6af46..cec9a32e600f4 100644
--- a/flang/test/Semantics/pointer01.f90
+++ b/flang/test/Semantics/pointer01.f90
@@ -1,4 +1,4 @@
-! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
+! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic -Wno-namelist-no-defer
 module m
   real mobj
  contains

>From 81250399a253ed0a21541760f2eea68ef2d3757b Mon Sep 17 00:00:00 2001
From: Ivan Rodriguez <ivan.rodriguez at hpe.com>
Date: Thu, 26 Mar 2026 16:48:45 -0500
Subject: [PATCH 2/2] Document flag in Extensions.md

---
 flang/docs/Extensions.md | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index f2770f0a7271a..3627df06ec4e5 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -833,7 +833,8 @@ end module
   has resolved all of the names in that scope.  This means that names
   that appear before their local declarations do not resolve to host
   associated objects and do not elicit errors about improper redeclarations
-  of implicitly typed entities.
+  of implicitly typed entities. This can be disabled with `-Wno-namelist-no-defer`,
+  which is implicitly enabled under `-pedantic`.
 
 * Standard Fortran allows forward references to derived types, which
   can lead to ambiguity when combined with host association.



More information about the flang-commits mailing list