Skip to content

Commit 39dd4eb

Browse files
committed
[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
1 parent f086f38 commit 39dd4eb

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4005,6 +4005,7 @@ bool SubprogramVisitor::BeginMpSubprogram(const parser::Name &name) {
40054005
// Convert the module procedure's interface into a subprogram.
40064006
SetScope(DEREF(symbol->scope()));
40074007
symbol->get<SubprogramDetails>().set_isInterface(false);
4008+
name.symbol = symbol;
40084009
} else {
40094010
// Copy the interface into a new subprogram scope.
40104011
EraseSymbol(name);
@@ -4025,7 +4026,8 @@ bool SubprogramVisitor::BeginSubprogram(const parser::Name &name,
40254026
Symbol::Flag subpFlag, bool hasModulePrefix,
40264027
const parser::LanguageBindingSpec *bindingSpec,
40274028
const ProgramTree::EntryStmtList *entryStmts) {
4028-
if (hasModulePrefix && currScope().IsGlobal()) { // C1547
4029+
if (hasModulePrefix && !currScope().IsModule() &&
4030+
!currScope().IsSubmodule()) { // C1547
40294031
Say(name,
40304032
"'%s' is a MODULE procedure which must be declared within a "
40314033
"MODULE or SUBMODULE"_err_en_US);

flang/test/Semantics/symbol28.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module subroutine s2 (j)
4343
end subroutine
4444
end interface
4545
contains
46-
!DEF: /m2/s MODULE SubprogramName
46+
!REF:/m2/s
4747
module procedure s
4848
end procedure
4949
!DEF: /m2/s2 MODULE, PUBLIC (Subroutine) Subprogram

0 commit comments

Comments
 (0)