[flang-commits] [flang] [flang] Fix symbol on module subroutine name with same name as generic (PR #67678)

via flang-commits flang-commits at lists.llvm.org
Thu Sep 28 06:46:58 PDT 2023


https://github.com/jeanPerier created https://github.com/llvm/llvm-project/pull/67678

When a MODULE SUBROUTINE or MODULE FUNCTION is implemented in the same scope as its interface and appears in a generic with the same name, the parse::Name of the implementation was not correctly reset and remained the SubprogramNameDetails symbol after semantics, causing a crash in lowering that picks up the procedure symbols on the parser names.

Reset the parser::Name symbol before the new symbol is created.

>From 9276d62f5c458a1ef591df2a0a2fab4c5a548ff2 Mon Sep 17 00:00:00 2001
From: Jean Perier <jperier at nvidia.com>
Date: Thu, 28 Sep 2023 06:38:07 -0700
Subject: [PATCH] [flang] Fix symbol on module subroutine name with same name
 as generic

When a MODULE SUBROUTINE or MODULE FUNCTION is implemented in the same
scope as its interface and appears in a generic with the same name, the
parse::Name of the implementation was not correctly reset and remained
the SubprogramNameDetails symbol after semantics, causing a crash in
lowering that picks up the procedure symbols on the parser names.

Reset the parser::Name symbol before the new symbol is created.
---
 flang/lib/Semantics/resolve-names.cpp | 1 +
 flang/test/Semantics/symbol28.f90     | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 22e52521e188362..40f5ab9eb6e27ca 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -4111,6 +4111,7 @@ bool SubprogramVisitor::BeginSubprogram(const parser::Name &name,
       if (GenericDetails *
           generic{DEREF(FindSymbol(name)).detailsIf<GenericDetails>()}) {
         generic->clear_specific();
+        name.symbol = nullptr;
       } else {
         EraseSymbol(name);
       }
diff --git a/flang/test/Semantics/symbol28.f90 b/flang/test/Semantics/symbol28.f90
index ab18749e6bd44b4..2bfe4e3a8c4c293 100644
--- a/flang/test/Semantics/symbol28.f90
+++ b/flang/test/Semantics/symbol28.f90
@@ -14,7 +14,7 @@ module subroutine s2 (j)
   end subroutine
  end interface
 contains
- !DEF: /m1/s MODULE (Subroutine) SubprogramName
+ !DEF: /m1/s MODULE (Subroutine) Subprogram
  module subroutine s
  end subroutine
  !REF: /m1/s2



More information about the flang-commits mailing list