Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 9 additions & 0 deletions flang/lib/Lower/ConvertVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,16 @@ 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()
: false;
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
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