[flang-commits] [flang] [Flag] Support passing a function that returns procedure pointer as actual corresponding to a procedure dummy. (PR #80891)

via flang-commits flang-commits at lists.llvm.org
Tue Feb 6 10:32:03 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-fir-hlfir

Author: Daniel Chen (DanielCChen)

<details>
<summary>Changes</summary>

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
  ```

---
Full diff: https://github.com/llvm/llvm-project/pull/80891.diff


1 Files Affected:

- (modified) flang/lib/Lower/ConvertCall.cpp (+4-2) 


``````````diff
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=*/{}};
     }

``````````

</details>


https://github.com/llvm/llvm-project/pull/80891


More information about the flang-commits mailing list