Skip to content

[Flang] Support passing a function that returns procedure pointer as actual corresponding to a procedure dummy. #80891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions flang/lib/Lower/ConvertCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,8 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
// Handle procedure arguments (procedure pointers should go through
// prepareProcedurePointerActualArgument).
if (hlfir::isFortranProcedureValue(dummyType)) {
// Procedure pointer actual to procedure dummy.
// Procedure pointer or function returns procedure pointer actual to
// procedure dummy.
if (actual.isProcedurePointer()) {
actual = hlfir::derefPointersAndAllocatables(loc, builder, actual);
return PreparedDummyArgument{actual, /*cleanups=*/{}};
Expand All @@ -931,7 +932,11 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
assert(actual.isProcedure());
// Do nothing if this is a procedure argument. It is already a
// fir.boxproc/fir.tuple<fir.boxproc, len> as it should.
if (actual.getType() != dummyType)
if (!actual.getType().isa<fir::BoxProcType>() &&
actual.getType() != dummyType)
// 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.
actual = fixProcedureDummyMismatch(loc, builder, actual, dummyType);
return PreparedDummyArgument{actual, /*cleanups=*/{}};
}
Expand Down