[flang-commits] [flang] [Flag] Support passing a function that returns procedure pointer as actual corresponding to a procedure dummy. (PR #80891)
Daniel Chen via flang-commits
flang-commits at lists.llvm.org
Tue Feb 6 10:31:35 PST 2024
https://github.com/DanielCChen created https://github.com/llvm/llvm-project/pull/80891
Flang crashes a with the following case. The problem is we missed the case when passing a reference to a function that returns a procedure pointer as actual that corresponds to a procedure dummy. This PR is to fix that.
```
PROGRAM main
IMPLICIT NONE
INTERFACE
FUNCTION IntF(Arg)
integer :: Arg, IntF
END FUNCTION
END INTERFACE
INTERFACE
FUNCTION RetPtr(Arg)
IMPORT
PROCEDURE(IntF) :: Arg
PROCEDURE(IntF), POINTER :: RetPtr
END FUNCTION
END INTERFACE
CALL ModSub(RetPtr(IntF))
contains
SUBROUTINE ModSub(Fun1)
PROCEDURE(IntF) :: Fun1
END SUBROUTINE
END
```
>From ec7bb8c0cbdaaf692dd51ce36ab4c1e663c1ea09 Mon Sep 17 00:00:00 2001
From: cdchen-ca <cdchen at ca.ibm.com>
Date: Tue, 6 Feb 2024 13:27:25 -0500
Subject: [PATCH] [Flag] Support passing a function that returns procedure
pointer as actual corresponding to a procedure dummy.
---
flang/lib/Lower/ConvertCall.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp
index bb8fd2e945f43..bd6bd81117966 100644
--- a/flang/lib/Lower/ConvertCall.cpp
+++ b/flang/lib/Lower/ConvertCall.cpp
@@ -915,8 +915,10 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
// Handle procedure arguments (procedure pointers should go through
// prepareProcedurePointerActualArgument).
if (hlfir::isFortranProcedureValue(dummyType)) {
- // Procedure pointer actual to procedure dummy.
- if (actual.isProcedurePointer()) {
+ // Procedure pointer or function returns procedure pointer actual to
+ // procedure dummy.
+ if (actual.isProcedurePointer() ||
+ actual.getType().isa<fir::BoxProcType>()) {
actual = hlfir::derefPointersAndAllocatables(loc, builder, actual);
return PreparedDummyArgument{actual, /*cleanups=*/{}};
}
More information about the flang-commits
mailing list