Skip to content

Commit c93312a

Browse files
authored
[flang] Handle USE-associated symbols in module procedure interface b… (#93616)
…lock specification expressions A subroutine or function interface block is of course allowed to USE-associate symbols into its scope and use them for specification expressions. This usage works, but crashes the module file output generator. Fix. Fixes #93413.
1 parent e783d5d commit c93312a

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

flang/lib/Semantics/resolve-names-utils.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -710,13 +710,15 @@ class SymbolMapper : public evaluate::AnyTraverse<SymbolMapper, bool> {
710710
SymbolMapper(Scope &scope, SymbolAndTypeMappings &map)
711711
: Base{*this}, scope_{scope}, map_{map} {}
712712
using Base::operator();
713-
bool operator()(const SymbolRef &ref) const {
713+
bool operator()(const SymbolRef &ref) {
714714
if (const Symbol *mapped{MapSymbol(*ref)}) {
715715
const_cast<SymbolRef &>(ref) = *mapped;
716+
} else if (ref->has<UseDetails>()) {
717+
CopySymbol(&*ref);
716718
}
717719
return false;
718720
}
719-
bool operator()(const Symbol &x) const {
721+
bool operator()(const Symbol &x) {
720722
if (MapSymbol(x)) {
721723
DIE("SymbolMapper hit symbol outside SymbolRef");
722724
}
@@ -726,9 +728,9 @@ class SymbolMapper : public evaluate::AnyTraverse<SymbolMapper, bool> {
726728
Symbol *CopySymbol(const Symbol *);
727729

728730
private:
729-
void MapParamValue(ParamValue &param) const { (*this)(param.GetExplicit()); }
730-
void MapBound(Bound &bound) const { (*this)(bound.GetExplicit()); }
731-
void MapShapeSpec(ShapeSpec &spec) const {
731+
void MapParamValue(ParamValue &param) { (*this)(param.GetExplicit()); }
732+
void MapBound(Bound &bound) { (*this)(bound.GetExplicit()); }
733+
void MapShapeSpec(ShapeSpec &spec) {
732734
MapBound(spec.lbound());
733735
MapBound(spec.ubound());
734736
}

flang/test/Semantics/resolve118.f90

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,26 @@ subroutine s4(x)
5757
subroutine t
5858
end
5959
end module
60+
61+
module m6a
62+
integer :: i = 7
63+
end module
64+
65+
module m6b
66+
interface
67+
module subroutine sub(arg)
68+
interface
69+
integer function arg(x)
70+
use m6a, only: i
71+
real :: x(i) ! ok
72+
end
73+
end interface
74+
end
75+
end interface
76+
end module
77+
78+
submodule (m6b) m6bs1
79+
contains
80+
module procedure sub
81+
end
82+
end submodule

0 commit comments

Comments
 (0)