mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 07:16:05 +00:00
[flang] Recognize unused dummy arguments during lowering with HLFIR.
So far we've relied on AllocaOp to represent the dummy arguments not declared for the current entry. With HLFIR we have to account for hlfir::DeclareOp. Differential Revision: https://reviews.llvm.org/D149231
This commit is contained in:
parent
85a13c716f
commit
d311cb64a7
@ -721,9 +721,12 @@ static void deallocateIntentOut(Fortran::lower::AbstractConverter &converter,
|
||||
if (auto mutBox = extVal.getBoxOf<fir::MutableBoxValue>()) {
|
||||
// The dummy argument is not passed in the ENTRY so it should not be
|
||||
// deallocated.
|
||||
if (mlir::Operation *op = mutBox->getAddr().getDefiningOp())
|
||||
if (mlir::isa<fir::AllocaOp>(op))
|
||||
if (mlir::Operation *op = mutBox->getAddr().getDefiningOp()) {
|
||||
if (auto declOp = mlir::dyn_cast<hlfir::DeclareOp>(op))
|
||||
op = declOp.getMemref().getDefiningOp();
|
||||
if (op && mlir::isa<fir::AllocaOp>(op))
|
||||
return;
|
||||
}
|
||||
mlir::Location loc = converter.getCurrentLocation();
|
||||
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
|
||||
auto genDeallocateWithTypeDesc = [&]() {
|
||||
|
16
flang/test/HLFIR/dummy_deallocation.f90
Normal file
16
flang/test/HLFIR/dummy_deallocation.f90
Normal file
@ -0,0 +1,16 @@
|
||||
! RUN: bbc -emit-fir -hlfir %s -o - | FileCheck %s
|
||||
! RUN: bbc -emit-fir %s -o - | FileCheck %s
|
||||
|
||||
! Test that the intent(out) allocatable dummy argument
|
||||
! is not deallocated in entry SUB_B.
|
||||
|
||||
! CHECK-LABEL: func.func @_QPsub_a
|
||||
! CHECK: fir.freemem
|
||||
|
||||
! CHECK-LABEL: func.func @_QPsub_b
|
||||
! CHECK-NOT: fir.freemem
|
||||
SUBROUTINE SUB_A(A)
|
||||
INTEGER, INTENT(out), ALLOCATABLE, DIMENSION (:) :: A
|
||||
RETURN
|
||||
ENTRY SUB_B
|
||||
END SUBROUTINE SUB_A
|
Loading…
x
Reference in New Issue
Block a user