Skip to content

Commit a4ac099

Browse files
authored
[Flang] Support passing a function that returns procedure pointer as actual corresponding to a procedure dummy. (llvm#80891)
Flang crashes 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 ```
1 parent f66f44e commit a4ac099

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

flang/lib/Lower/ConvertCall.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,8 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
922922
// Handle procedure arguments (procedure pointers should go through
923923
// prepareProcedurePointerActualArgument).
924924
if (hlfir::isFortranProcedureValue(dummyType)) {
925-
// Procedure pointer actual to procedure dummy.
925+
// Procedure pointer or function returns procedure pointer actual to
926+
// procedure dummy.
926927
if (actual.isProcedurePointer()) {
927928
actual = hlfir::derefPointersAndAllocatables(loc, builder, actual);
928929
return PreparedDummyArgument{actual, /*cleanups=*/{}};
@@ -931,7 +932,11 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
931932
assert(actual.isProcedure());
932933
// Do nothing if this is a procedure argument. It is already a
933934
// fir.boxproc/fir.tuple<fir.boxproc, len> as it should.
934-
if (actual.getType() != dummyType)
935+
if (!actual.getType().isa<fir::BoxProcType>() &&
936+
actual.getType() != dummyType)
937+
// The actual argument may be a procedure that returns character (a
938+
// fir.tuple<fir.boxproc, len>) while the dummy is not. Extract the tuple
939+
// in that case.
935940
actual = fixProcedureDummyMismatch(loc, builder, actual, dummyType);
936941
return PreparedDummyArgument{actual, /*cleanups=*/{}};
937942
}

0 commit comments

Comments
 (0)