[flang-commits] [flang] [flang] Fix type inheritance for statement function dummy arguments (PR #93624)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Tue May 28 16:45:09 PDT 2024
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/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 https://github.com/llvm/llvm-project/issues/93484.
>From e0a90cfe50edcc3c5b3c7ab2325add5ebcc1f257 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 28 May 2024 16:42:28 -0700
Subject: [PATCH] [flang] Fix type inheritance for statement function dummy
arguments
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 https://github.com/llvm/llvm-project/issues/93484.
---
flang/lib/Semantics/resolve-names.cpp | 6 ++----
flang/test/Semantics/stmt-func01.f90 | 10 ++++++++--
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 68cfc8641b9b2..fd3d4daea0154 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -3694,10 +3694,8 @@ bool SubprogramVisitor::HandleStmtFunction(const parser::StmtFunctionStmt &x) {
for (const auto &dummyName : std::get<std::list<parser::Name>>(x.t)) {
ObjectEntityDetails dummyDetails{true};
if (auto *dummySymbol{FindInScope(currScope().parent(), dummyName)}) {
- if (auto *d{dummySymbol->detailsIf<EntityDetails>()}) {
- if (d->type()) {
- dummyDetails.set_type(*d->type());
- }
+ if (auto *d{dummySymbol->GetType()}) {
+ dummyDetails.set_type(*d);
}
}
Symbol &dummy{MakeSymbol(dummyName, std::move(dummyDetails))};
diff --git a/flang/test/Semantics/stmt-func01.f90 b/flang/test/Semantics/stmt-func01.f90
index 3c9ffa565900a..83c31ded1d39b 100644
--- a/flang/test/Semantics/stmt-func01.f90
+++ b/flang/test/Semantics/stmt-func01.f90
@@ -37,7 +37,13 @@ pure integer function ifunc()
!ERROR: Statement function 'sf10' may not reference another statement function 'sf11' that is defined later
sf10(n) = sf11(n)
sf11(n) = sf10(n) ! mutual recursion, caused crash
- sf13 = 1.
+ integer(1) iarg1
+ !PORTABILITY: nonstandard usage: based POINTER
+ pointer(iarg1p, iarg1)
+ sf13(iarg1) = iarg1
+ ! executable part
+ print *, sf13(iarg1) ! ok
+ sf14 = 1.
contains
real function explicit(x,y)
integer, intent(in) :: x
@@ -50,7 +56,7 @@ pure function arr()
end function
subroutine foo
!PORTABILITY: An implicitly typed statement function should not appear when the same symbol is available in its host scope
- sf13(x) = 2.*x
+ sf14(x) = 2.*x
end subroutine
end
More information about the flang-commits
mailing list