[flang-commits] [flang] [flang] Fix crash in module file generation (PR #123859)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Tue Jan 21 16:29:22 PST 2025


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

An assertion in module file generation didn't allow for a case that has arisen in a test; remove it, extend commentary, and add a regression test.

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

>From 801ddca41ef1ecb179b767b740d258c57efd5e4f Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 21 Jan 2025 16:26:48 -0800
Subject: [PATCH] [flang] Fix crash in module file generation

An assertion in module file generation didn't allow for a
case that has arisen in a test; remove it, extend commentary,
and add a regression test.

Fixes https://github.com/llvm/llvm-project/issues/123534.
---
 flang/lib/Semantics/mod-file.cpp   |  4 ++--
 flang/test/Semantics/bug123534.f90 | 33 ++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 2 deletions(-)
 create mode 100644 flang/test/Semantics/bug123534.f90

diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp
index 51ff70c3ed8341..848a1c9b689655 100644
--- a/flang/lib/Semantics/mod-file.cpp
+++ b/flang/lib/Semantics/mod-file.cpp
@@ -1780,8 +1780,8 @@ bool SubprogramSymbolCollector::NeedImport(
     return found->has<UseDetails>() && found->owner() != scope_;
   } else {
     // "found" can be null in the case of a use-associated derived type's
-    // parent type
-    CHECK(symbol.has<DerivedTypeDetails>());
+    // parent type, and also in the case of an object (like a dummy argument)
+    // used to define a length or bound of a nested interface.
     return false;
   }
 }
diff --git a/flang/test/Semantics/bug123534.f90 b/flang/test/Semantics/bug123534.f90
new file mode 100644
index 00000000000000..0a94336732110f
--- /dev/null
+++ b/flang/test/Semantics/bug123534.f90
@@ -0,0 +1,33 @@
+! RUN: %python %S/test_modfile.py %s %flang_fc1
+! Simplified regression test for crashreported in
+! https://github.com/llvm/llvm-project/issues/123534.
+module m
+  interface
+    ! f1 returns a pointer to a procedure whose result characteristics
+    ! depend on the value of a dummy argument.
+    function f1()
+      interface
+        function f2(n)
+          integer, intent(in) :: n
+          character(n), pointer :: f2
+        end
+      end interface
+      procedure (f2), pointer :: f1
+    end
+  end interface
+end
+
+!Expect: m.mod
+!module m
+!interface
+!function f1()
+!interface
+!function f2(n)
+!integer(4),intent(in)::n
+!character(n,1),pointer::f2
+!end
+!end interface
+!procedure(f2),pointer::f1
+!end
+!end interface
+!end



More information about the flang-commits mailing list