Skip to content

Commit 3cf373e

Browse files
committed
[Flang] Handle reference to null() as actual argument to procedure pointer dummy.
1 parent 6d98a22 commit 3cf373e

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

flang/lib/Lower/ConvertCall.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -874,27 +874,39 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
874874
// element if this is an array in an elemental call.
875875
hlfir::Entity actual = preparedActual.getActual(loc, builder);
876876

877-
// Handles the procedure pointer actual arguments.
877+
// Handle the procedure pointer actual arguments.
878878
if (actual.isProcedurePointer()) {
879+
// Procedure pointer actual to procedure pointer dummy.
879880
if (hlfir::isBoxProcAddressType(dummyType))
880-
// Procedure pointer actual to procedure pointer dummy.
881881
return PreparedDummyArgument{actual, /*cleanups=*/{}};
882+
// Procedure pointer actual to procedure dummy.
882883
if (hlfir::isFortranProcedureValue(dummyType)) {
883-
// Procedure pointer actual to procedure dummy.
884884
actual = hlfir::derefPointersAndAllocatables(loc, builder, actual);
885885
return PreparedDummyArgument{actual, /*cleanups=*/{}};
886886
}
887887
}
888888

889-
// Do nothing if this is a procedure argument. It is already a
890-
// fir.boxproc/fir.tuple<fir.boxproc, len> as it should.
889+
// NULL() actual to procedure pointer dummy
890+
if (Fortran::evaluate::IsNullProcedurePointer(expr) &&
891+
hlfir::isBoxProcAddressType(dummyType)) {
892+
auto boxTy{Fortran::lower::getUntypedBoxProcType(builder.getContext())};
893+
auto tempBoxProc{builder.createTemporary(loc, boxTy)};
894+
hlfir::Entity nullBoxProc(
895+
fir::factory::createNullBoxProc(builder, loc, boxTy));
896+
builder.create<fir::StoreOp>(loc, nullBoxProc, tempBoxProc);
897+
return PreparedDummyArgument{tempBoxProc, /*cleanups=*/{}};
898+
}
899+
891900
if (actual.isProcedure()) {
901+
// Procedure actual to procedure pointer dummy.
892902
if (hlfir::isBoxProcAddressType(dummyType)) {
893-
// Procedure actual to procedure pointer dummy.
894903
auto tempBoxProc{builder.createTemporary(loc, actual.getType())};
895904
builder.create<fir::StoreOp>(loc, actual, tempBoxProc);
896905
return PreparedDummyArgument{tempBoxProc, /*cleanups=*/{}};
897906
}
907+
// Procedure actual to procedure dummy.
908+
// Do nothing if this is a procedure argument. It is already a
909+
// fir.boxproc/fir.tuple<fir.boxproc, len> as it should.
898910
if (actual.getType() != dummyType)
899911
actual = fixProcedureDummyMismatch(loc, builder, actual, dummyType);
900912
return PreparedDummyArgument{actual, /*cleanups=*/{}};

0 commit comments

Comments
 (0)