[flang-commits] [flang] [flang] Initializers for proc pointers in module files (PR #170349)
via flang-commits
flang-commits at lists.llvm.org
Tue Dec 2 10:46:41 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
Default initializers for procedure pointer components are missing from module files; add them.
Fixes https://github.com/llvm/llvm-project/issues/170331.
---
Full diff: https://github.com/llvm/llvm-project/pull/170349.diff
2 Files Affected:
- (modified) flang/lib/Semantics/mod-file.cpp (+9)
- (added) flang/test/Semantics/modfile75.f90 (+28)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/170349
More information about the flang-commits
mailing list