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 = [&]() {
--- /dev/null
+! 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