Skip to content

Commit 74f4034

Browse files
authored
[flang] Fix type inheritance for statement function dummy arguments (#93624)
The code that used existing type declarations (if any) for the names being used as dummy arguments in a statement function definition would apply those types only if they came from EntityDetails symbols. This broke a case in which the type was being inherited from a Cray pointee. Fixes #93484.
1 parent 037a052 commit 74f4034

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3700,10 +3700,8 @@ bool SubprogramVisitor::HandleStmtFunction(const parser::StmtFunctionStmt &x) {
37003700
for (const auto &dummyName : std::get<std::list<parser::Name>>(x.t)) {
37013701
ObjectEntityDetails dummyDetails{true};
37023702
if (auto *dummySymbol{FindInScope(currScope().parent(), dummyName)}) {
3703-
if (auto *d{dummySymbol->detailsIf<EntityDetails>()}) {
3704-
if (d->type()) {
3705-
dummyDetails.set_type(*d->type());
3706-
}
3703+
if (auto *d{dummySymbol->GetType()}) {
3704+
dummyDetails.set_type(*d);
37073705
}
37083706
}
37093707
Symbol &dummy{MakeSymbol(dummyName, std::move(dummyDetails))};

flang/test/Semantics/stmt-func01.f90

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ pure integer function ifunc()
3737
!ERROR: Statement function 'sf10' may not reference another statement function 'sf11' that is defined later
3838
sf10(n) = sf11(n)
3939
sf11(n) = sf10(n) ! mutual recursion, caused crash
40-
sf13 = 1.
40+
integer(1) iarg1
41+
!PORTABILITY: nonstandard usage: based POINTER
42+
pointer(iarg1p, iarg1)
43+
sf13(iarg1) = iarg1
44+
! executable part
45+
print *, sf13(iarg1) ! ok
46+
sf14 = 1.
4147
contains
4248
real function explicit(x,y)
4349
integer, intent(in) :: x
@@ -50,7 +56,7 @@ pure function arr()
5056
end function
5157
subroutine foo
5258
!PORTABILITY: An implicitly typed statement function should not appear when the same symbol is available in its host scope
53-
sf13(x) = 2.*x
59+
sf14(x) = 2.*x
5460
end subroutine
5561
end
5662

0 commit comments

Comments
 (0)