[flang-commits] [flang] [flang][NFC] Converted five tests from old lowering to new lowering (part 15) (PR #179854)

Eugene Epshteyn via flang-commits flang-commits at lists.llvm.org
Sun Feb 8 20:24:48 PST 2026


https://github.com/eugeneepshteyn updated https://github.com/llvm/llvm-project/pull/179854

>From b13177ede61d84f48c3354f4ca1b849f2b06eeea Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Wed, 4 Feb 2026 22:31:17 -0500
Subject: [PATCH 1/3] [flang][NFC] Converted five tests from old lowering to
 new lowering (part 15)

Tests converted from test/Lower: equivalence-with-host-assoc.f90,
explicit-interface-results-2.f90, explicit-interface-results.f90,
ext-proc-as-actual-argument-1.f90, ext-proc-as-actual-argument-2.f90
---
 .../Lower/equivalence-with-host-assoc.f90     |  73 +----
 .../Lower/explicit-interface-results-2.f90    | 201 ++++++-------
 .../test/Lower/explicit-interface-results.f90 | 266 ++++++++----------
 .../Lower/ext-proc-as-actual-argument-1.f90   |  34 ++-
 .../Lower/ext-proc-as-actual-argument-2.f90   |  32 ++-
 5 files changed, 264 insertions(+), 342 deletions(-)

diff --git a/flang/test/Lower/equivalence-with-host-assoc.f90 b/flang/test/Lower/equivalence-with-host-assoc.f90
index 733531ab8a2c8..c3a7f743fcd87 100644
--- a/flang/test/Lower/equivalence-with-host-assoc.f90
+++ b/flang/test/Lower/equivalence-with-host-assoc.f90
@@ -1,5 +1,4 @@
-! RUN: bbc -emit-fir -hlfir=false -o - %s | FileCheck %s --check-prefixes=FIR
-! RUN: bbc -emit-hlfir -o - %s | FileCheck %s --check-prefixes=HLFIR
+! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck %s --check-prefixes=HLFIR
 
 subroutine test1()
   integer :: i1 = 1
@@ -10,20 +9,6 @@ subroutine inner
     i1 = j1
   end subroutine inner
 end subroutine test1
-! FIR-LABEL:   func.func private @_QFtest1Pinner() attributes {fir.host_symbol = {{.*}}, llvm.linkage = #llvm.linkage<internal>} {
-! FIR:           %[[VAL_0:.*]] = fir.address_of(@_QFtest1Ei1) : !fir.ref<!fir.array<1xi32>>
-! FIR:           %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<!fir.array<1xi32>>) -> !fir.ref<!fir.array<4xi8>>
-! FIR:           %[[VAL_2:.*]] = arith.constant 0 : index
-! FIR:           %[[VAL_3:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_2]] : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
-! FIR:           %[[VAL_4:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<i8>) -> !fir.ptr<i32>
-! FIR:           %[[VAL_5:.*]] = arith.constant 0 : index
-! FIR:           %[[VAL_6:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_5]] : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
-! FIR:           %[[VAL_7:.*]] = fir.convert %[[VAL_6]] : (!fir.ref<i8>) -> !fir.ptr<i32>
-! FIR:           %[[VAL_8:.*]] = fir.load %[[VAL_7]] : !fir.ptr<i32>
-! FIR:           fir.store %[[VAL_8]] to %[[VAL_4]] : !fir.ptr<i32>
-! FIR:           return
-! FIR:         }
-
 ! HLFIR-LABEL:   func.func private @_QFtest1Pinner() attributes {fir.host_symbol = {{.*}}, llvm.linkage = #llvm.linkage<internal>} {
 ! HLFIR:           %[[VAL_0:.*]] = fir.address_of(@_QFtest1Ei1) : !fir.ref<!fir.array<1xi32>>
 ! HLFIR:           %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<!fir.array<1xi32>>) -> !fir.ref<!fir.array<4xi8>>
@@ -54,20 +39,6 @@ subroutine inner
     end subroutine inner
   end subroutine host
 end module test2
-! FIR-LABEL:   func.func private @_QMtest2FhostPinner() attributes {fir.host_symbol = {{.*}}, llvm.linkage = #llvm.linkage<internal>} {
-! FIR:           %[[VAL_0:.*]] = fir.address_of(@_QMtest2FhostEf1) : !fir.ref<!fir.array<1xi32>>
-! FIR:           %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<!fir.array<1xi32>>) -> !fir.ref<!fir.array<4xi8>>
-! FIR:           %[[VAL_2:.*]] = arith.constant 0 : index
-! FIR:           %[[VAL_3:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_2]] : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
-! FIR:           %[[VAL_4:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<i8>) -> !fir.ptr<f32>
-! FIR:           %[[VAL_5:.*]] = arith.constant 0 : index
-! FIR:           %[[VAL_6:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_5]] : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
-! FIR:           %[[VAL_7:.*]] = fir.convert %[[VAL_6]] : (!fir.ref<i8>) -> !fir.ptr<f32>
-! FIR:           %[[VAL_8:.*]] = fir.load %[[VAL_7]] : !fir.ptr<f32>
-! FIR:           fir.store %[[VAL_8]] to %[[VAL_4]] : !fir.ptr<f32>
-! FIR:           return
-! FIR:         }
-
 ! HLFIR-LABEL:   func.func private @_QMtest2FhostPinner() attributes {fir.host_symbol = {{.*}}, llvm.linkage = #llvm.linkage<internal>} {
 ! HLFIR:           %[[VAL_0:.*]] = fir.address_of(@_QMtest2FhostEf1) : !fir.ref<!fir.array<1xi32>>
 ! HLFIR:           %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<!fir.array<1xi32>>) -> !fir.ref<!fir.array<4xi8>>
@@ -94,27 +65,6 @@ subroutine inner
     i1 = j1 + k1
   end subroutine inner
 end subroutine test3
-! FIR-LABEL:   func.func private @_QFtest3Pinner() attributes {fir.host_symbol = {{.*}}, llvm.linkage = #llvm.linkage<internal>} {
-! FIR:           %[[VAL_0:.*]] = fir.address_of(@blk_) : !fir.ref<tuple<i32>>
-! FIR:           %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<tuple<i32>>) -> !fir.ref<!fir.array<4xi8>>
-! FIR:           %[[VAL_2:.*]] = arith.constant 0 : index
-! FIR:           %[[VAL_3:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_2]] : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
-! FIR:           %[[VAL_4:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<i8>) -> !fir.ptr<i32>
-! FIR:           %[[VAL_5:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<tuple<i32>>) -> !fir.ref<!fir.array<4xi8>>
-! FIR:           %[[VAL_6:.*]] = arith.constant 0 : index
-! FIR:           %[[VAL_7:.*]] = fir.coordinate_of %[[VAL_5]], %[[VAL_6]] : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
-! FIR:           %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (!fir.ref<i8>) -> !fir.ptr<i32>
-! FIR:           %[[VAL_9:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<tuple<i32>>) -> !fir.ref<!fir.array<4xi8>>
-! FIR:           %[[VAL_10:.*]] = arith.constant 0 : index
-! FIR:           %[[VAL_11:.*]] = fir.coordinate_of %[[VAL_9]], %[[VAL_10]] : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
-! FIR:           %[[VAL_12:.*]] = fir.convert %[[VAL_11]] : (!fir.ref<i8>) -> !fir.ptr<i32>
-! FIR:           %[[VAL_13:.*]] = fir.load %[[VAL_8]] : !fir.ptr<i32>
-! FIR:           %[[VAL_14:.*]] = fir.load %[[VAL_12]] : !fir.ptr<i32>
-! FIR:           %[[VAL_15:.*]] = arith.addi %[[VAL_13]], %[[VAL_14]] : i32
-! FIR:           fir.store %[[VAL_15]] to %[[VAL_4]] : !fir.ptr<i32>
-! FIR:           return
-! FIR:         }
-
 ! HLFIR-LABEL:   func.func private @_QFtest3Pinner() attributes {fir.host_symbol = {{.*}}, llvm.linkage = #llvm.linkage<internal>} {
 ! HLFIR:           %[[VAL_0:.*]] = fir.address_of(@blk_) : !fir.ref<tuple<i32>>
 ! HLFIR:           %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<tuple<i32>>) -> !fir.ref<!fir.array<4xi8>>
@@ -149,27 +99,6 @@ subroutine inner
     i1 = j1 + k1
   end subroutine inner
 end subroutine test4
-! FIR-LABEL:   func.func private @_QFtest4Pinner() attributes {fir.host_symbol = {{.*}}, llvm.linkage = #llvm.linkage<internal>} {
-! FIR:           %[[VAL_0:.*]] = fir.address_of(@blk_) : !fir.ref<tuple<i32>>
-! FIR:           %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<tuple<i32>>) -> !fir.ref<!fir.array<4xi8>>
-! FIR:           %[[VAL_2:.*]] = arith.constant 0 : index
-! FIR:           %[[VAL_3:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_2]] : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
-! FIR:           %[[VAL_4:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<i8>) -> !fir.ptr<i32>
-! FIR:           %[[VAL_5:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<tuple<i32>>) -> !fir.ref<!fir.array<4xi8>>
-! FIR:           %[[VAL_6:.*]] = arith.constant 0 : index
-! FIR:           %[[VAL_7:.*]] = fir.coordinate_of %[[VAL_5]], %[[VAL_6]] : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
-! FIR:           %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (!fir.ref<i8>) -> !fir.ptr<i32>
-! FIR:           %[[VAL_9:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<tuple<i32>>) -> !fir.ref<!fir.array<4xi8>>
-! FIR:           %[[VAL_10:.*]] = arith.constant 0 : index
-! FIR:           %[[VAL_11:.*]] = fir.coordinate_of %[[VAL_9]], %[[VAL_10]] : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
-! FIR:           %[[VAL_12:.*]] = fir.convert %[[VAL_11]] : (!fir.ref<i8>) -> !fir.ptr<i32>
-! FIR:           %[[VAL_13:.*]] = fir.load %[[VAL_8]] : !fir.ptr<i32>
-! FIR:           %[[VAL_14:.*]] = fir.load %[[VAL_12]] : !fir.ptr<i32>
-! FIR:           %[[VAL_15:.*]] = arith.addi %[[VAL_13]], %[[VAL_14]] : i32
-! FIR:           fir.store %[[VAL_15]] to %[[VAL_4]] : !fir.ptr<i32>
-! FIR:           return
-! FIR:         }
-
 ! HLFIR-LABEL:   func.func private @_QFtest4Pinner() attributes {fir.host_symbol = {{.*}}, llvm.linkage = #llvm.linkage<internal>} {
 ! HLFIR:           %[[VAL_0:.*]] = fir.address_of(@blk_) : !fir.ref<tuple<i32>>
 ! HLFIR:           %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<tuple<i32>>) -> !fir.ref<!fir.array<4xi8>>
diff --git a/flang/test/Lower/explicit-interface-results-2.f90 b/flang/test/Lower/explicit-interface-results-2.f90
index 42043579a53d0..f29ee99522b2e 100644
--- a/flang/test/Lower/explicit-interface-results-2.f90
+++ b/flang/test/Lower/explicit-interface-results-2.f90
@@ -1,7 +1,4 @@
-! Test lowering of internal procedures returning arrays or characters.
-! This test allocation on the caller side of the results that may depend on
-! host associated symbols.
-! RUN: bbc -hlfir=false %s -o - | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s
 
 module some_module
  integer :: n_module
@@ -9,17 +6,19 @@ module some_module
 
 ! Test host calling array internal procedure.
 ! Result depends on host variable.
-! CHECK-LABEL: func @_QPhost1
+! CHECK-LABEL: func.func @_QPhost1
 subroutine host1()
   implicit none
   integer :: n
-! CHECK:  %[[VAL_1:.*]] = fir.alloca i32
   call takes_array(return_array())
-! CHECK:  %[[VAL_4:.*]] = fir.load %[[VAL_1]] : !fir.ref<i32>
-! CHECK:  %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (i32) -> index
-! CHECK:  %[[CMPI:.*]] = arith.cmpi sgt, %[[VAL_5]], %{{.*}} : index
-! CHECK:  %[[SELECT:.*]] = arith.select %[[CMPI]], %[[VAL_5]], %{{.*}} : index
-! CHECK:  %[[VAL_6:.*]] = fir.alloca !fir.array<?xf32>, %[[SELECT]] {bindc_name = ".result"}
+! CHECK:  fir.shape %[[SELECT:.*]] : (index) -> !fir.shape<1>
+! CHECK:  %[[VAL_8:.*]] = hlfir.eval_in_mem shape %[[VAL_7:.*]] : (!fir.shape<1>) -> !hlfir.expr<?xf32> {
+! CHECK:  ^bb0(%[[ARG:.*]]: !fir.ref<!fir.array<?xf32>>):
+! CHECK:    %[[RES:.*]] = fir.call @_QFhost1Preturn_array(%{{.*}}) {{.*}}: (!fir.ref<tuple<!fir.ref<i32>>>) -> !fir.array<?xf32>
+! CHECK:    fir.save_result %[[RES]] to %[[ARG]](%[[VAL_7]]) : !fir.array<?xf32>, !fir.ref<!fir.array<?xf32>>, !fir.shape<1>
+! CHECK:  }
+! CHECK:  %[[VAL_9:.*]]:3 = hlfir.associate %[[VAL_8]](%[[VAL_7]]) {{.*}} : (!hlfir.expr<?xf32>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>, i1)
+! CHECK:  fir.call @_QPtakes_array(%[[VAL_9]]#1) {{.*}}: (!fir.ref<!fir.array<?xf32>>) -> ()
 contains
   function return_array()
     real :: return_array(n)
@@ -28,16 +27,18 @@ function return_array()
 
 ! Test host calling array internal procedure.
 ! Result depends on module variable with the use statement inside the host.
-! CHECK-LABEL: func @_QPhost2
+! CHECK-LABEL: func.func @_QPhost2
 subroutine host2()
   use :: some_module
   call takes_array(return_array())
-! CHECK:  %[[VAL_0:.*]] = fir.address_of(@_QMsome_moduleEn_module) : !fir.ref<i32>
-! CHECK:  %[[VAL_1:.*]] = fir.load %[[VAL_0]] : !fir.ref<i32>
-! CHECK:  %[[VAL_2:.*]] = fir.convert %[[VAL_1]] : (i32) -> index
-! CHECK:  %[[CMPI:.*]] = arith.cmpi sgt, %[[VAL_2]], %{{.*}} : index
-! CHECK:  %[[SELECT:.*]] = arith.select %[[CMPI]], %[[VAL_2]], %{{.*}} : index
-! CHECK:  %[[VAL_3:.*]] = fir.alloca !fir.array<?xf32>, %[[SELECT]] {bindc_name = ".result"}
+! CHECK:  fir.shape %[[SELECT:.*]] : (index) -> !fir.shape<1>
+! CHECK:  %[[VAL_5:.*]] = hlfir.eval_in_mem shape %[[VAL_4:.*]] : (!fir.shape<1>) -> !hlfir.expr<?xf32> {
+! CHECK:  ^bb0(%[[ARG:.*]]: !fir.ref<!fir.array<?xf32>>):
+! CHECK:    %[[RES:.*]] = fir.call @_QFhost2Preturn_array() {{.*}}: () -> !fir.array<?xf32>
+! CHECK:    fir.save_result %[[RES]] to %[[ARG]](%[[VAL_4]]) : !fir.array<?xf32>, !fir.ref<!fir.array<?xf32>>, !fir.shape<1>
+! CHECK:  }
+! CHECK:  %[[VAL_6:.*]]:3 = hlfir.associate %[[VAL_5]](%[[VAL_4]]) {{.*}} : (!hlfir.expr<?xf32>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>, i1)
+! CHECK:  fir.call @_QPtakes_array(%[[VAL_6]]#1) {{.*}}: (!fir.ref<!fir.array<?xf32>>) -> ()
 contains
   function return_array()
     real :: return_array(n_module)
@@ -46,15 +47,17 @@ function return_array()
 
 ! Test host calling array internal procedure.
 ! Result depends on module variable with the use statement inside the internal procedure.
-! CHECK-LABEL: func @_QPhost3
+! CHECK-LABEL: func.func @_QPhost3
 subroutine host3()
   call takes_array(return_array())
-! CHECK:  %[[VAL_0:.*]] = fir.address_of(@_QMsome_moduleEn_module) : !fir.ref<i32>
-! CHECK:  %[[VAL_1:.*]] = fir.load %[[VAL_0]] : !fir.ref<i32>
-! CHECK:  %[[VAL_2:.*]] = fir.convert %[[VAL_1]] : (i32) -> index
-! CHECK:  %[[CMPI:.*]] = arith.cmpi sgt, %[[VAL_2]], %{{.*}} : index
-! CHECK:  %[[SELECT:.*]] = arith.select %[[CMPI]], %[[VAL_2]], %{{.*}} : index
-! CHECK:  %[[VAL_3:.*]] = fir.alloca !fir.array<?xf32>, %[[SELECT]] {bindc_name = ".result"}
+! CHECK:  fir.shape %[[SELECT:.*]] : (index) -> !fir.shape<1>
+! CHECK:  %[[VAL_5:.*]] = hlfir.eval_in_mem shape %[[VAL_4:.*]] : (!fir.shape<1>) -> !hlfir.expr<?xf32> {
+! CHECK:  ^bb0(%[[ARG:.*]]: !fir.ref<!fir.array<?xf32>>):
+! CHECK:    %[[RES:.*]] = fir.call @_QFhost3Preturn_array() {{.*}}: () -> !fir.array<?xf32>
+! CHECK:    fir.save_result %[[RES]] to %[[ARG]](%[[VAL_4]]) : !fir.array<?xf32>, !fir.ref<!fir.array<?xf32>>, !fir.shape<1>
+! CHECK:  }
+! CHECK:  %[[VAL_6:.*]]:3 = hlfir.associate %[[VAL_5]](%[[VAL_4]]) {{.*}} : (!hlfir.expr<?xf32>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>, i1)
+! CHECK:  fir.call @_QPtakes_array(%[[VAL_6]]#1) {{.*}}: (!fir.ref<!fir.array<?xf32>>) -> ()
 contains
   function return_array()
     use :: some_module
@@ -69,18 +72,18 @@ subroutine host4()
   integer :: n
   call internal_proc_a()
 contains
-! CHECK-LABEL: func private @_QFhost4Pinternal_proc_a
-! CHECK-SAME:  %[[VAL_0:.*]]: !fir.ref<tuple<!fir.ref<i32>>> {fir.host_assoc}) attributes {fir.host_symbol = {{.*}}, llvm.linkage = #llvm.linkage<internal>} {
+! CHECK-LABEL: func.func private @_QFhost4Pinternal_proc_a
+! CHECK-SAME:  %[[VAL_0:.*]]: !fir.ref<tuple<!fir.ref<i32>>> {fir.host_assoc})
   subroutine internal_proc_a()
     call takes_array(return_array())
-! CHECK:  %[[VAL_1:.*]] = arith.constant 0 : i32
-! CHECK:  %[[VAL_2:.*]] = fir.coordinate_of %[[VAL_0]], %[[VAL_1]] : (!fir.ref<tuple<!fir.ref<i32>>>, i32) -> !fir.llvm_ptr<!fir.ref<i32>>
-! CHECK:  %[[VAL_3:.*]] = fir.load %[[VAL_2]] : !fir.llvm_ptr<!fir.ref<i32>>
-! CHECK:  %[[VAL_4:.*]] = fir.load %[[VAL_3]] : !fir.ref<i32>
-! CHECK:  %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (i32) -> index
-! CHECK:  %[[CMPI:.*]] = arith.cmpi sgt, %[[VAL_5]], %{{.*}} : index
-! CHECK:  %[[SELECT:.*]] = arith.select %[[CMPI]], %[[VAL_5]], %{{.*}} : index
-! CHECK:  %[[VAL_6:.*]] = fir.alloca !fir.array<?xf32>, %[[SELECT]] {bindc_name = ".result"}
+! CHECK:  fir.shape %[[SELECT:.*]] : (index) -> !fir.shape<1>
+! CHECK:  %[[VAL_8:.*]] = hlfir.eval_in_mem shape %[[VAL_7:.*]] : (!fir.shape<1>) -> !hlfir.expr<?xf32> {
+! CHECK:  ^bb0(%[[ARG:.*]]: !fir.ref<!fir.array<?xf32>>):
+! CHECK:    %[[RES:.*]] = fir.call @_QFhost4Preturn_array(%[[VAL_0]]) {{.*}}: (!fir.ref<tuple<!fir.ref<i32>>>) -> !fir.array<?xf32>
+! CHECK:    fir.save_result %[[RES]] to %[[ARG]](%[[VAL_7]]) : !fir.array<?xf32>, !fir.ref<!fir.array<?xf32>>, !fir.shape<1>
+! CHECK:  }
+! CHECK:  %[[VAL_9:.*]]:3 = hlfir.associate %[[VAL_8]](%[[VAL_7]]) {{.*}} : (!hlfir.expr<?xf32>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>, i1)
+! CHECK:  fir.call @_QPtakes_array(%[[VAL_9]]#1) {{.*}}: (!fir.ref<!fir.array<?xf32>>) -> ()
   end subroutine
   function return_array()
     real :: return_array(n)
@@ -94,15 +97,17 @@ subroutine host5()
   implicit none
   call internal_proc_a()
 contains
-! CHECK-LABEL: func private @_QFhost5Pinternal_proc_a() attributes {fir.host_symbol = {{.*}}, llvm.linkage = #llvm.linkage<internal>} {
+! CHECK-LABEL: func.func private @_QFhost5Pinternal_proc_a
   subroutine internal_proc_a()
     call takes_array(return_array())
-! CHECK:  %[[VAL_0:.*]] = fir.address_of(@_QMsome_moduleEn_module) : !fir.ref<i32>
-! CHECK:  %[[VAL_1:.*]] = fir.load %[[VAL_0]] : !fir.ref<i32>
-! CHECK:  %[[VAL_2:.*]] = fir.convert %[[VAL_1]] : (i32) -> index
-! CHECK:  %[[CMPI:.*]] = arith.cmpi sgt, %[[VAL_2]], %{{.*}} : index
-! CHECK:  %[[SELECT:.*]] = arith.select %[[CMPI]], %[[VAL_2]], %{{.*}} : index
-! CHECK:  %[[VAL_3:.*]] = fir.alloca !fir.array<?xf32>, %[[SELECT]] {bindc_name = ".result"}
+! CHECK:  fir.shape %[[SELECT:.*]] : (index) -> !fir.shape<1>
+! CHECK:  %[[VAL_5:.*]] = hlfir.eval_in_mem shape %[[VAL_4:.*]] : (!fir.shape<1>) -> !hlfir.expr<?xf32> {
+! CHECK:  ^bb0(%[[ARG:.*]]: !fir.ref<!fir.array<?xf32>>):
+! CHECK:    %[[RES:.*]] = fir.call @_QFhost5Preturn_array() {{.*}}: () -> !fir.array<?xf32>
+! CHECK:    fir.save_result %[[RES]] to %[[ARG]](%[[VAL_4]]) : !fir.array<?xf32>, !fir.ref<!fir.array<?xf32>>, !fir.shape<1>
+! CHECK:  }
+! CHECK:  %[[VAL_6:.*]]:3 = hlfir.associate %[[VAL_5]](%[[VAL_4]]) {{.*}} : (!hlfir.expr<?xf32>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>, i1)
+! CHECK:  fir.call @_QPtakes_array(%[[VAL_6]]#1) {{.*}}: (!fir.ref<!fir.array<?xf32>>) -> ()
   end subroutine
   function return_array()
     real :: return_array(n_module)
@@ -115,15 +120,17 @@ subroutine host6()
   implicit none
   call internal_proc_a()
 contains
-! CHECK-LABEL: func private @_QFhost6Pinternal_proc_a
+! CHECK-LABEL: func.func private @_QFhost6Pinternal_proc_a
   subroutine internal_proc_a()
     call takes_array(return_array())
-! CHECK:  %[[VAL_0:.*]] = fir.address_of(@_QMsome_moduleEn_module) : !fir.ref<i32>
-! CHECK:  %[[VAL_1:.*]] = fir.load %[[VAL_0]] : !fir.ref<i32>
-! CHECK:  %[[VAL_2:.*]] = fir.convert %[[VAL_1]] : (i32) -> index
-! CHECK:  %[[CMPI:.*]] = arith.cmpi sgt, %[[VAL_2]], %{{.*}} : index
-! CHECK:  %[[SELECT:.*]] = arith.select %[[CMPI]], %[[VAL_2]], %{{.*}} : index
-! CHECK:  %[[VAL_3:.*]] = fir.alloca !fir.array<?xf32>, %[[SELECT]] {bindc_name = ".result"}
+! CHECK:  fir.shape %[[SELECT:.*]] : (index) -> !fir.shape<1>
+! CHECK:  %[[VAL_5:.*]] = hlfir.eval_in_mem shape %[[VAL_4:.*]] : (!fir.shape<1>) -> !hlfir.expr<?xf32> {
+! CHECK:  ^bb0(%[[ARG:.*]]: !fir.ref<!fir.array<?xf32>>):
+! CHECK:    %[[RES:.*]] = fir.call @_QFhost6Preturn_array() {{.*}}: () -> !fir.array<?xf32>
+! CHECK:    fir.save_result %[[RES]] to %[[ARG]](%[[VAL_4]]) : !fir.array<?xf32>, !fir.ref<!fir.array<?xf32>>, !fir.shape<1>
+! CHECK:  }
+! CHECK:  %[[VAL_6:.*]]:3 = hlfir.associate %[[VAL_5]](%[[VAL_4]]) {{.*}} : (!hlfir.expr<?xf32>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>, i1)
+! CHECK:  fir.call @_QPtakes_array(%[[VAL_6]]#1) {{.*}}: (!fir.ref<!fir.array<?xf32>>) -> ()
   end subroutine
   function return_array()
     use :: some_module
@@ -133,21 +140,20 @@ function return_array()
 
 ! Test host calling array internal procedure.
 ! Result depends on a common block variable declared in the host.
-! CHECK-LABEL: func @_QPhost7
+! CHECK-LABEL: func.func @_QPhost7
 subroutine host7()
   implicit none
   integer :: n_common
   common /mycom/ n_common
   call takes_array(return_array())
-! CHECK:  %[[VAL_0:.*]] = arith.constant 0 : index
-! CHECK:  %[[VAL_2:.*]] = fir.address_of(@mycom_) : !fir.ref<!fir.array<4xi8>>
-! CHECK:  %[[VAL_4:.*]] = fir.coordinate_of %[[VAL_2]], %[[VAL_0]] : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
-! CHECK:  %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (!fir.ref<i8>) -> !fir.ref<i32>
-! CHECK:  %[[VAL_8:.*]] = fir.load %[[VAL_5]] : !fir.ref<i32>
-! CHECK:  %[[VAL_9:.*]] = fir.convert %[[VAL_8]] : (i32) -> index
-! CHECK:  %[[CMPI:.*]] = arith.cmpi sgt, %[[VAL_9]], %{{.*}} : index
-! CHECK:  %[[SELECT:.*]] = arith.select %[[CMPI]], %[[VAL_9]], %{{.*}} : index
-! CHECK:  %[[VAL_10:.*]] = fir.alloca !fir.array<?xf32>, %[[SELECT]] {bindc_name = ".result"}
+! CHECK:  fir.shape %[[SELECT:.*]] : (index) -> !fir.shape<1>
+! CHECK:  %[[VAL_12:.*]] = hlfir.eval_in_mem shape %[[VAL_11:.*]] : (!fir.shape<1>) -> !hlfir.expr<?xf32> {
+! CHECK:  ^bb0(%[[ARG:.*]]: !fir.ref<!fir.array<?xf32>>):
+! CHECK:    %[[RES:.*]] = fir.call @_QFhost7Preturn_array() {{.*}}: () -> !fir.array<?xf32>
+! CHECK:    fir.save_result %[[RES]] to %[[ARG]](%[[VAL_11]]) : !fir.array<?xf32>, !fir.ref<!fir.array<?xf32>>, !fir.shape<1>
+! CHECK:  }
+! CHECK:  %[[VAL_13:.*]]:3 = hlfir.associate %[[VAL_12]](%[[VAL_11]]) {{.*}} : (!hlfir.expr<?xf32>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>, i1)
+! CHECK:  fir.call @_QPtakes_array(%[[VAL_13]]#1) {{.*}}: (!fir.ref<!fir.array<?xf32>>) -> ()
 contains
   function return_array()
     real :: return_array(n_common)
@@ -156,19 +162,18 @@ function return_array()
 
 ! Test host calling array internal procedure.
 ! Result depends on a common block variable declared in the internal procedure.
-! CHECK-LABEL: func @_QPhost8
+! CHECK-LABEL: func.func @_QPhost8
 subroutine host8()
   implicit none
   call takes_array(return_array())
-! CHECK:  %[[VAL_0:.*]] = arith.constant 0 : index
-! CHECK:  %[[VAL_1:.*]] = fir.address_of(@mycom_) : !fir.ref<!fir.array<4xi8>>
-! CHECK:  %[[VAL_3:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_0]] : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
-! CHECK:  %[[VAL_4:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<i8>) -> !fir.ref<i32>
-! CHECK:  %[[VAL_5:.*]] = fir.load %[[VAL_4]] : !fir.ref<i32>
-! CHECK:  %[[VAL_6:.*]] = fir.convert %[[VAL_5]] : (i32) -> index
-! CHECK:  %[[CMPI:.*]] = arith.cmpi sgt, %[[VAL_6]], %{{.*}} : index
-! CHECK:  %[[SELECT:.*]] = arith.select %[[CMPI]], %[[VAL_6]], %{{.*}} : index
-! CHECK:  %[[VAL_7:.*]] = fir.alloca !fir.array<?xf32>, %[[SELECT]] {bindc_name = ".result"}
+! CHECK:  fir.shape %[[SELECT:.*]] : (index) -> !fir.shape<1>
+! CHECK:  %[[VAL_9:.*]] = hlfir.eval_in_mem shape %[[VAL_8:.*]] : (!fir.shape<1>) -> !hlfir.expr<?xf32> {
+! CHECK:  ^bb0(%[[ARG:.*]]: !fir.ref<!fir.array<?xf32>>):
+! CHECK:    %[[RES:.*]] = fir.call @_QFhost8Preturn_array() {{.*}}: () -> !fir.array<?xf32>
+! CHECK:    fir.save_result %[[RES]] to %[[ARG]](%[[VAL_8]]) : !fir.array<?xf32>, !fir.ref<!fir.array<?xf32>>, !fir.shape<1>
+! CHECK:  }
+! CHECK:  %[[VAL_10:.*]]:3 = hlfir.associate %[[VAL_9]](%[[VAL_8]]) {{.*}} : (!hlfir.expr<?xf32>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>, i1)
+! CHECK:  fir.call @_QPtakes_array(%[[VAL_10]]#1) {{.*}}: (!fir.ref<!fir.array<?xf32>>) -> ()
 contains
   function return_array()
     integer :: n_common
@@ -185,18 +190,17 @@ subroutine host9()
   common /mycom/ n_common
   call internal_proc_a()
 contains
-! CHECK-LABEL: func private @_QFhost9Pinternal_proc_a
+! CHECK-LABEL: func.func private @_QFhost9Pinternal_proc_a
   subroutine internal_proc_a()
-! CHECK:  %[[VAL_0:.*]] = arith.constant 0 : index
-! CHECK:  %[[VAL_1:.*]] = fir.address_of(@mycom_) : !fir.ref<!fir.array<4xi8>>
-! CHECK:  %[[VAL_3:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_0]] : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
-! CHECK:  %[[VAL_4:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<i8>) -> !fir.ref<i32>
-! CHECK:  %[[VAL_5:.*]] = fir.load %[[VAL_4]] : !fir.ref<i32>
-! CHECK:  %[[VAL_6:.*]] = fir.convert %[[VAL_5]] : (i32) -> index
-! CHECK:  %[[VAL_7:.*]] = arith.cmpi sgt, %[[VAL_6]], %[[VAL_0]] : index
-! CHECK:  %[[VAL_8:.*]] = arith.select %[[VAL_7]], %[[VAL_6]], %[[VAL_0]] : index
-! CHECK:  %[[VAL_10:.*]] = fir.alloca !fir.array<?xf32>, %[[VAL_8]] {bindc_name = ".result"}
     call takes_array(return_array())
+! CHECK:  fir.shape %[[SELECT:.*]] : (index) -> !fir.shape<1>
+! CHECK:  %[[VAL_11:.*]] = hlfir.eval_in_mem shape %[[VAL_10:.*]] : (!fir.shape<1>) -> !hlfir.expr<?xf32> {
+! CHECK:  ^bb0(%[[ARG:.*]]: !fir.ref<!fir.array<?xf32>>):
+! CHECK:    %[[RES:.*]] = fir.call @_QFhost9Preturn_array() {{.*}}: () -> !fir.array<?xf32>
+! CHECK:    fir.save_result %[[RES]] to %[[ARG]](%[[VAL_10]]) : !fir.array<?xf32>, !fir.ref<!fir.array<?xf32>>, !fir.shape<1>
+! CHECK:  }
+! CHECK:  %[[VAL_12:.*]]:3 = hlfir.associate %[[VAL_11]](%[[VAL_10]]) {{.*}} : (!hlfir.expr<?xf32>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>, i1)
+! CHECK:  fir.call @_QPtakes_array(%[[VAL_12]]#1) {{.*}}: (!fir.ref<!fir.array<?xf32>>) -> ()
   end subroutine
   function return_array()
     use :: some_module
@@ -210,18 +214,17 @@ subroutine host10()
   implicit none
   call internal_proc_a()
 contains
-! CHECK-LABEL: func private @_QFhost10Pinternal_proc_a
+! CHECK-LABEL: func.func private @_QFhost10Pinternal_proc_a
   subroutine internal_proc_a()
     call takes_array(return_array())
-! CHECK:  %[[VAL_0:.*]] = arith.constant 0 : index
-! CHECK:  %[[VAL_1:.*]] = fir.address_of(@mycom_) : !fir.ref<!fir.array<4xi8>>
-! CHECK:  %[[VAL_3:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_0]] : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
-! CHECK:  %[[VAL_4:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<i8>) -> !fir.ref<i32>
-! CHECK:  %[[VAL_5:.*]] = fir.load %[[VAL_4]] : !fir.ref<i32>
-! CHECK:  %[[VAL_6:.*]] = fir.convert %[[VAL_5]] : (i32) -> index
-! CHECK:  %[[CMPI:.*]] = arith.cmpi sgt, %[[VAL_6]], %{{.*}} : index
-! CHECK:  %[[SELECT:.*]] = arith.select %[[CMPI]], %[[VAL_6]], %{{.*}} : index
-! CHECK:  %[[VAL_7:.*]] = fir.alloca !fir.array<?xf32>, %[[SELECT]] {bindc_name = ".result"}
+! CHECK:  fir.shape %[[SELECT:.*]] : (index) -> !fir.shape<1>
+! CHECK:  %[[VAL_9:.*]] = hlfir.eval_in_mem shape %[[VAL_8:.*]] : (!fir.shape<1>) -> !hlfir.expr<?xf32> {
+! CHECK:  ^bb0(%[[ARG:.*]]: !fir.ref<!fir.array<?xf32>>):
+! CHECK:    %[[RES:.*]] = fir.call @_QFhost10Preturn_array() {{.*}}: () -> !fir.array<?xf32>
+! CHECK:    fir.save_result %[[RES]] to %[[ARG]](%[[VAL_8]]) : !fir.array<?xf32>, !fir.ref<!fir.array<?xf32>>, !fir.shape<1>
+! CHECK:  }
+! CHECK:  %[[VAL_10:.*]]:3 = hlfir.associate %[[VAL_9]](%[[VAL_8]]) {{.*}} : (!hlfir.expr<?xf32>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>, i1)
+! CHECK:  fir.call @_QPtakes_array(%[[VAL_10]]#1) {{.*}}: (!fir.ref<!fir.array<?xf32>>) -> ()
   end subroutine
   function return_array()
     integer :: n_common
@@ -240,18 +243,20 @@ function foo()
   foo = 42
 end function
 end module
-! CHECK-LABEL: func @_QPtest_call_to_used_interface(
+! CHECK-LABEL: func.func @_QPtest_call_to_used_interface(
 ! CHECK-SAME:  %[[VAL_0:.*]]: !fir.boxproc<() -> ()>) {
 subroutine test_call_to_used_interface(dummy_proc)
   use define_interface
   procedure(foo) :: dummy_proc
   call takes_array(dummy_proc())
-! CHECK:  %[[VAL_1:.*]] = arith.constant 100 : index
-! CHECK:  %[[VAL_2:.*]] = fir.alloca !fir.array<100xf32> {bindc_name = ".result"}
-! CHECK:  %[[VAL_4:.*]] = fir.shape %[[VAL_1]] : (index) -> !fir.shape<1>
-! CHECK:  %[[VAL_5:.*]] = fir.box_addr %[[VAL_0]] : (!fir.boxproc<() -> ()>) -> (() -> !fir.array<100xf32>)
-! CHECK:  %[[VAL_6:.*]] = fir.call %[[VAL_5]]() {{.*}}: () -> !fir.array<100xf32>
-! CHECK:  fir.save_result %[[VAL_6]] to %[[VAL_2]](%[[VAL_4]]) : !fir.array<100xf32>, !fir.ref<!fir.array<100xf32>>, !fir.shape<1>
-! CHECK:  %[[VAL_7:.*]] = fir.convert %[[VAL_2]] : (!fir.ref<!fir.array<100xf32>>) -> !fir.ref<!fir.array<?xf32>>
-! CHECK:  fir.call @_QPtakes_array(%[[VAL_7]]) {{.*}}: (!fir.ref<!fir.array<?xf32>>) -> ()
+! CHECK:  fir.shape %[[VAL_9:.*]] : (index) -> !fir.shape<1>
+! CHECK:  %[[VAL_11:.*]] = hlfir.eval_in_mem shape %[[VAL_10:.*]] : (!fir.shape<1>) -> !hlfir.expr<100xf32> {
+! CHECK:  ^bb0(%[[ARG:.*]]: !fir.ref<!fir.array<100xf32>>):
+! CHECK:    %[[VAL_12:.*]] = fir.box_addr %[[VAL_0]] : (!fir.boxproc<() -> ()>) -> (() -> !fir.array<100xf32>)
+! CHECK:    %[[VAL_13:.*]] = fir.call %[[VAL_12]]() fastmath<contract> : () -> !fir.array<100xf32>
+! CHECK:    fir.save_result %[[VAL_13]] to %[[ARG]](%[[VAL_10]]) : !fir.array<100xf32>, !fir.ref<!fir.array<100xf32>>, !fir.shape<1>
+! CHECK:  }
+! CHECK:  %[[VAL_14:.*]]:3 = hlfir.associate %[[VAL_11]](%[[VAL_10]]) {adapt.valuebyref} : (!hlfir.expr<100xf32>, !fir.shape<1>) -> (!fir.ref<!fir.array<100xf32>>, !fir.ref<!fir.array<100xf32>>, i1)
+! CHECK:  %[[VAL_15:.*]] = fir.convert %[[VAL_14]]#0 : (!fir.ref<!fir.array<100xf32>>) -> !fir.ref<!fir.array<?xf32>>
+! CHECK:  fir.call @_QPtakes_array(%[[VAL_15]]) fastmath<contract> : (!fir.ref<!fir.array<?xf32>>) -> ()
 end subroutine
diff --git a/flang/test/Lower/explicit-interface-results.f90 b/flang/test/Lower/explicit-interface-results.f90
index 8d51786da14ca..acfbf046e840b 100644
--- a/flang/test/Lower/explicit-interface-results.f90
+++ b/flang/test/Lower/explicit-interface-results.f90
@@ -1,86 +1,86 @@
-! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s
 
 module callee
 implicit none
 contains
-! CHECK-LABEL: func @_QMcalleePreturn_cst_array() -> !fir.array<20x30xf32>
+! CHECK-LABEL: func.func @_QMcalleePreturn_cst_array() -> !fir.array<20x30xf32>
 function return_cst_array()
   real :: return_cst_array(20, 30)
 end function
 
-! CHECK-LABEL: func @_QMcalleePreturn_dyn_array(
+! CHECK-LABEL: func.func @_QMcalleePreturn_dyn_array(
 ! CHECK-SAME: %{{.*}}: !fir.ref<i32>{{.*}}, %{{.*}}: !fir.ref<i32>{{.*}}) -> !fir.array<?x?xf32>
 function return_dyn_array(m, n)
   integer :: m, n
   real :: return_dyn_array(m, n)
 end function
 
-! CHECK-LABEL: func @_QMcalleePreturn_cst_char_cst_array() -> !fir.array<20x30x!fir.char<1,10>>
+! CHECK-LABEL: func.func @_QMcalleePreturn_cst_char_cst_array() -> !fir.array<20x30x!fir.char<1,10>>
 function return_cst_char_cst_array()
   character(10) :: return_cst_char_cst_array(20, 30)
 end function
 
-! CHECK-LABEL: func @_QMcalleePreturn_dyn_char_cst_array(
+! CHECK-LABEL: func.func @_QMcalleePreturn_dyn_char_cst_array(
 ! CHECK-SAME: %{{.*}}: !fir.ref<i32>{{.*}}) -> !fir.array<20x30x!fir.char<1,?>>
 function return_dyn_char_cst_array(l)
   integer :: l
   character(l) :: return_dyn_char_cst_array(20, 30)
 end function
 
-! CHECK-LABEL: func @_QMcalleePreturn_cst_char_dyn_array(
+! CHECK-LABEL: func.func @_QMcalleePreturn_cst_char_dyn_array(
 ! CHECK-SAME: %{{.*}}: !fir.ref<i32>{{.*}}, %{{.*}}: !fir.ref<i32>{{.*}}) -> !fir.array<?x?x!fir.char<1,10>>
 function return_cst_char_dyn_array(m, n)
   integer :: m, n
   character(10) :: return_cst_char_dyn_array(m, n)
 end function
 
-! CHECK-LABEL: func @_QMcalleePreturn_dyn_char_dyn_array(
+! CHECK-LABEL: func.func @_QMcalleePreturn_dyn_char_dyn_array(
 ! CHECK-SAME: %{{.*}}: !fir.ref<i32>{{.*}}, %{{.*}}: !fir.ref<i32>{{.*}}, %{{.*}}: !fir.ref<i32>{{.*}}) -> !fir.array<?x?x!fir.char<1,?>>
 function return_dyn_char_dyn_array(l, m, n)
   integer :: l, m, n
   character(l) :: return_dyn_char_dyn_array(m, n)
 end function
 
-! CHECK-LABEL: func @_QMcalleePreturn_alloc() -> !fir.box<!fir.heap<!fir.array<?xf32>>>
+! CHECK-LABEL: func.func @_QMcalleePreturn_alloc() -> !fir.box<!fir.heap<!fir.array<?xf32>>>
 function return_alloc()
   real, allocatable :: return_alloc(:)
 end function
 
-! CHECK-LABEL: func @_QMcalleePreturn_cst_char_alloc() -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>
+! CHECK-LABEL: func.func @_QMcalleePreturn_cst_char_alloc() -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>
 function return_cst_char_alloc()
   character(10), allocatable :: return_cst_char_alloc(:)
 end function
 
-! CHECK-LABEL: func @_QMcalleePreturn_dyn_char_alloc(
+! CHECK-LABEL: func.func @_QMcalleePreturn_dyn_char_alloc(
 ! CHECK-SAME: %{{.*}}: !fir.ref<i32>{{.*}}) -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>
 function return_dyn_char_alloc(l)
   integer :: l
   character(l), allocatable :: return_dyn_char_alloc(:)
 end function
 
-! CHECK-LABEL: func @_QMcalleePreturn_def_char_alloc() -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>
+! CHECK-LABEL: func.func @_QMcalleePreturn_def_char_alloc() -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>
 function return_def_char_alloc()
   character(:), allocatable :: return_def_char_alloc(:)
 end function
 
-! CHECK-LABEL: func @_QMcalleePreturn_pointer() -> !fir.box<!fir.ptr<!fir.array<?xf32>>>
+! CHECK-LABEL: func.func @_QMcalleePreturn_pointer() -> !fir.box<!fir.ptr<!fir.array<?xf32>>>
 function return_pointer()
   real, pointer :: return_pointer(:)
 end function
 
-! CHECK-LABEL: func @_QMcalleePreturn_cst_char_pointer() -> !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,10>>>>
+! CHECK-LABEL: func.func @_QMcalleePreturn_cst_char_pointer() -> !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,10>>>>
 function return_cst_char_pointer()
   character(10), pointer :: return_cst_char_pointer(:)
 end function
 
-! CHECK-LABEL: func @_QMcalleePreturn_dyn_char_pointer(
+! CHECK-LABEL: func.func @_QMcalleePreturn_dyn_char_pointer(
 ! CHECK-SAME: %{{.*}}: !fir.ref<i32>{{.*}}) -> !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>
 function return_dyn_char_pointer(l)
   integer :: l
   character(l), pointer :: return_dyn_char_pointer(:)
 end function
 
-! CHECK-LABEL: func @_QMcalleePreturn_def_char_pointer() -> !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>
+! CHECK-LABEL: func.func @_QMcalleePreturn_def_char_pointer() -> !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>
 function return_def_char_pointer()
   character(:), pointer :: return_def_char_pointer(:)
 end function
@@ -90,212 +90,181 @@ module caller
   use callee
 contains
 
-! CHECK-LABEL: func @_QMcallerPcst_array()
+! CHECK-LABEL: func.func @_QMcallerPcst_array()
 subroutine cst_array()
-  ! CHECK: %[[alloc:.*]] = fir.alloca !fir.array<20x30xf32> {{{.*}}bindc_name = ".result"}
-  ! CHECK: %[[shape:.*]] = fir.shape %{{.*}}, {{.*}} : (index, index) -> !fir.shape<2>
-  ! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_cst_array() {{.*}}: () -> !fir.array<20x30xf32>
-  ! CHECK: fir.save_result %[[res]] to %[[alloc]](%[[shape]]) : !fir.array<20x30xf32>, !fir.ref<!fir.array<20x30xf32>>, !fir.shape<2>
+  ! CHECK: %[[VAL_14:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2>
+  ! CHECK: %[[VAL_15:.*]] = hlfir.eval_in_mem shape %[[VAL_14]] : (!fir.shape<2>) -> !hlfir.expr<20x30xf32> {
+  ! CHECK: ^bb0(%[[ARG:.*]]: !fir.ref<!fir.array<20x30xf32>>):
+  ! CHECK:   %[[RES:.*]] = fir.call @_QMcalleePreturn_cst_array() {{.*}}: () -> !fir.array<20x30xf32>
+  ! CHECK:   fir.save_result %[[RES]] to %[[ARG]](%[[VAL_14]]) : !fir.array<20x30xf32>, !fir.ref<!fir.array<20x30xf32>>, !fir.shape<2>
+  ! CHECK: }
+  ! CHECK: %[[VAL_16:.*]]:3 = hlfir.associate %[[VAL_15]](%[[VAL_14]])
   print *, return_cst_array()
 end subroutine
 
-! CHECK-LABEL: func @_QMcallerPcst_char_cst_array()
+! CHECK-LABEL: func.func @_QMcallerPcst_char_cst_array()
 subroutine cst_char_cst_array()
-  ! CHECK: %[[alloc:.*]] = fir.alloca !fir.array<20x30x!fir.char<1,10>> {{{.*}}bindc_name = ".result"}
-  ! CHECK: %[[shape:.*]] = fir.shape %{{.*}}, {{.*}} : (index, index) -> !fir.shape<2>
-  ! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_cst_char_cst_array() {{.*}}: () -> !fir.array<20x30x!fir.char<1,10>>
-  ! CHECK: fir.save_result %[[res]] to %[[alloc]](%[[shape]]) typeparams %{{.*}} : !fir.array<20x30x!fir.char<1,10>>, !fir.ref<!fir.array<20x30x!fir.char<1,10>>>, !fir.shape<2>, index
+  ! CHECK: %[[VAL_17:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2>
+  ! CHECK: %[[VAL_18:.*]] = hlfir.eval_in_mem shape %[[VAL_17]] typeparams %{{.*}} : (!fir.shape<2>, index) -> !hlfir.expr<20x30x!fir.char<1,10>> {
+  ! CHECK: ^bb0(%[[ARG:.*]]: !fir.ref<!fir.array<20x30x!fir.char<1,10>>>):
+  ! CHECK:   %[[RES:.*]] = fir.call @_QMcalleePreturn_cst_char_cst_array() {{.*}}: () -> !fir.array<20x30x!fir.char<1,10>>
+  ! CHECK:   fir.save_result %[[RES]] to %[[ARG]](%[[VAL_17]]) typeparams %{{.*}} : !fir.array<20x30x!fir.char<1,10>>, !fir.ref<!fir.array<20x30x!fir.char<1,10>>>, !fir.shape<2>, index
+  ! CHECK: }
+  ! CHECK: %[[VAL_19:.*]]:3 = hlfir.associate %[[VAL_18]](%[[VAL_17]]) typeparams %{{.*}}
   print *, return_cst_char_cst_array()
 end subroutine
 
-! CHECK-LABEL: func @_QMcallerPalloc()
+! CHECK-LABEL: func.func @_QMcallerPalloc()
 subroutine alloc()
-  ! CHECK: %[[alloc:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?xf32>>> {{{.*}}bindc_name = ".result"}
-  ! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_alloc() {{.*}}: () -> !fir.box<!fir.heap<!fir.array<?xf32>>>
-  ! CHECK: fir.save_result %[[res]] to %[[alloc]] : !fir.box<!fir.heap<!fir.array<?xf32>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
+  ! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?xf32>>> {bindc_name = ".result"}
+  ! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = ".tmp.func_result"}
+  ! CHECK: %[[VAL_6:.*]] = fir.call @_QMcalleePreturn_alloc() {{.*}}: () -> !fir.box<!fir.heap<!fir.array<?xf32>>>
+  ! CHECK: fir.save_result %[[VAL_6]] to %[[VAL_5]]#0 : !fir.box<!fir.heap<!fir.array<?xf32>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
   print *, return_alloc()
   ! CHECK: _FortranAioOutputDescriptor
-  ! CHECK: %[[load:.*]] = fir.load %[[alloc]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
+  ! CHECK: %[[load:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
   ! CHECK: %[[addr:.*]] = fir.box_addr %[[load]] : (!fir.box<!fir.heap<!fir.array<?xf32>>>) -> !fir.heap<!fir.array<?xf32>>
   ! CHECK: %[[cmpi:.*]] = arith.cmpi
   ! CHECK: fir.if %[[cmpi]]
   ! CHECK: fir.freemem %[[addr]] : !fir.heap<!fir.array<?xf32>>
 end subroutine
 
-! CHECK-LABEL: func @_QMcallerPcst_char_alloc()
+! CHECK-LABEL: func.func @_QMcallerPcst_char_alloc()
 subroutine cst_char_alloc()
-  ! CHECK: %[[alloc:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>> {{{.*}}bindc_name = ".result"}
-  ! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_cst_char_alloc() {{.*}}: () -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>
-  ! CHECK: fir.save_result %[[res]] to %[[alloc]] : !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>>
+  ! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>> {bindc_name = ".result"}
+  ! CHECK: %[[VAL_9:.*]]:2 = hlfir.declare %[[VAL_0]] typeparams %{{.*}} {uniq_name = ".tmp.func_result"}
+  ! CHECK: %[[VAL_10:.*]] = fir.call @_QMcalleePreturn_cst_char_alloc() {{.*}}: () -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>
+  ! CHECK: fir.save_result %[[VAL_10]] to %[[VAL_9]]#0 : !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>>
   print *, return_cst_char_alloc()
   ! CHECK: _FortranAioOutputDescriptor
-  ! CHECK: %[[load:.*]] = fir.load %[[alloc]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>>
+  ! CHECK: %[[load:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>>
   ! CHECK: %[[addr:.*]] = fir.box_addr %[[load]] : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>) -> !fir.heap<!fir.array<?x!fir.char<1,10>>>
   ! CHECK: %[[cmpi:.*]] = arith.cmpi
   ! CHECK: fir.if %[[cmpi]]
   ! CHECK: fir.freemem %[[addr]] : !fir.heap<!fir.array<?x!fir.char<1,10>>>
 end subroutine
 
-! CHECK-LABEL: func @_QMcallerPdef_char_alloc()
+! CHECK-LABEL: func.func @_QMcallerPdef_char_alloc()
 subroutine def_char_alloc()
-  ! CHECK: %[[alloc:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>> {{{.*}}bindc_name = ".result"}
-  ! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_def_char_alloc() {{.*}}: () -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>
-  ! CHECK: fir.save_result %[[res]] to %[[alloc]] : !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
+  ! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>> {bindc_name = ".result"}
+  ! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = ".tmp.func_result"}
+  ! CHECK: %[[VAL_6:.*]] = fir.call @_QMcalleePreturn_def_char_alloc() {{.*}}: () -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>
+  ! CHECK: fir.save_result %[[VAL_6]] to %[[VAL_5]]#0 : !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
   print *, return_def_char_alloc()
   ! CHECK: _FortranAioOutputDescriptor
-  ! CHECK: %[[load:.*]] = fir.load %[[alloc]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
+  ! CHECK: %[[load:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
   ! CHECK: %[[addr:.*]] = fir.box_addr %[[load]] : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>) -> !fir.heap<!fir.array<?x!fir.char<1,?>>>
   ! CHECK: %[[cmpi:.*]] = arith.cmpi
   ! CHECK: fir.if %[[cmpi]]
   ! CHECK: fir.freemem %[[addr]] : !fir.heap<!fir.array<?x!fir.char<1,?>>>
 end subroutine
 
-! CHECK-LABEL: func @_QMcallerPpointer_test()
+! CHECK-LABEL: func.func @_QMcallerPpointer_test()
 subroutine pointer_test()
-  ! CHECK: %[[alloc:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?xf32>>> {{{.*}}bindc_name = ".result"}
-  ! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_pointer() {{.*}}: () -> !fir.box<!fir.ptr<!fir.array<?xf32>>>
-  ! CHECK: fir.save_result %[[res]] to %[[alloc]] : !fir.box<!fir.ptr<!fir.array<?xf32>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
+  ! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?xf32>>> {bindc_name = ".result"}
+  ! CHECK: %[[VAL_5:.*]] = fir.call @_QMcalleePreturn_pointer() {{.*}}: () -> !fir.box<!fir.ptr<!fir.array<?xf32>>>
+  ! CHECK: fir.save_result %[[VAL_5]] to %[[VAL_0]] : !fir.box<!fir.ptr<!fir.array<?xf32>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
   print *, return_pointer()
   ! CHECK-NOT: fir.freemem
 end subroutine
 
-! CHECK-LABEL: func @_QMcallerPcst_char_pointer()
+! CHECK-LABEL: func.func @_QMcallerPcst_char_pointer()
 subroutine cst_char_pointer()
-  ! CHECK: %[[alloc:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,10>>>> {{{.*}}bindc_name = ".result"}
-  ! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_cst_char_pointer() {{.*}}: () -> !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,10>>>>
-  ! CHECK: fir.save_result %[[res]] to %[[alloc]] : !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,10>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,10>>>>>
+  ! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,10>>>> {bindc_name = ".result"}
+  ! CHECK: %[[VAL_9:.*]] = fir.call @_QMcalleePreturn_cst_char_pointer() {{.*}}: () -> !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,10>>>>
+  ! CHECK: fir.save_result %[[VAL_9]] to %[[VAL_0]] : !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,10>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,10>>>>>
   print *, return_cst_char_pointer()
   ! CHECK-NOT: fir.freemem
 end subroutine
 
-! CHECK-LABEL: func @_QMcallerPdef_char_pointer()
+! CHECK-LABEL: func.func @_QMcallerPdef_char_pointer()
 subroutine def_char_pointer()
-  ! CHECK: %[[alloc:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>> {{{.*}}bindc_name = ".result"}
-  ! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_def_char_pointer() {{.*}}: () -> !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>
-  ! CHECK: fir.save_result %[[res]] to %[[alloc]] : !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>>
+  ! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>> {bindc_name = ".result"}
+  ! CHECK: %[[VAL_5:.*]] = fir.call @_QMcalleePreturn_def_char_pointer() {{.*}}: () -> !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>
+  ! CHECK: fir.save_result %[[VAL_5]] to %[[VAL_0]] : !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>>
   print *, return_def_char_pointer()
   ! CHECK-NOT: fir.freemem
 end subroutine
 
-! CHECK-LABEL: func @_QMcallerPdyn_array(
+! CHECK-LABEL: func.func @_QMcallerPdyn_array(
 ! CHECK-SAME: %[[m:.*]]: !fir.ref<i32>{{.*}}, %[[n:.*]]: !fir.ref<i32>{{.*}}) {
 subroutine dyn_array(m, n)
   integer :: m, n
-  ! CHECK-DAG: %[[mload:.*]] = fir.load %[[m]] : !fir.ref<i32>
-  ! CHECK-DAG: %[[mcast:.*]] = fir.convert %[[mload]] : (i32) -> i64
-  ! CHECK-DAG: %[[msub:.*]] = arith.subi %[[mcast]], %c1{{.*}} : i64
-  ! CHECK-DAG: %[[madd:.*]] = arith.addi %[[msub]], %c1{{.*}} : i64
-  ! CHECK-DAG: %[[mcast2:.*]] = fir.convert %[[madd]] : (i64) -> index
-  ! CHECK-DAG: %[[mcmpi:.*]] = arith.cmpi sgt, %[[mcast2]], %{{.*}} : index
-  ! CHECK-DAG: %[[mselect:.*]] = arith.select %[[mcmpi]], %[[mcast2]], %{{.*}} : index
-  ! CHECK-DAG: %[[nload:.*]] = fir.load %[[n]] : !fir.ref<i32>
-  ! CHECK-DAG: %[[ncast:.*]] = fir.convert %[[nload]] : (i32) -> i64
-  ! CHECK-DAG: %[[nsub:.*]] = arith.subi %[[ncast]], %c1{{.*}} : i64
-  ! CHECK-DAG: %[[nadd:.*]] = arith.addi %[[nsub]], %c1{{.*}} : i64
-  ! CHECK-DAG: %[[ncast2:.*]] = fir.convert %[[nadd]] : (i64) -> index
-  ! CHECK-DAG: %[[ncmpi:.*]] = arith.cmpi sgt, %[[ncast2]], %{{.*}} : index
-  ! CHECK-DAG: %[[nselect:.*]] = arith.select %[[ncmpi]], %[[ncast2]], %{{.*}} : index
-  ! CHECK: %[[shape:.*]] = fir.shape %[[mselect]], %[[nselect]] : (index, index) -> !fir.shape<2>
-  ! CHECK: %[[tmp:.*]] = fir.alloca !fir.array<?x?xf32>, %[[mselect]], %[[nselect]]
-  ! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_dyn_array(%[[m]], %[[n]]) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>) -> !fir.array<?x?xf32>
-  ! CHECK: fir.save_result %[[res]] to %[[tmp]](%[[shape]]) : !fir.array<?x?xf32>, !fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>
+  ! CHECK: %[[VAL_22:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2>
+  ! CHECK: %[[VAL_23:.*]] = hlfir.eval_in_mem shape %[[VAL_22]] : (!fir.shape<2>) -> !hlfir.expr<?x?xf32> {
+  ! CHECK: ^bb0(%[[ARG:.*]]: !fir.ref<!fir.array<?x?xf32>>):
+  ! CHECK:   %[[RES:.*]] = fir.call @_QMcalleePreturn_dyn_array(%{{.*}}, %{{.*}}) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>) -> !fir.array<?x?xf32>
+  ! CHECK:   fir.save_result %[[RES]] to %[[ARG]](%[[VAL_22]]) : !fir.array<?x?xf32>, !fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>
+  ! CHECK: }
+  ! CHECK: %[[VAL_24:.*]]:3 = hlfir.associate %[[VAL_23]](%[[VAL_22]])
   print *, return_dyn_array(m, n)
 end subroutine
 
-! CHECK-LABEL: func @_QMcallerPdyn_char_cst_array(
+! CHECK-LABEL: func.func @_QMcallerPdyn_char_cst_array(
 ! CHECK-SAME: %[[l:.*]]: !fir.ref<i32>{{.*}}) {
 subroutine dyn_char_cst_array(l)
   integer :: l
-  ! CHECK: %[[lload:.*]] = fir.load %[[l]] : !fir.ref<i32>
-  ! CHECK: %[[lcast:.*]] = fir.convert %[[lload]] : (i32) -> i64
-  ! CHECK: %[[lcast2:.*]] = fir.convert %[[lcast]] : (i64) -> index
-  ! CHECK: %[[cmpi:.*]] = arith.cmpi sgt, %[[lcast2]], %{{.*}} : index
-  ! CHECK: %[[select:.*]] = arith.select %[[cmpi]], %[[lcast2]], %{{.*}} : index
-  ! CHECK: %[[shape:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2>
-  ! CHECK: %[[tmp:.*]] = fir.alloca !fir.array<20x30x!fir.char<1,?>>(%[[select]] : index)
-  ! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_dyn_char_cst_array(%[[l]]) {{.*}}: (!fir.ref<i32>) -> !fir.array<20x30x!fir.char<1,?>>
-  ! CHECK: fir.save_result %[[res]] to %[[tmp]](%[[shape]]) typeparams %[[select]] : !fir.array<20x30x!fir.char<1,?>>, !fir.ref<!fir.array<20x30x!fir.char<1,?>>>, !fir.shape<2>, index
+  ! CHECK: %[[VAL_21:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2>
+  ! CHECK: %[[VAL_22:.*]] = hlfir.eval_in_mem shape %[[VAL_21]] typeparams %[[VAL_20:.*]] : (!fir.shape<2>, index) -> !hlfir.expr<20x30x!fir.char<1,?>> {
+  ! CHECK: ^bb0(%[[ARG:.*]]: !fir.ref<!fir.array<20x30x!fir.char<1,?>>>):
+  ! CHECK:   %[[RES:.*]] = fir.call @_QMcalleePreturn_dyn_char_cst_array(%{{.*}}) {{.*}}: (!fir.ref<i32>) -> !fir.array<20x30x!fir.char<1,?>>
+  ! CHECK:   fir.save_result %[[RES]] to %[[ARG]](%[[VAL_21]]) typeparams %[[VAL_20]] : !fir.array<20x30x!fir.char<1,?>>, !fir.ref<!fir.array<20x30x!fir.char<1,?>>>, !fir.shape<2>, index
+  ! CHECK: }
+  ! CHECK: %[[VAL_23:.*]]:3 = hlfir.associate %[[VAL_22]](%[[VAL_21]]) typeparams %[[VAL_20]]
   print *, return_dyn_char_cst_array(l)
 end subroutine
 
-! CHECK-LABEL: func @_QMcallerPcst_char_dyn_array(
+! CHECK-LABEL: func.func @_QMcallerPcst_char_dyn_array(
 ! CHECK-SAME: %[[m:.*]]: !fir.ref<i32>{{.*}}, %[[n:.*]]: !fir.ref<i32>{{.*}}) {
 subroutine cst_char_dyn_array(m, n)
   integer :: m, n
-  ! CHECK-DAG: %[[mload:.*]] = fir.load %[[m]] : !fir.ref<i32>
-  ! CHECK-DAG: %[[mcast:.*]] = fir.convert %[[mload]] : (i32) -> i64
-  ! CHECK-DAG: %[[msub:.*]] = arith.subi %[[mcast]], %c1{{.*}} : i64
-  ! CHECK-DAG: %[[madd:.*]] = arith.addi %[[msub]], %c1{{.*}} : i64
-  ! CHECK-DAG: %[[mcast2:.*]] = fir.convert %[[madd]] : (i64) -> index
-  ! CHECK-DAG: %[[mcmpi:.*]] = arith.cmpi sgt, %[[mcast2]], %{{.*}} : index
-  ! CHECK-DAG: %[[mselect:.*]] = arith.select %[[mcmpi]], %[[mcast2]], %{{.*}} : index
-  ! CHECK-DAG: %[[nload:.*]] = fir.load %[[n]] : !fir.ref<i32>
-  ! CHECK-DAG: %[[ncast:.*]] = fir.convert %[[nload]] : (i32) -> i64
-  ! CHECK-DAG: %[[nsub:.*]] = arith.subi %[[ncast]], %c1{{.*}} : i64
-  ! CHECK-DAG: %[[nadd:.*]] = arith.addi %[[nsub]], %c1{{.*}} : i64
-  ! CHECK-DAG: %[[ncast2:.*]] = fir.convert %[[nadd]] : (i64) -> index
-  ! CHECK-DAG: %[[ncmpi:.*]] = arith.cmpi sgt, %[[ncast2]], %{{.*}} : index
-  ! CHECK-DAG: %[[nselect:.*]] = arith.select %[[ncmpi]], %[[ncast2]], %{{.*}} : index
-  ! CHECK: %[[shape:.*]] = fir.shape %[[mselect]], %[[nselect]] : (index, index) -> !fir.shape<2>
-  ! CHECK: %[[tmp:.*]] = fir.alloca !fir.array<?x?x!fir.char<1,10>>, %[[mselect]], %[[nselect]]
-  ! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_cst_char_dyn_array(%[[m]], %[[n]]) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>) -> !fir.array<?x?x!fir.char<1,10>>
-  ! CHECK: fir.save_result %[[res]] to %[[tmp]](%[[shape]]) typeparams {{.*}} : !fir.array<?x?x!fir.char<1,10>>, !fir.ref<!fir.array<?x?x!fir.char<1,10>>>, !fir.shape<2>, index
+  ! CHECK: %[[VAL_25:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2>
+  ! CHECK: %[[VAL_26:.*]] = hlfir.eval_in_mem shape %[[VAL_25]] typeparams %[[VAL_24:.*]] : (!fir.shape<2>, index) -> !hlfir.expr<?x?x!fir.char<1,10>> {
+  ! CHECK: ^bb0(%[[ARG:.*]]: !fir.ref<!fir.array<?x?x!fir.char<1,10>>>):
+  ! CHECK:   %[[RES:.*]] = fir.call @_QMcalleePreturn_cst_char_dyn_array(%{{.*}}, %{{.*}}) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>) -> !fir.array<?x?x!fir.char<1,10>>
+  ! CHECK:   fir.save_result %[[RES]] to %[[ARG]](%[[VAL_25]]) typeparams %[[VAL_24]] : !fir.array<?x?x!fir.char<1,10>>, !fir.ref<!fir.array<?x?x!fir.char<1,10>>>, !fir.shape<2>, index
+  ! CHECK: }
+  ! CHECK: %[[VAL_27:.*]]:3 = hlfir.associate %[[VAL_26]](%[[VAL_25]]) typeparams %[[VAL_24]]
   print *, return_cst_char_dyn_array(m, n)
 end subroutine
 
-! CHECK-LABEL: func @_QMcallerPdyn_char_dyn_array(
+! CHECK-LABEL: func.func @_QMcallerPdyn_char_dyn_array(
 ! CHECK-SAME: %[[l:.*]]: !fir.ref<i32>{{.*}}, %[[m:.*]]: !fir.ref<i32>{{.*}}, %[[n:.*]]: !fir.ref<i32>{{.*}}) {
 subroutine dyn_char_dyn_array(l, m, n)
-  ! CHECK-DAG: %[[mload:.*]] = fir.load %[[m]] : !fir.ref<i32>
-  ! CHECK-DAG: %[[mcast:.*]] = fir.convert %[[mload]] : (i32) -> i64
-  ! CHECK-DAG: %[[msub:.*]] = arith.subi %[[mcast]], %c1{{.*}} : i64
-  ! CHECK-DAG: %[[madd:.*]] = arith.addi %[[msub]], %c1{{.*}} : i64
-  ! CHECK-DAG: %[[mcast2:.*]] = fir.convert %[[madd]] : (i64) -> index
-  ! CHECK-DAG: %[[mcmpi:.*]] = arith.cmpi sgt, %[[mcast2]], %{{.*}} : index
-  ! CHECK-DAG: %[[mselect:.*]] = arith.select %[[mcmpi]], %[[mcast2]], %{{.*}} : index
-
-  ! CHECK-DAG: %[[nload:.*]] = fir.load %[[n]] : !fir.ref<i32>
-  ! CHECK-DAG: %[[ncast:.*]] = fir.convert %[[nload]] : (i32) -> i64
-  ! CHECK-DAG: %[[nsub:.*]] = arith.subi %[[ncast]], %c1{{.*}} : i64
-  ! CHECK-DAG: %[[nadd:.*]] = arith.addi %[[nsub]], %c1{{.*}} : i64
-  ! CHECK-DAG: %[[ncast2:.*]] = fir.convert %[[nadd]] : (i64) -> index
-  ! CHECK-DAG: %[[ncmpi:.*]] = arith.cmpi sgt, %[[ncast2]], %{{.*}} : index
-  ! CHECK-DAG: %[[nselect:.*]] = arith.select %[[ncmpi]], %[[ncast2]], %{{.*}} : index
-
-  ! CHECK-DAG: %[[lload:.*]] = fir.load %[[l]] : !fir.ref<i32>
-  ! CHECK-DAG: %[[lcast:.*]] = fir.convert %[[lload]] : (i32) -> i64
-  ! CHECK-DAG: %[[lcast2:.*]] = fir.convert %[[lcast]] : (i64) -> index
-  ! CHECK-DAG: %[[lcmpi:.*]] = arith.cmpi sgt, %[[lcast2]], %{{.*}} : index
-  ! CHECK-DAG: %[[lselect:.*]] = arith.select %[[lcmpi]], %[[lcast2]], %{{.*}} : index
-  ! CHECK: %[[shape:.*]] = fir.shape %[[mselect]], %[[nselect]] : (index, index) -> !fir.shape<2>
-  ! CHECK: %[[tmp:.*]] = fir.alloca !fir.array<?x?x!fir.char<1,?>>(%[[lselect]] : index), %[[mselect]], %[[nselect]]
-  ! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_dyn_char_dyn_array(%[[l]], %[[m]], %[[n]]) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>, !fir.ref<i32>) -> !fir.array<?x?x!fir.char<1,?>>
-  ! CHECK: fir.save_result %[[res]] to %[[tmp]](%[[shape]]) typeparams {{.*}} : !fir.array<?x?x!fir.char<1,?>>, !fir.ref<!fir.array<?x?x!fir.char<1,?>>>, !fir.shape<2>, index
+  ! CHECK: %[[VAL_29:.*]] = fir.shape %{{.*}}, %{{.*}} : (index, index) -> !fir.shape<2>
+  ! CHECK: %[[VAL_30:.*]] = hlfir.eval_in_mem shape %[[VAL_29]] typeparams %[[VAL_28:.*]] : (!fir.shape<2>, index) -> !hlfir.expr<?x?x!fir.char<1,?>> {
+  ! CHECK: ^bb0(%[[ARG:.*]]: !fir.ref<!fir.array<?x?x!fir.char<1,?>>>):
+  ! CHECK:   %[[RES:.*]] = fir.call @_QMcalleePreturn_dyn_char_dyn_array(%{{.*}}, %{{.*}}, %{{.*}}) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>, !fir.ref<i32>) -> !fir.array<?x?x!fir.char<1,?>>
+  ! CHECK:   fir.save_result %[[RES]] to %[[ARG]](%[[VAL_29]]) typeparams %[[VAL_28]] : !fir.array<?x?x!fir.char<1,?>>, !fir.ref<!fir.array<?x?x!fir.char<1,?>>>, !fir.shape<2>, index
+  ! CHECK: }
+  ! CHECK: %[[VAL_31:.*]]:3 = hlfir.associate %[[VAL_30]](%[[VAL_29]]) typeparams %[[VAL_28]]
   integer :: l, m, n
   print *, return_dyn_char_dyn_array(l, m, n)
 end subroutine
 
-! CHECK-LABEL: @_QMcallerPdyn_char_alloc
+! CHECK-LABEL: func.func @_QMcallerPdyn_char_alloc
 subroutine dyn_char_alloc(l)
   integer :: l
-  ! CHECK: %[[alloc:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>> {{{.*}}bindc_name = ".result"}
-  ! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_dyn_char_alloc({{.*}}) {{.*}}: (!fir.ref<i32>) -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>
-  ! CHECK: fir.save_result %[[res]] to %[[alloc]] : !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
+  ! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>> {bindc_name = ".result"}
+  ! CHECK: %[[VAL_13:.*]]:2 = hlfir.declare %[[VAL_0]] typeparams %[[VAL_11:.*]] {uniq_name = ".tmp.func_result"}
+  ! CHECK: %[[VAL_14:.*]] = fir.call @_QMcalleePreturn_dyn_char_alloc({{.*}}) {{.*}}: (!fir.ref<i32>) -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>
+  ! CHECK: fir.save_result %[[VAL_14]] to %[[VAL_13]]#0 : !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
   print *, return_dyn_char_alloc(l)
   ! CHECK: _FortranAioOutputDescriptor
-  ! CHECK: %[[load:.*]] = fir.load %[[alloc]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
+  ! CHECK: %[[load:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
   ! CHECK: %[[addr:.*]] = fir.box_addr %[[load]] : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>) -> !fir.heap<!fir.array<?x!fir.char<1,?>>>
   ! CHECK: %[[cmpi:.*]] = arith.cmpi
   ! CHECK: fir.if %[[cmpi]]
   ! CHECK: fir.freemem %[[addr]] : !fir.heap<!fir.array<?x!fir.char<1,?>>>
 end subroutine
 
-! CHECK-LABEL: @_QMcallerPdyn_char_pointer
+! CHECK-LABEL: func.func @_QMcallerPdyn_char_pointer
 subroutine dyn_char_pointer(l)
   integer :: l
-  ! CHECK: %[[alloc:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>> {{{.*}}bindc_name = ".result"}
-  ! CHECK: %[[res:.*]] = fir.call @_QMcalleePreturn_dyn_char_pointer({{.*}}) {{.*}}: (!fir.ref<i32>) -> !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>
-  ! CHECK: fir.save_result %[[res]] to %[[alloc]] : !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>>
+  ! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>> {bindc_name = ".result"}
+  ! CHECK: %[[VAL_13:.*]] = fir.call @_QMcalleePreturn_dyn_char_pointer({{.*}}) {{.*}}: (!fir.ref<i32>) -> !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>
+  ! CHECK: fir.save_result %[[VAL_13]] to %[[VAL_0]] : !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>>
+  ! CHECK: %[[VAL_14:.*]]:2 = hlfir.declare %[[VAL_0]] typeparams %[[VAL_11:.*]] {uniq_name = ".tmp.func_result"}
   print *, return_dyn_char_pointer(l)
   ! CHECK-NOT: fir.freemem
 end subroutine
@@ -316,13 +285,14 @@ function result_depends_on_equiv_sym()
   end function
 end module
 
-! CHECK-LABEL: func @_QPtest_result_depends_on_equiv_sym
+! CHECK-LABEL: func.func @_QPtest_result_depends_on_equiv_sym
 subroutine test_result_depends_on_equiv_sym()
   use m_with_equiv, only : result_depends_on_equiv_sym
   ! CHECK: %[[equiv:.*]] = fir.address_of(@_QMm_with_equivEarray) : !fir.ref<!fir.array<24xi8>>
   ! CHECK: %[[coor:.*]] = fir.coordinate_of %[[equiv]], %c{{.*}} : (!fir.ref<!fir.array<24xi8>>, index) -> !fir.ref<i8>
   ! CHECK: %[[l:.*]] = fir.convert %[[coor]] : (!fir.ref<i8>) -> !fir.ptr<i64>
-  ! CHECK: %[[load:.*]] = fir.load %[[l]] : !fir.ptr<i64>
+  ! CHECK: %[[l_decl:.*]]:2 = hlfir.declare %[[l]] storage(%[[equiv]][8]) {uniq_name = "_QMm_with_equivEl"}
+  ! CHECK: %[[load:.*]] = fir.load %[[l_decl]]#0 : !fir.ptr<i64>
   ! CHECK: %[[lcast:.*]] = fir.convert %[[load]] : (i64) -> index
   ! CHECK: %[[cmpi:.*]] = arith.cmpi sgt, %[[lcast]], %{{.*}} : index
   ! CHECK: %[[select:.*]] = arith.select %[[cmpi]], %[[lcast]], %{{.*}} : index
@@ -330,7 +300,7 @@ subroutine test_result_depends_on_equiv_sym()
   print *, result_depends_on_equiv_sym()
 end subroutine
 
-! CHECK-LABEL: func @_QPtest_depends_on_descriptor(
+! CHECK-LABEL: func.func @_QPtest_depends_on_descriptor(
 ! CHECK-SAME: %[[x:.*]]: !fir.box<!fir.array<?xf32>>{{.*}}) {
 subroutine test_depends_on_descriptor(x)
   interface
@@ -340,7 +310,7 @@ function depends_on_descriptor(x)
     end function
   end interface
   real :: x(:)
-  ! CHECK: %[[dims:.*]]:3 = fir.box_dims %arg0, %c0 : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
+  ! CHECK: %[[dims:.*]]:3 = fir.box_dims %{{.*}}, %c0 : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
   ! CHECK: %[[extentCast:.*]] = fir.convert %[[dims]]#1 : (index) -> i64
   ! CHECK: %[[extent:.*]] = fir.convert %[[extentCast]] : (i64) -> index
   ! CHECK: %[[cmpi:.*]] = arith.cmpi sgt, %[[extent]], %{{.*}} : index
@@ -349,7 +319,7 @@ function depends_on_descriptor(x)
   print *, depends_on_descriptor(x)
 end subroutine
 
-! CHECK-LABEL: func @_QPtest_symbol_indirection(
+! CHECK-LABEL: func.func @_QPtest_symbol_indirection(
 ! CHECK-SAME: %[[n:.*]]: !fir.ref<i64>{{.*}}) {
 subroutine test_symbol_indirection(n)
   interface
@@ -362,7 +332,7 @@ function symbol_indirection(c, n)
   integer(8) :: n
   character(n) :: c
   ! CHECK: BeginExternalListOutput
-  ! CHECK: %[[nload:.*]] = fir.load %[[n]] : !fir.ref<i64>
+  ! CHECK: %[[nload:.*]] = fir.load %{{.*}} : !fir.ref<i64>
   ! CHECK: %[[n_is_positive:.*]] = arith.cmpi sgt, %[[nload]], %c0{{.*}} : i64
   ! CHECK: %[[len:.*]] = arith.select %[[n_is_positive]], %[[nload]], %c0{{.*}} : i64
   ! CHECK: %[[len_cast:.*]] = fir.convert %[[len]] : (i64) -> index
@@ -372,7 +342,7 @@ function symbol_indirection(c, n)
   print *, symbol_indirection(c, n)
 end subroutine
 
-! CHECK-LABEL: func @_QPtest_recursion(
+! CHECK-LABEL: func.func @_QPtest_recursion(
 ! CHECK-SAME: %[[res:.*]]: !fir.ref<!fir.char<1,?>>{{.*}}, %[[resLen:.*]]: index{{.*}}, %[[n:.*]]: !fir.ref<i64>{{.*}}) -> !fir.boxchar<1> {
 function test_recursion(n) result(res)
   integer(8) :: n
@@ -393,13 +363,13 @@ function test_recursion(n) result(res)
     ! verify that the actual argument for symbol n ("n-1") is used to allocate
     ! the result, and not the local value of symbol n.
 
-    ! CHECK: %[[nLoad:.*]] = fir.load %[[n]] : !fir.ref<i64>
+    ! CHECK: %[[nLoad:.*]] = fir.load %[[n_decl:.*]]#0 : !fir.ref<i64>
     ! CHECK: %[[sub:.*]] = arith.subi %[[nLoad]], %c1{{.*}} : i64
-    ! CHECK: fir.store %[[sub]] to %[[nInCall:.*]] : !fir.ref<i64>
+    ! CHECK: %[[nInCall_assoc:.*]]:3 = hlfir.associate %[[sub]] {adapt.valuebyref}
 
     ! CHECK-NOT: fir.alloca !fir.array<?xi32>
 
-    ! CHECK: %[[nInCallLoad:.*]] = fir.load %[[nInCall]] : !fir.ref<i64>
+    ! CHECK: %[[nInCallLoad:.*]] = fir.load %[[nInCall_decl:.*]]#0 : !fir.ref<i64>
     ! CHECK: %[[nInCallCast:.*]] = fir.convert %[[nInCallLoad]] : (i64) -> index
     ! CHECK: %[[cmpi:.*]] = arith.cmpi sgt, %[[nInCallCast]], %{{.*}} : index
     ! CHECK: %[[select:.*]] = arith.select %[[cmpi]], %[[nInCallCast]], %{{.*}} : index
@@ -412,20 +382,20 @@ function test_recursion(n) result(res)
     ! Verify that symbol n was not remapped to the actual argument passed
     ! to n in the call (that the temporary mapping was cleaned-up).
 
-    ! CHECK: %[[nLoad2:.*]] = fir.load %[[n]] : !fir.ref<i64>
+    ! CHECK: %[[nLoad2:.*]] = fir.load %[[n_decl]]#0 : !fir.ref<i64>
     ! CHECK: OutputInteger64(%{{.*}}, %[[nLoad2]])
     print *, n
   end if
 end function
 
 ! Test call to character function for which only the result type is explicit
-! CHECK-LABEL:func @_QPtest_not_entirely_explicit_interface(
+! CHECK-LABEL:func.func @_QPtest_not_entirely_explicit_interface(
 ! CHECK-SAME: %[[n_arg:.*]]: !fir.ref<i64>{{.*}}) {
 subroutine test_not_entirely_explicit_interface(n)
   integer(8) :: n
   character(n) :: return_dyn_char_2
   print *, return_dyn_char_2(10)
-  ! CHECK: %[[n:.*]] = fir.load %[[n_arg]] : !fir.ref<i64>
+  ! CHECK: %[[n:.*]] = fir.load %[[n_decl:.*]]#0 : !fir.ref<i64>
   ! CHECK: %[[len:.*]] = fir.convert %[[n]] : (i64) -> index
   ! CHECK: %[[cmpi:.*]] = arith.cmpi sgt, %[[len]], %{{.*}} : index
   ! CHECK: %[[select:.*]] = arith.select %[[cmpi]], %[[len]], %{{.*}} : index
diff --git a/flang/test/Lower/ext-proc-as-actual-argument-1.f90 b/flang/test/Lower/ext-proc-as-actual-argument-1.f90
index 6ef8e00610086..50da368ab967f 100644
--- a/flang/test/Lower/ext-proc-as-actual-argument-1.f90
+++ b/flang/test/Lower/ext-proc-as-actual-argument-1.f90
@@ -1,19 +1,29 @@
-! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s
 
 ! Test external procedure as actual argument with the implicit character type.
 
-! CHECK-LABEL: func @_QQmain
-! CHECK:  %[[VAL_0:.*]] = fir.address_of(@_QPext_func) : (!fir.ref<!fir.char<1,?>>, index) -> !fir.boxchar<1>
-! CHECK:  %[[VAL_1:.*]] = fir.emboxproc %[[VAL_0]] : ((!fir.ref<!fir.char<1,?>>, index) -> !fir.boxchar<1>) -> !fir.boxproc<() -> ()>
-! CHECK:  %[[VAL_2:.*]] = fir.undefined i64
-! CHECK:  %[[VAL_3:.*]] = fir.undefined tuple<!fir.boxproc<() -> ()>, i64>
-! CHECK:  %[[VAL_4:.*]] = fir.insert_value %[[VAL_3]], %[[VAL_1]], [0 : index] : (tuple<!fir.boxproc<() -> ()>, i64>, !fir.boxproc<() -> ()>) -> tuple<!fir.boxproc<() -> ()>, i64>
-! CHECK:  %[[VAL_5:.*]] = fir.insert_value %[[VAL_4]], %[[VAL_2]], [1 : index] : (tuple<!fir.boxproc<() -> ()>, i64>, i64) -> tuple<!fir.boxproc<() -> ()>, i64>
-! CHECK:  fir.call @_QFPsub(%[[VAL_5]]) {{.*}}: (tuple<!fir.boxproc<() -> ()>, i64>) -> ()
-! CHECK:  return
+! CHECK-LABEL: func.func @_QQmain()
+! CHECK:  %[[VAL_1:.*]] = fir.address_of(@_QPext_func) : (!fir.ref<!fir.char<1,?>>, index) -> !fir.boxchar<1>
+! CHECK:  %[[VAL_2:.*]] = fir.emboxproc %[[VAL_1]] : ((!fir.ref<!fir.char<1,?>>, index) -> !fir.boxchar<1>) -> !fir.boxproc<() -> ()>
+! CHECK:  %[[VAL_5:.*]] = fir.undefined tuple<!fir.boxproc<() -> ()>, i64>
+! CHECK:  %[[VAL_6:.*]] = fir.insert_value %[[VAL_5]], %[[VAL_2]], [0 : index] : (tuple<!fir.boxproc<() -> ()>, i64>, !fir.boxproc<() -> ()>) -> tuple<!fir.boxproc<() -> ()>, i64>
+! CHECK:  %[[VAL_7:.*]] = fir.insert_value %[[VAL_6]], %{{.*}}, [1 : index] : (tuple<!fir.boxproc<() -> ()>, i64>, i64) -> tuple<!fir.boxproc<() -> ()>, i64>
+! CHECK:  fir.call @_QFPsub(%[[VAL_7]]) {{.*}}: (tuple<!fir.boxproc<() -> ()>, i64>) -> ()
 
-! CHECK-LABEL: func @_QPext_func(
-! CHECK: %[[ARG_0:.*]]: !fir.ref<!fir.char<1,?>>, %[[ARG_1:.*]]: index) -> !fir.boxchar<1> {
+! CHECK-LABEL: func.func private @_QFPsub(
+! CHECK-SAME: %[[VAL_0:.*]]: tuple<!fir.boxproc<() -> ()>, i64> {fir.char_proc}
+! CHECK: %[[VAL_5:.*]] = fir.extract_value %[[VAL_0]], [0 : index] : (tuple<!fir.boxproc<() -> ()>, i64>) -> !fir.boxproc<() -> ()>
+! CHECK: %[[VAL_6:.*]] = fir.box_addr %[[VAL_5]] : (!fir.boxproc<() -> ()>) -> (() -> ())
+! CHECK: %[[VAL_7:.*]] = fir.emboxproc %[[VAL_6]] : (() -> ()) -> !fir.boxproc<() -> ()>
+! CHECK: %[[VAL_8:.*]] = fir.undefined tuple<!fir.boxproc<() -> ()>, i64>
+! CHECK: %[[VAL_9:.*]] = fir.insert_value %[[VAL_8]], %[[VAL_7]], [0 : index] : (tuple<!fir.boxproc<() -> ()>, i64>, !fir.boxproc<() -> ()>) -> tuple<!fir.boxproc<() -> ()>, i64>
+! CHECK: %[[VAL_10:.*]] = fir.insert_value %[[VAL_9]], %{{.*}}, [1 : index] : (tuple<!fir.boxproc<() -> ()>, i64>, i64) -> tuple<!fir.boxproc<() -> ()>, i64>
+! CHECK: %[[VAL_11:.*]] = fir.extract_value %[[VAL_10]], [0 : index] : (tuple<!fir.boxproc<() -> ()>, i64>) -> !fir.boxproc<() -> ()>
+! CHECK: %[[VAL_16:.*]] = fir.box_addr %[[VAL_11]] : (!fir.boxproc<() -> ()>) -> ((!fir.ref<!fir.char<1,20>>, index) -> !fir.boxchar<1>)
+! CHECK: %[[VAL_18:.*]] = fir.call %[[VAL_16]](%{{.*}}, %{{.*}}) {{.*}}: (!fir.ref<!fir.char<1,20>>, index) -> !fir.boxchar<1>
+
+! CHECK-LABEL: func.func @_QPext_func(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.char<1,?>>{{.*}}, %[[VAL_1:.*]]: index{{.*}}) -> !fir.boxchar<1>
 program m
   external :: ext_func
   call sub(ext_func)
diff --git a/flang/test/Lower/ext-proc-as-actual-argument-2.f90 b/flang/test/Lower/ext-proc-as-actual-argument-2.f90
index d0544271e0628..4f469791b592b 100644
--- a/flang/test/Lower/ext-proc-as-actual-argument-2.f90
+++ b/flang/test/Lower/ext-proc-as-actual-argument-2.f90
@@ -1,19 +1,27 @@
-! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s
 
 ! Test external procedure as actual argument with the implicit character type.
 
-! CHECK-LABEL: func @_QQmain
-! CHECK:  %[[VAL_0:.*]] = fir.address_of(@_QPext_func) : (!fir.ref<!fir.char<1,20>>, index) -> !fir.boxchar<1>
-! CHECK:  %[[VAL_1:.*]] = fir.emboxproc %[[VAL_0]] : ((!fir.ref<!fir.char<1,20>>, index) -> !fir.boxchar<1>) -> !fir.boxproc<() -> ()>
-! CHECK:  %[[VAL_2:.*]] = fir.undefined i64
-! CHECK:  %[[VAL_3:.*]] = fir.undefined tuple<!fir.boxproc<() -> ()>, i64>
-! CHECK:  %[[VAL_4:.*]] = fir.insert_value %[[VAL_3]], %[[VAL_1]], [0 : index] : (tuple<!fir.boxproc<() -> ()>, i64>, !fir.boxproc<() -> ()>) -> tuple<!fir.boxproc<() -> ()>, i64>
-! CHECK:  %[[VAL_5:.*]] = fir.insert_value %[[VAL_4]], %[[VAL_2]], [1 : index] : (tuple<!fir.boxproc<() -> ()>, i64>, i64) -> tuple<!fir.boxproc<() -> ()>, i64>
-! CHECK:  fir.call @_QFPsub(%[[VAL_5]]) {{.*}}: (tuple<!fir.boxproc<() -> ()>, i64>) -> ()
-! CHECK:  return
+! CHECK-LABEL: func.func @_QQmain()
+! CHECK:  %[[VAL_1:.*]] = fir.address_of(@_QPext_func) : (!fir.ref<!fir.char<1,20>>, index) -> !fir.boxchar<1>
+! CHECK:  %[[VAL_2:.*]] = fir.emboxproc %[[VAL_1]] : ((!fir.ref<!fir.char<1,20>>, index) -> !fir.boxchar<1>) -> !fir.boxproc<() -> ()>
+! CHECK:  %[[VAL_5:.*]] = fir.undefined tuple<!fir.boxproc<() -> ()>, i64>
+! CHECK:  %[[VAL_6:.*]] = fir.insert_value %[[VAL_5]], %[[VAL_2]], [0 : index] : (tuple<!fir.boxproc<() -> ()>, i64>, !fir.boxproc<() -> ()>) -> tuple<!fir.boxproc<() -> ()>, i64>
+! CHECK:  %[[VAL_7:.*]] = fir.insert_value %[[VAL_6]], %{{.*}}, [1 : index] : (tuple<!fir.boxproc<() -> ()>, i64>, i64) -> tuple<!fir.boxproc<() -> ()>, i64>
+! CHECK:  fir.call @_QFPsub(%[[VAL_7]]) {{.*}}: (tuple<!fir.boxproc<() -> ()>, i64>) -> ()
+
+! CHECK-LABEL: func.func private @_QFPsub(
+! CHECK-SAME: %[[VAL_0:.*]]: tuple<!fir.boxproc<() -> ()>, i64> {fir.char_proc}
+! CHECK: %[[VAL_5:.*]] = fir.extract_value %[[VAL_0]], [0 : index] : (tuple<!fir.boxproc<() -> ()>, i64>) -> !fir.boxproc<() -> ()>
+! CHECK: %[[VAL_6:.*]] = fir.box_addr %[[VAL_5]] : (!fir.boxproc<() -> ()>) -> (() -> ())
+! CHECK: %[[VAL_7:.*]] = fir.emboxproc %[[VAL_6]] : (() -> ()) -> !fir.boxproc<() -> ()>
+! CHECK: %[[VAL_11:.*]] = fir.extract_value %{{.*}}, [0 : index] : (tuple<!fir.boxproc<() -> ()>, i64>) -> !fir.boxproc<() -> ()>
+! CHECK: %[[VAL_16:.*]] = fir.box_addr %[[VAL_11]] : (!fir.boxproc<() -> ()>) -> ((!fir.ref<!fir.char<1,20>>, index) -> !fir.boxchar<1>)
+! CHECK: %[[VAL_18:.*]] = fir.call %[[VAL_16]](%{{.*}}, %{{.*}}) {{.*}}: (!fir.ref<!fir.char<1,20>>, index) -> !fir.boxchar<1>
+
+! CHECK-LABEL: func.func @_QPext_func(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.char<1,20>>{{.*}}, %[[VAL_1:.*]]: index{{.*}}) -> !fir.boxchar<1>
 
-! CHECK-LABEL: func @_QPext_func(
-! CHECK: %[[ARG_0:.*]]: !fir.ref<!fir.char<1,20>>, %[[ARG_1:.*]]: index) -> !fir.boxchar<1> {
 program m
   external :: ext_func
   call sub(ext_func)

>From 8671e27d51650022ee69202ab39f38dc8cb14719 Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Sun, 8 Feb 2026 23:20:20 -0500
Subject: [PATCH 2/3] Fix Lower/explicit-interface-results.f90

---
 .../test/Lower/explicit-interface-results.f90 | 24 ++++---------------
 1 file changed, 4 insertions(+), 20 deletions(-)

diff --git a/flang/test/Lower/explicit-interface-results.f90 b/flang/test/Lower/explicit-interface-results.f90
index acfbf046e840b..c9af7c225dc08 100644
--- a/flang/test/Lower/explicit-interface-results.f90
+++ b/flang/test/Lower/explicit-interface-results.f90
@@ -122,11 +122,7 @@ subroutine alloc()
   ! CHECK: fir.save_result %[[VAL_6]] to %[[VAL_5]]#0 : !fir.box<!fir.heap<!fir.array<?xf32>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
   print *, return_alloc()
   ! CHECK: _FortranAioOutputDescriptor
-  ! CHECK: %[[load:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
-  ! CHECK: %[[addr:.*]] = fir.box_addr %[[load]] : (!fir.box<!fir.heap<!fir.array<?xf32>>>) -> !fir.heap<!fir.array<?xf32>>
-  ! CHECK: %[[cmpi:.*]] = arith.cmpi
-  ! CHECK: fir.if %[[cmpi]]
-  ! CHECK: fir.freemem %[[addr]] : !fir.heap<!fir.array<?xf32>>
+  ! CHECK: hlfir.destroy %{{.*}} : !hlfir.expr<?xf32>
 end subroutine
 
 ! CHECK-LABEL: func.func @_QMcallerPcst_char_alloc()
@@ -137,11 +133,7 @@ subroutine cst_char_alloc()
   ! CHECK: fir.save_result %[[VAL_10]] to %[[VAL_9]]#0 : !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>>
   print *, return_cst_char_alloc()
   ! CHECK: _FortranAioOutputDescriptor
-  ! CHECK: %[[load:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>>
-  ! CHECK: %[[addr:.*]] = fir.box_addr %[[load]] : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>) -> !fir.heap<!fir.array<?x!fir.char<1,10>>>
-  ! CHECK: %[[cmpi:.*]] = arith.cmpi
-  ! CHECK: fir.if %[[cmpi]]
-  ! CHECK: fir.freemem %[[addr]] : !fir.heap<!fir.array<?x!fir.char<1,10>>>
+  ! CHECK: hlfir.destroy %{{.*}} : !hlfir.expr<?x!fir.char<1,10>>
 end subroutine
 
 ! CHECK-LABEL: func.func @_QMcallerPdef_char_alloc()
@@ -152,11 +144,7 @@ subroutine def_char_alloc()
   ! CHECK: fir.save_result %[[VAL_6]] to %[[VAL_5]]#0 : !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
   print *, return_def_char_alloc()
   ! CHECK: _FortranAioOutputDescriptor
-  ! CHECK: %[[load:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
-  ! CHECK: %[[addr:.*]] = fir.box_addr %[[load]] : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>) -> !fir.heap<!fir.array<?x!fir.char<1,?>>>
-  ! CHECK: %[[cmpi:.*]] = arith.cmpi
-  ! CHECK: fir.if %[[cmpi]]
-  ! CHECK: fir.freemem %[[addr]] : !fir.heap<!fir.array<?x!fir.char<1,?>>>
+  ! CHECK: hlfir.destroy %{{.*}} : !hlfir.expr<?x!fir.char<1,?>>
 end subroutine
 
 ! CHECK-LABEL: func.func @_QMcallerPpointer_test()
@@ -251,11 +239,7 @@ subroutine dyn_char_alloc(l)
   ! CHECK: fir.save_result %[[VAL_14]] to %[[VAL_13]]#0 : !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
   print *, return_dyn_char_alloc(l)
   ! CHECK: _FortranAioOutputDescriptor
-  ! CHECK: %[[load:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
-  ! CHECK: %[[addr:.*]] = fir.box_addr %[[load]] : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>) -> !fir.heap<!fir.array<?x!fir.char<1,?>>>
-  ! CHECK: %[[cmpi:.*]] = arith.cmpi
-  ! CHECK: fir.if %[[cmpi]]
-  ! CHECK: fir.freemem %[[addr]] : !fir.heap<!fir.array<?x!fir.char<1,?>>>
+  ! CHECK: hlfir.destroy %{{.*}} : !hlfir.expr<?x!fir.char<1,?>>
 end subroutine
 
 ! CHECK-LABEL: func.func @_QMcallerPdyn_char_pointer

>From dd5739d051309dc58daaedc4083fcab205c49a07 Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Sun, 8 Feb 2026 23:24:33 -0500
Subject: [PATCH 3/3] Improved the checks in
 Lower/explicit-interface-results.f90

---
 .../test/Lower/explicit-interface-results.f90 | 56 +++++++++++++++----
 1 file changed, 45 insertions(+), 11 deletions(-)

diff --git a/flang/test/Lower/explicit-interface-results.f90 b/flang/test/Lower/explicit-interface-results.f90
index c9af7c225dc08..dff009d5496f2 100644
--- a/flang/test/Lower/explicit-interface-results.f90
+++ b/flang/test/Lower/explicit-interface-results.f90
@@ -121,8 +121,12 @@ subroutine alloc()
   ! CHECK: %[[VAL_6:.*]] = fir.call @_QMcalleePreturn_alloc() {{.*}}: () -> !fir.box<!fir.heap<!fir.array<?xf32>>>
   ! CHECK: fir.save_result %[[VAL_6]] to %[[VAL_5]]#0 : !fir.box<!fir.heap<!fir.array<?xf32>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
   print *, return_alloc()
+  ! CHECK: %[[load:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
+  ! CHECK: %[[as_expr:.*]] = hlfir.as_expr %[[load]] move %{{.*}} : (!fir.box<!fir.heap<!fir.array<?xf32>>>, i1) -> !hlfir.expr<?xf32>
+  ! CHECK: %[[assoc:.*]]:3 = hlfir.associate %[[as_expr]]({{.*}}) {adapt.valuebyref} : (!hlfir.expr<?xf32>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>, i1)
   ! CHECK: _FortranAioOutputDescriptor
-  ! CHECK: hlfir.destroy %{{.*}} : !hlfir.expr<?xf32>
+  ! CHECK: hlfir.end_associate %[[assoc]]#1, %[[assoc]]#2 : !fir.ref<!fir.array<?xf32>>, i1
+  ! CHECK: hlfir.destroy %[[as_expr]] : !hlfir.expr<?xf32>
 end subroutine
 
 ! CHECK-LABEL: func.func @_QMcallerPcst_char_alloc()
@@ -132,8 +136,12 @@ subroutine cst_char_alloc()
   ! CHECK: %[[VAL_10:.*]] = fir.call @_QMcalleePreturn_cst_char_alloc() {{.*}}: () -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>
   ! CHECK: fir.save_result %[[VAL_10]] to %[[VAL_9]]#0 : !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>>
   print *, return_cst_char_alloc()
+  ! CHECK: %[[load:.*]] = fir.load %[[VAL_9]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>>
+  ! CHECK: %[[as_expr:.*]] = hlfir.as_expr %[[load]] move %{{.*}} : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>, i1) -> !hlfir.expr<?x!fir.char<1,10>>
+  ! CHECK: %[[assoc:.*]]:3 = hlfir.associate %[[as_expr]]({{.*}}) typeparams %{{.*}} {adapt.valuebyref} : (!hlfir.expr<?x!fir.char<1,10>>, !fir.shape<1>, index) -> (!fir.box<!fir.array<?x!fir.char<1,10>>>, !fir.ref<!fir.array<?x!fir.char<1,10>>>, i1)
   ! CHECK: _FortranAioOutputDescriptor
-  ! CHECK: hlfir.destroy %{{.*}} : !hlfir.expr<?x!fir.char<1,10>>
+  ! CHECK: hlfir.end_associate %[[assoc]]#1, %[[assoc]]#2 : !fir.ref<!fir.array<?x!fir.char<1,10>>>, i1
+  ! CHECK: hlfir.destroy %[[as_expr]] : !hlfir.expr<?x!fir.char<1,10>>
 end subroutine
 
 ! CHECK-LABEL: func.func @_QMcallerPdef_char_alloc()
@@ -143,8 +151,12 @@ subroutine def_char_alloc()
   ! CHECK: %[[VAL_6:.*]] = fir.call @_QMcalleePreturn_def_char_alloc() {{.*}}: () -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>
   ! CHECK: fir.save_result %[[VAL_6]] to %[[VAL_5]]#0 : !fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
   print *, return_def_char_alloc()
+  ! CHECK: %[[load:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>>
+  ! CHECK: %[[as_expr:.*]] = hlfir.as_expr %[[load]] move %{{.*}} : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>, i1) -> !hlfir.expr<?x!fir.char<1,?>>
+  ! CHECK: %[[assoc:.*]]:3 = hlfir.associate %[[as_expr]]({{.*}}) typeparams %{{.*}} {adapt.valuebyref} : (!hlfir.expr<?x!fir.char<1,?>>, !fir.shape<1>, index) -> (!fir.box<!fir.array<?x!fir.char<1,?>>>, !fir.ref<!fir.array<?x!fir.char<1,?>>>, i1)
   ! CHECK: _FortranAioOutputDescriptor
-  ! CHECK: hlfir.destroy %{{.*}} : !hlfir.expr<?x!fir.char<1,?>>
+  ! CHECK: hlfir.end_associate %[[assoc]]#1, %[[assoc]]#2 : !fir.ref<!fir.array<?x!fir.char<1,?>>>, i1
+  ! CHECK: hlfir.destroy %[[as_expr]] : !hlfir.expr<?x!fir.char<1,?>>
 end subroutine
 
 ! CHECK-LABEL: func.func @_QMcallerPpointer_test()
@@ -153,6 +165,8 @@ subroutine pointer_test()
   ! CHECK: %[[VAL_5:.*]] = fir.call @_QMcalleePreturn_pointer() {{.*}}: () -> !fir.box<!fir.ptr<!fir.array<?xf32>>>
   ! CHECK: fir.save_result %[[VAL_5]] to %[[VAL_0]] : !fir.box<!fir.ptr<!fir.array<?xf32>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
   print *, return_pointer()
+  ! CHECK: %[[load:.*]] = fir.load %{{.*}} : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
+  ! CHECK: _FortranAioOutputDescriptor
   ! CHECK-NOT: fir.freemem
 end subroutine
 
@@ -162,6 +176,8 @@ subroutine cst_char_pointer()
   ! CHECK: %[[VAL_9:.*]] = fir.call @_QMcalleePreturn_cst_char_pointer() {{.*}}: () -> !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,10>>>>
   ! CHECK: fir.save_result %[[VAL_9]] to %[[VAL_0]] : !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,10>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,10>>>>>
   print *, return_cst_char_pointer()
+  ! CHECK: %[[load:.*]] = fir.load %{{.*}} : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,10>>>>>
+  ! CHECK: _FortranAioOutputDescriptor
   ! CHECK-NOT: fir.freemem
 end subroutine
 
@@ -171,6 +187,8 @@ subroutine def_char_pointer()
   ! CHECK: %[[VAL_5:.*]] = fir.call @_QMcalleePreturn_def_char_pointer() {{.*}}: () -> !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>
   ! CHECK: fir.save_result %[[VAL_5]] to %[[VAL_0]] : !fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>>
   print *, return_def_char_pointer()
+  ! CHECK: %[[load:.*]] = fir.load %{{.*}} : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,?>>>>>
+  ! CHECK: _FortranAioOutputDescriptor
   ! CHECK-NOT: fir.freemem
 end subroutine
 
@@ -184,8 +202,11 @@ subroutine dyn_array(m, n)
   ! CHECK:   %[[RES:.*]] = fir.call @_QMcalleePreturn_dyn_array(%{{.*}}, %{{.*}}) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>) -> !fir.array<?x?xf32>
   ! CHECK:   fir.save_result %[[RES]] to %[[ARG]](%[[VAL_22]]) : !fir.array<?x?xf32>, !fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>
   ! CHECK: }
-  ! CHECK: %[[VAL_24:.*]]:3 = hlfir.associate %[[VAL_23]](%[[VAL_22]])
+  ! CHECK: %[[VAL_24:.*]]:3 = hlfir.associate %[[VAL_23]](%[[VAL_22]]) {adapt.valuebyref}
   print *, return_dyn_array(m, n)
+  ! CHECK: _FortranAioOutputDescriptor
+  ! CHECK: hlfir.end_associate %[[VAL_24]]#1, %[[VAL_24]]#2 : !fir.ref<!fir.array<?x?xf32>>, i1
+  ! CHECK: hlfir.destroy %[[VAL_23]] : !hlfir.expr<?x?xf32>
 end subroutine
 
 ! CHECK-LABEL: func.func @_QMcallerPdyn_char_cst_array(
@@ -198,8 +219,11 @@ subroutine dyn_char_cst_array(l)
   ! CHECK:   %[[RES:.*]] = fir.call @_QMcalleePreturn_dyn_char_cst_array(%{{.*}}) {{.*}}: (!fir.ref<i32>) -> !fir.array<20x30x!fir.char<1,?>>
   ! CHECK:   fir.save_result %[[RES]] to %[[ARG]](%[[VAL_21]]) typeparams %[[VAL_20]] : !fir.array<20x30x!fir.char<1,?>>, !fir.ref<!fir.array<20x30x!fir.char<1,?>>>, !fir.shape<2>, index
   ! CHECK: }
-  ! CHECK: %[[VAL_23:.*]]:3 = hlfir.associate %[[VAL_22]](%[[VAL_21]]) typeparams %[[VAL_20]]
+  ! CHECK: %[[VAL_23:.*]]:3 = hlfir.associate %[[VAL_22]](%[[VAL_21]]) typeparams %[[VAL_20]] {adapt.valuebyref}
   print *, return_dyn_char_cst_array(l)
+  ! CHECK: _FortranAioOutputDescriptor
+  ! CHECK: hlfir.end_associate %[[VAL_23]]#1, %[[VAL_23]]#2 : !fir.ref<!fir.array<20x30x!fir.char<1,?>>>, i1
+  ! CHECK: hlfir.destroy %[[VAL_22]] : !hlfir.expr<20x30x!fir.char<1,?>>
 end subroutine
 
 ! CHECK-LABEL: func.func @_QMcallerPcst_char_dyn_array(
@@ -212,8 +236,11 @@ subroutine cst_char_dyn_array(m, n)
   ! CHECK:   %[[RES:.*]] = fir.call @_QMcalleePreturn_cst_char_dyn_array(%{{.*}}, %{{.*}}) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>) -> !fir.array<?x?x!fir.char<1,10>>
   ! CHECK:   fir.save_result %[[RES]] to %[[ARG]](%[[VAL_25]]) typeparams %[[VAL_24]] : !fir.array<?x?x!fir.char<1,10>>, !fir.ref<!fir.array<?x?x!fir.char<1,10>>>, !fir.shape<2>, index
   ! CHECK: }
-  ! CHECK: %[[VAL_27:.*]]:3 = hlfir.associate %[[VAL_26]](%[[VAL_25]]) typeparams %[[VAL_24]]
+  ! CHECK: %[[VAL_27:.*]]:3 = hlfir.associate %[[VAL_26]](%[[VAL_25]]) typeparams %[[VAL_24]] {adapt.valuebyref}
   print *, return_cst_char_dyn_array(m, n)
+  ! CHECK: _FortranAioOutputDescriptor
+  ! CHECK: hlfir.end_associate %[[VAL_27]]#1, %[[VAL_27]]#2 : !fir.ref<!fir.array<?x?x!fir.char<1,10>>>, i1
+  ! CHECK: hlfir.destroy %[[VAL_26]] : !hlfir.expr<?x?x!fir.char<1,10>>
 end subroutine
 
 ! CHECK-LABEL: func.func @_QMcallerPdyn_char_dyn_array(
@@ -225,9 +252,12 @@ subroutine dyn_char_dyn_array(l, m, n)
   ! CHECK:   %[[RES:.*]] = fir.call @_QMcalleePreturn_dyn_char_dyn_array(%{{.*}}, %{{.*}}, %{{.*}}) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>, !fir.ref<i32>) -> !fir.array<?x?x!fir.char<1,?>>
   ! CHECK:   fir.save_result %[[RES]] to %[[ARG]](%[[VAL_29]]) typeparams %[[VAL_28]] : !fir.array<?x?x!fir.char<1,?>>, !fir.ref<!fir.array<?x?x!fir.char<1,?>>>, !fir.shape<2>, index
   ! CHECK: }
-  ! CHECK: %[[VAL_31:.*]]:3 = hlfir.associate %[[VAL_30]](%[[VAL_29]]) typeparams %[[VAL_28]]
+  ! CHECK: %[[VAL_31:.*]]:3 = hlfir.associate %[[VAL_30]](%[[VAL_29]]) typeparams %[[VAL_28]] {adapt.valuebyref}
   integer :: l, m, n
   print *, return_dyn_char_dyn_array(l, m, n)
+  ! CHECK: _FortranAioOutputDescriptor
+  ! CHECK: hlfir.end_associate %[[VAL_31]]#1, %[[VAL_31]]#2 : !fir.ref<!fir.array<?x?x!fir.char<1,?>>>, i1
+  ! CHECK: hlfir.destroy %[[VAL_30]] : !hlfir.expr<?x?x!fir.char<1,?>>
 end subroutine
 
 ! CHECK-LABEL: func.func @_QMcallerPdyn_char_alloc
@@ -349,19 +379,21 @@ function test_recursion(n) result(res)
 
     ! CHECK: %[[nLoad:.*]] = fir.load %[[n_decl:.*]]#0 : !fir.ref<i64>
     ! CHECK: %[[sub:.*]] = arith.subi %[[nLoad]], %c1{{.*}} : i64
-    ! CHECK: %[[nInCall_assoc:.*]]:3 = hlfir.associate %[[sub]] {adapt.valuebyref}
+    ! CHECK: %[[nInCall_assoc:.*]]:3 = hlfir.associate %[[sub]] {adapt.valuebyref} : (i64) -> (!fir.ref<i64>, !fir.ref<i64>, i1)
+    ! CHECK: %[[nInCall_decl:.*]]:2 = hlfir.declare %[[nInCall_assoc]]#0 {uniq_name = "_QFtest_recursionEn"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
 
     ! CHECK-NOT: fir.alloca !fir.array<?xi32>
 
-    ! CHECK: %[[nInCallLoad:.*]] = fir.load %[[nInCall_decl:.*]]#0 : !fir.ref<i64>
+    ! CHECK: %[[nInCallLoad:.*]] = fir.load %[[nInCall_decl]]#0 : !fir.ref<i64>
     ! CHECK: %[[nInCallCast:.*]] = fir.convert %[[nInCallLoad]] : (i64) -> index
     ! CHECK: %[[cmpi:.*]] = arith.cmpi sgt, %[[nInCallCast]], %{{.*}} : index
     ! CHECK: %[[select:.*]] = arith.select %[[cmpi]], %[[nInCallCast]], %{{.*}} : index
     ! CHECK: %[[tmp:.*]] = fir.alloca !fir.char<1,?>(%[[select]] : index)
 
     ! CHECK-NOT: fir.alloca !fir.array<?xi32>
-    ! CHECK: fir.call @_QPtest_recursion(%[[tmp]], {{.*}}
+    ! CHECK: fir.call @_QPtest_recursion(%[[tmp]], %[[select]], %[[nInCall_assoc]]#0) {{.*}}
     res = char(some_local(1)) // test_recursion(n-1)
+    ! CHECK: hlfir.end_associate %[[nInCall_assoc]]#1, %[[nInCall_assoc]]#2 : !fir.ref<i64>, i1
 
     ! Verify that symbol n was not remapped to the actual argument passed
     ! to n in the call (that the temporary mapping was cleaned-up).
@@ -379,10 +411,12 @@ subroutine test_not_entirely_explicit_interface(n)
   integer(8) :: n
   character(n) :: return_dyn_char_2
   print *, return_dyn_char_2(10)
+  ! CHECK: %[[assoc:.*]]:3 = hlfir.associate %c10_i32 {adapt.valuebyref}
   ! CHECK: %[[n:.*]] = fir.load %[[n_decl:.*]]#0 : !fir.ref<i64>
   ! CHECK: %[[len:.*]] = fir.convert %[[n]] : (i64) -> index
   ! CHECK: %[[cmpi:.*]] = arith.cmpi sgt, %[[len]], %{{.*}} : index
   ! CHECK: %[[select:.*]] = arith.select %[[cmpi]], %[[len]], %{{.*}} : index
   ! CHECK: %[[result:.*]] = fir.alloca !fir.char<1,?>(%[[select]] : index) {bindc_name = ".result"}
-  ! CHECK: fir.call @_QPreturn_dyn_char_2(%[[result]], %[[select]], %{{.*}}) {{.*}}: (!fir.ref<!fir.char<1,?>>, index, !fir.ref<i32>) -> !fir.boxchar<1>
+  ! CHECK: fir.call @_QPreturn_dyn_char_2(%[[result]], %[[select]], %[[assoc]]#0) {{.*}}: (!fir.ref<!fir.char<1,?>>, index, !fir.ref<i32>) -> !fir.boxchar<1>
+  ! CHECK: hlfir.end_associate %[[assoc]]#1, %[[assoc]]#2 : !fir.ref<i32>, i1
 end subroutine



More information about the flang-commits mailing list