Skip to content
Merged
Show file tree
Hide file tree
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: 8 additions & 1 deletion flang/lib/Lower/ConvertVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,15 @@ static void instantiateLocal(Fortran::lower::AbstractConverter &converter,
Fortran::lower::SymMap &symMap) {
assert(!var.isAlias());
Fortran::lower::StatementContext stmtCtx;
// isUnusedEntryDummy must be computed before mapSymbolAttributes.
const bool isUnusedEntryDummy =
var.hasSymbol() && Fortran::semantics::IsDummy(var.getSymbol()) &&
!symMap.lookupSymbol(var.getSymbol()).getAddr();
mapSymbolAttributes(converter, var, symMap, stmtCtx);
// Do not generate code to initialize/finalize/destroy dummy arguments that
// are nor part of the current ENTRY. They do not have backing storage.
if (isUnusedEntryDummy)
return;
deallocateIntentOut(converter, var, symMap);
if (needDummyIntentoutFinalization(var))
finalizeAtRuntime(converter, var, symMap);
Expand Down Expand Up @@ -999,7 +1007,6 @@ static void instantiateLocal(Fortran::lower::AbstractConverter &converter,
"trying to deallocate entity not lowered as allocatable");
Fortran::lower::genDeallocateIfAllocated(*converterPtr, *mutableBox,
loc, sym);

});
}
}
Expand Down
26 changes: 26 additions & 0 deletions flang/test/Lower/entry-statement-init.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
! RUN: bbc -emit-hlfir -o - %s | FileCheck %s

! Test initialization and finalizations of dummy arguments in entry statements.

module m
type t
end type
contains
subroutine test1(x)
class(t), intent(out) :: x
entry test1_entry()
end subroutine
subroutine test2(x)
class(t), intent(out) :: x
entry test2_entry(x)
end subroutine
end module
! CHECK-LABEL: func.func @_QMmPtest1_entry(
! CHECK-NOT: Destroy
! CHECK-NOT: Initialize
! CHECK: return

! CHECK-LABEL: func.func @_QMmPtest2_entry(
! CHECK: Destroy
! CHECK: Initialize
! CHECK: return