[flang-commits] [flang] 39dd4eb - [flang] Prevent lowering crash by properly updating symbol pointer

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Mon Jul 3 12:10:58 PDT 2023


Author: Peter Klausler
Date: 2023-07-03T12:10:49-07:00
New Revision: 39dd4ebd2b63daf4f5e3d44040f53331fce3b966

URL: https://github.com/llvm/llvm-project/commit/39dd4ebd2b63daf4f5e3d44040f53331fce3b966
DIFF: https://github.com/llvm/llvm-project/commit/39dd4ebd2b63daf4f5e3d44040f53331fce3b966.diff

LOG: [flang] Prevent lowering crash by properly updating symbol pointer

Kind of an edge case.  When a MODULE FUNCTION or SUBROUTINE
interface is defined by a MODULE PROCEDURE in the same program
unit, ensure that the symbol table pointer in the parse tree is
updated to point to the SubprogramDetails symbol for the
interface, and not left pointing to what should soon become
a dead SubprogramNameDetails symbol.

Differential Revision: https://reviews.llvm.org/D154380

Added: 
    

Modified: 
    flang/lib/Semantics/resolve-names.cpp
    flang/test/Semantics/symbol28.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index f21aba59c7c505..78b07f098cd57a 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -4005,6 +4005,7 @@ bool SubprogramVisitor::BeginMpSubprogram(const parser::Name &name) {
     // Convert the module procedure's interface into a subprogram.
     SetScope(DEREF(symbol->scope()));
     symbol->get<SubprogramDetails>().set_isInterface(false);
+    name.symbol = symbol;
   } else {
     // Copy the interface into a new subprogram scope.
     EraseSymbol(name);
@@ -4025,7 +4026,8 @@ bool SubprogramVisitor::BeginSubprogram(const parser::Name &name,
     Symbol::Flag subpFlag, bool hasModulePrefix,
     const parser::LanguageBindingSpec *bindingSpec,
     const ProgramTree::EntryStmtList *entryStmts) {
-  if (hasModulePrefix && currScope().IsGlobal()) { // C1547
+  if (hasModulePrefix && !currScope().IsModule() &&
+      !currScope().IsSubmodule()) { // C1547
     Say(name,
         "'%s' is a MODULE procedure which must be declared within a "
         "MODULE or SUBMODULE"_err_en_US);

diff  --git a/flang/test/Semantics/symbol28.f90 b/flang/test/Semantics/symbol28.f90
index 83fb370664bb0a..ab18749e6bd44b 100644
--- a/flang/test/Semantics/symbol28.f90
+++ b/flang/test/Semantics/symbol28.f90
@@ -43,7 +43,7 @@ module subroutine s2 (j)
   end subroutine
  end interface
 contains
- !DEF: /m2/s MODULE SubprogramName
+ !REF:/m2/s
  module procedure s
  end procedure
  !DEF: /m2/s2 MODULE, PUBLIC (Subroutine) Subprogram


        


More information about the flang-commits mailing list