[flang-commits] [flang] c93312a - [flang] Handle USE-associated symbols in module procedure interface b… (#93616)
via flang-commits
flang-commits at lists.llvm.org
Mon Jun 3 13:13:19 PDT 2024
Author: Peter Klausler
Date: 2024-06-03T13:13:16-07:00
New Revision: c93312a63db8e8c87b14e1828c5a4d1eac5aac20
URL: https://github.com/llvm/llvm-project/commit/c93312a63db8e8c87b14e1828c5a4d1eac5aac20
DIFF: https://github.com/llvm/llvm-project/commit/c93312a63db8e8c87b14e1828c5a4d1eac5aac20.diff
LOG: [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 https://github.com/llvm/llvm-project/issues/93413.
Added:
Modified:
flang/lib/Semantics/resolve-names-utils.cpp
flang/test/Semantics/resolve118.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/resolve-names-utils.cpp b/flang/lib/Semantics/resolve-names-utils.cpp
index e27a54361749f..39392257938d6 100644
--- a/flang/lib/Semantics/resolve-names-utils.cpp
+++ b/flang/lib/Semantics/resolve-names-utils.cpp
@@ -710,13 +710,15 @@ class SymbolMapper : public evaluate::AnyTraverse<SymbolMapper, bool> {
SymbolMapper(Scope &scope, SymbolAndTypeMappings &map)
: Base{*this}, scope_{scope}, map_{map} {}
using Base::operator();
- bool operator()(const SymbolRef &ref) const {
+ bool operator()(const SymbolRef &ref) {
if (const Symbol *mapped{MapSymbol(*ref)}) {
const_cast<SymbolRef &>(ref) = *mapped;
+ } else if (ref->has<UseDetails>()) {
+ CopySymbol(&*ref);
}
return false;
}
- bool operator()(const Symbol &x) const {
+ bool operator()(const Symbol &x) {
if (MapSymbol(x)) {
DIE("SymbolMapper hit symbol outside SymbolRef");
}
@@ -726,9 +728,9 @@ class SymbolMapper : public evaluate::AnyTraverse<SymbolMapper, bool> {
Symbol *CopySymbol(const Symbol *);
private:
- void MapParamValue(ParamValue ¶m) const { (*this)(param.GetExplicit()); }
- void MapBound(Bound &bound) const { (*this)(bound.GetExplicit()); }
- void MapShapeSpec(ShapeSpec &spec) const {
+ void MapParamValue(ParamValue ¶m) { (*this)(param.GetExplicit()); }
+ void MapBound(Bound &bound) { (*this)(bound.GetExplicit()); }
+ void MapShapeSpec(ShapeSpec &spec) {
MapBound(spec.lbound());
MapBound(spec.ubound());
}
diff --git a/flang/test/Semantics/resolve118.f90 b/flang/test/Semantics/resolve118.f90
index 11fa18255f045..024b67b5a471b 100644
--- a/flang/test/Semantics/resolve118.f90
+++ b/flang/test/Semantics/resolve118.f90
@@ -57,3 +57,26 @@ subroutine s4(x)
subroutine t
end
end module
+
+module m6a
+ integer :: i = 7
+end module
+
+module m6b
+ interface
+ module subroutine sub(arg)
+ interface
+ integer function arg(x)
+ use m6a, only: i
+ real :: x(i) ! ok
+ end
+ end interface
+ end
+ end interface
+end module
+
+submodule (m6b) m6bs1
+ contains
+ module procedure sub
+ end
+end submodule
More information about the flang-commits
mailing list