[flang-commits] [flang] [flang] Initializers for proc pointers in module files (PR #170349)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Tue Dec 2 10:46:11 PST 2025


https://github.com/klausler created https://github.com/llvm/llvm-project/pull/170349

Default initializers for procedure pointer components are missing from module files; add them.

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

>From bb26ed064aeb4ebd993c3c8f74c03620c869afe7 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 2 Dec 2025 10:35:59 -0800
Subject: [PATCH] [flang] Initializers for proc pointers in module files

Default initializers for procedure pointer components are
missing from module files; add them.

Fixes https://github.com/llvm/llvm-project/issues/170331.
---
 flang/lib/Semantics/mod-file.cpp   |  9 +++++++++
 flang/test/Semantics/modfile75.f90 | 28 ++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)
 create mode 100644 flang/test/Semantics/modfile75.f90

diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp
index 840b98dd42139..759b66ca27016 100644
--- a/flang/lib/Semantics/mod-file.cpp
+++ b/flang/lib/Semantics/mod-file.cpp
@@ -1069,6 +1069,15 @@ void ModFileWriter::PutProcEntity(llvm::raw_ostream &os, const Symbol &symbol) {
         PutPassName(os, details.passName());
       },
       attrs);
+  if (symbol.owner().IsDerivedType()) {
+    if (const auto &init{details.init()}) {
+      if (const Symbol *symbol{*init}) {
+        os << "=>" << symbol->name();
+      } else {
+        os << "=>NULL()";
+      }
+    }
+  }
   os << '\n';
 }
 
diff --git a/flang/test/Semantics/modfile75.f90 b/flang/test/Semantics/modfile75.f90
new file mode 100644
index 0000000000000..e1f4db4051bbe
--- /dev/null
+++ b/flang/test/Semantics/modfile75.f90
@@ -0,0 +1,28 @@
+! RUN: %python %S/test_modfile.py %s %flang_fc1
+module m
+  type dt
+    procedure(sub), pointer, nopass :: p1 => sub
+    procedure(sub), pointer, nopass :: p2 => null()
+    procedure(sub), pointer, nopass :: p3
+  end type
+  procedure(sub), pointer :: p4 => sub
+  procedure(sub), pointer :: p5 => null()
+ contains
+  subroutine sub
+  end
+end
+
+!Expect: m.mod
+!module m
+!type::dt
+!procedure(sub),nopass,pointer::p1=>sub
+!procedure(sub),nopass,pointer::p2=>NULL()
+!procedure(sub),nopass,pointer::p3
+!end type
+!intrinsic::null
+!procedure(sub),pointer::p4
+!procedure(sub),pointer::p5
+!contains
+!subroutine sub()
+!end
+!end



More information about the flang-commits mailing list