[flang-commits] [flang] [Flang] 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
Wed Feb 7 01:49:31 PST 2024


================
@@ -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.
----------------
jeanPerier wrote:

The comment is not quite true because most cases will now fall into this code (all nonpointer procedure actual should be fir::BoxProcType at that point, except if they are character functions).

The issue was that fixProcedureDummyMismatch was not rightfully called because the signature inside the boxproc type mismatched (procedure dummy are all () -> () while the result is strongly typed), but this was not a tuple <-> boxproc mismatch.

All that to say, your fix is correct, but it would make more sense to me to move it below by turning  the `if (actual.getType() != dummyType)` into `if (!actual.isa<fir::BoxProcType>() && actual.getType() != dummyType)`  because the goal is not to fall in the code that calls `derefPointersAndAllocatables`, the goal is to bypass `fixProcedureDummyMismatch`.

You can change tcomment related to `fixProcedureDummyMismatch` into:
```
The actual argument may be a procedure that returns character (a fir.tuple<fir.boxproc, len>)
while the dummy is not. Extract the tuple in that case.
```

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


More information about the flang-commits mailing list