Skip to content

Conversation

@klausler
Copy link
Contributor

When a separate module procedure is defined with MODULE PROCEDURE, the compiler crashes if there is a dummy procedure in the interface defined with only a result type. This is due to the type already having been defined on the ProcEntityDetails symbol as part of earlier wholesale symbol duplication. Adjust the code to not define the result type of the ProcEntityDetails if it is already present, but to verify that it is the same type instead.

Fixes #124487.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Jan 28, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 28, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

When a separate module procedure is defined with MODULE PROCEDURE, the compiler crashes if there is a dummy procedure in the interface defined with only a result type. This is due to the type already having been defined on the ProcEntityDetails symbol as part of earlier wholesale symbol duplication. Adjust the code to not define the result type of the ProcEntityDetails if it is already present, but to verify that it is the same type instead.

Fixes #124487.


Full diff: https://github.com/llvm/llvm-project/pull/124663.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-names-utils.cpp (+5-1)
  • (added) flang/test/Semantics/bug124487.f90 (+13)
diff --git a/flang/lib/Semantics/resolve-names-utils.cpp b/flang/lib/Semantics/resolve-names-utils.cpp
index a838d49c06104d..347f54e0640705 100644
--- a/flang/lib/Semantics/resolve-names-utils.cpp
+++ b/flang/lib/Semantics/resolve-names-utils.cpp
@@ -762,7 +762,11 @@ void SymbolMapper::MapSymbolExprs(Symbol &symbol) {
               proc.set_procInterfaces(
                   *mappedSymbol, BypassGeneric(mappedSymbol->GetUltimate()));
             } else if (const DeclTypeSpec * mappedType{MapType(proc.type())}) {
-              proc.set_type(*mappedType);
+              if (proc.type()) {
+                CHECK(*proc.type() == *mappedType);
+              } else {
+                proc.set_type(*mappedType);
+              }
             }
             if (proc.init()) {
               if (const Symbol * mapped{MapSymbol(*proc.init())}) {
diff --git a/flang/test/Semantics/bug124487.f90 b/flang/test/Semantics/bug124487.f90
new file mode 100644
index 00000000000000..867f6e30beb5d1
--- /dev/null
+++ b/flang/test/Semantics/bug124487.f90
@@ -0,0 +1,13 @@
+!RUN: %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck --allow-empty %s
+module m
+  interface
+    module subroutine smp(x)
+      character, external :: x
+    end
+  end interface
+end
+submodule (m) sm
+ contains
+  module procedure smp ! crashes here
+  end
+end

When a separate module procedure is defined with MODULE PROCEDURE,
the compiler crashes if there is a dummy procedure in the interface
defined with only a result type.  This is due to the type already
having been defined on the ProcEntityDetails symbol as part of earlier
wholesale symbol duplication.  Adjust the code to not define the
result type of the ProcEntityDetails if it is already present,
but to verify that it is the same type instead.

Fixes llvm#124487.
@klausler klausler merged commit 36caa8f into llvm:main Jan 31, 2025
8 checks passed
@klausler klausler deleted the bug124487 branch January 31, 2025 18:52
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

3 participants