Skip to content

Conversation

@klausler
Copy link
Contributor

@klausler klausler commented Dec 2, 2025

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

Fixes #170331.

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

Fixes llvm#170331.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Dec 2, 2025
@llvmbot
Copy link
Member

llvmbot commented Dec 2, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

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

Fixes #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 --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

@klausler klausler merged commit 6a41ace into llvm:main Dec 12, 2025
13 checks passed
@klausler klausler deleted the bug170331 branch December 12, 2025 23:01
@lhames
Copy link
Contributor

lhames commented Dec 13, 2025

@klausler This commit is causing issues on macOS:

% git co 6a41ace~1                        
HEAD is now at 6f1e3c396812 [alpha.webkit.UncountedLocalVarsChecker] Ignore a VarDecl in "if" with trivial "then" (#171764)
% git stat
HEAD detached at 6f1e3c396812
nothing added to commit but untracked files present (use "git add" to track)
% git co  6a41ace
Previous HEAD position was 6f1e3c396812 [alpha.webkit.UncountedLocalVarsChecker] Ignore a VarDecl in "if" with trivial "then" (#171764)
HEAD is now at 6a41acef89b4 [flang] Initializers for proc pointers in module files (#170349)
% git stat
HEAD detached at 6a41acef89b4
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   flang/test/Semantics/modfile75.F90

no changes added to commit (use "git add" and/or "git commit -a")

The newly introduced flang/test/Semantics/modfile75.f90 path differs from an existing flang/test/Semantics/modfile75.F90 testcase path only by case f (f90 vs F90), which causes problems on macOS's filesystem. Can the testcase be renamed?

fhahn added a commit that referenced this pull request Dec 13, 2025
There is already a modfile75.F90 test, and the new test added in
#170349 breaks git on macOS.
Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed the test in 3afa68f, as this pretty much breaks any git operation on macOS

llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Dec 13, 2025
There is already a modfile75.F90 test, and the new test added in
llvm/llvm-project#170349 breaks git on macOS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flang] Default initialization of derived type procedure pointer component fails across file boundaries

6 participants