Skip to content

Commit 90742f9

Browse files
committed
[flang] do not finalize or initialize unused entry dummy
1 parent 5fdf161 commit 90742f9

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

flang/lib/Lower/ConvertVariable.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,16 @@ static void instantiateLocal(Fortran::lower::AbstractConverter &converter,
956956
Fortran::lower::SymMap &symMap) {
957957
assert(!var.isAlias());
958958
Fortran::lower::StatementContext stmtCtx;
959+
// isUnusedEntryDummy must be computed before mapSymbolAttributes.
960+
const bool isUnusedEntryDummy =
961+
var.hasSymbol() ? Fortran::semantics::IsDummy(var.getSymbol()) &&
962+
!symMap.lookupSymbol(var.getSymbol()).getAddr()
963+
: false;
959964
mapSymbolAttributes(converter, var, symMap, stmtCtx);
965+
// Do not generate code to initialize/finalize/destroy dummy arguments that
966+
// are nor part of the current ENTRY. They do not have backing storage.
967+
if (isUnusedEntryDummy)
968+
return;
960969
deallocateIntentOut(converter, var, symMap);
961970
if (needDummyIntentoutFinalization(var))
962971
finalizeAtRuntime(converter, var, symMap);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
! RUN: bbc -emit-hlfir -o - %s | FileCheck %s
2+
3+
! Test initialization and finalizations of dummy arguments in entry statements.
4+
5+
module m
6+
type t
7+
end type
8+
contains
9+
subroutine test1(x)
10+
class(t), intent(out) :: x
11+
entry test1_entry()
12+
end subroutine
13+
subroutine test2(x)
14+
class(t), intent(out) :: x
15+
entry test2_entry(x)
16+
end subroutine
17+
end module
18+
! CHECK-LABEL: func.func @_QMmPtest1_entry(
19+
! CHECK-NOT: Destroy
20+
! CHECK-NOT: Initialize
21+
! CHECK: return
22+
23+
! CHECK-LABEL: func.func @_QMmPtest2_entry(
24+
! CHECK: Destroy
25+
! CHECK: Initialize
26+
! CHECK: return

0 commit comments

Comments
 (0)