! Test lowering of allocate, deallocate and pointer assignment statements to ! HLFIR. ! RUN: bbc -emit-hlfir -o - %s -I nw | FileCheck %s subroutine allocation(x) character(*), allocatable :: x(:) ! CHECK-LABEL: func.func @_QPallocation( ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] typeparams %[[VAL_2:[a-z0-9]*]] dummy_scope %{{[0-9]+}} arg {{[0-9]+}} {fortran_attrs = #fir.var_attrs, {{.*}}Ex deallocate(x) ! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref>>>> ! CHECK: %[[VAL_5:.*]] = fir.box_addr %[[VAL_4]] : (!fir.box>>>) -> !fir.heap>> ! CHECK: fir.freemem %[[VAL_5]] : !fir.heap>> ! CHECK: %[[VAL_6:.*]] = fir.zero_bits !fir.heap>> ! CHECK: %[[VAL_7:.*]] = arith.constant 0 : index ! CHECK: %[[VAL_8:.*]] = fir.shape %[[VAL_7]] : (index) -> !fir.shape<1> ! CHECK: %[[VAL_9:.*]] = fir.embox %[[VAL_6]](%[[VAL_8]]) typeparams %[[VAL_2]] : (!fir.heap>>, !fir.shape<1>, index) -> !fir.box>>> allocate(x(100)) ! CHECK: %[[VAL_10:.*]] = arith.constant 100 : i32 ! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (i32) -> index ! CHECK: %[[VAL_12:.*]] = arith.constant 0 : index ! CHECK: %[[VAL_13:.*]] = arith.cmpi sgt, %[[VAL_11]], %[[VAL_12]] : index ! CHECK: %[[VAL_14:.*]] = arith.select %[[VAL_13]], %[[VAL_11]], %[[VAL_12]] : index ! CHECK: %[[VAL_15:.*]] = fir.allocmem !fir.array>(%[[VAL_2]] : index), %[[VAL_14]] {fir.must_be_heap = true, uniq_name = "_QFallocationEx.alloc"} ! CHECK: %[[VAL_16:.*]] = fir.shape %[[VAL_14]] : (index) -> !fir.shape<1> ! CHECK: %[[VAL_17:.*]] = fir.embox %[[VAL_15]](%[[VAL_16]]) typeparams %[[VAL_2]] : (!fir.heap>>, !fir.shape<1>, index) -> !fir.box>>> ! CHECK: fir.store %[[VAL_17]] to %[[VAL_3]]#0 : !fir.ref>>>> end subroutine subroutine pointer_assignment(p, ziel) real, pointer :: p(:) real, target :: ziel(42:) ! CHECK-LABEL: func.func @_QPpointer_assignment( ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] dummy_scope %{{[0-9]+}} arg {{[0-9]+}} {fortran_attrs = #fir.var_attrs, {{.*}}Ep ! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_1:[a-z0-9]*]](%[[VAL_5:[a-z0-9]*]]) dummy_scope %{{[0-9]+}} arg {{[0-9]+}} {fortran_attrs = #fir.var_attrs, {{.*}}Eziel p => ziel ! CHECK: %[[VAL_7:.*]] = fir.shift %[[VAL_4:.*]] : (index) -> !fir.shift<1> ! CHECK: %[[VAL_8:.*]] = fir.rebox %[[VAL_6]]#0(%[[VAL_7]]) : (!fir.box>, !fir.shift<1>) -> !fir.box>> ! CHECK: fir.store %[[VAL_8]] to %[[VAL_2]]#0 : !fir.ref>>> p => ziel(42:77:3) ! CHECK: %[[VAL_14:.*]] = hlfir.designate %{{.*}}#0 (%{{.*}}:%{{.*}}:%{{.*}}) shape %{{.*}} : (!fir.box>, index, index, index, !fir.shape<1>) -> !fir.box> ! CHECK: %[[VAL_15:.*]] = fir.rebox %[[VAL_14]] : (!fir.box>) -> !fir.box>> ! CHECK: fir.store %[[VAL_15]] to %[[VAL_2]]#0 : !fir.ref>>> end subroutine subroutine pointer_remapping(p, ziel) real, pointer :: p(:, :) real, target :: ziel(10, 20, 30) ! CHECK-LABEL: func.func @_QPpointer_remapping( ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] dummy_scope %{{[0-9]+}} arg {{[0-9]+}} {fortran_attrs = #fir.var_attrs, {{.*}}Ep ! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_1:[a-z0-9]*]](%[[VAL_6:[a-z0-9]*]]) dummy_scope %{{[0-9]+}} arg {{[0-9]+}} {fortran_attrs = #fir.var_attrs, {{.*}}Eziel p(2:7, 3:102) => ziel ! CHECK: %[[CONVERT_0:.*]] = fir.convert %[[VAL_7]]#0 : (!fir.ref>) -> !fir.ref> ! CHECK: %[[EMBOX_0:.*]] = fir.embox %[[CONVERT_0]](%[[VAL_6]]) : (!fir.ref>, !fir.shape<3>) -> !fir.box>> ! CHECK: %[[CONSTANT_3:.*]] = arith.constant 0 : index ! CHECK: %[[CONSTANT_4:.*]] = arith.constant 1 : index ! CHECK: %[[CONSTANT_5:.*]] = arith.constant 2 : i64 ! CHECK: %[[CONVERT_1:.*]] = fir.convert %[[CONSTANT_5]] : (i64) -> index ! CHECK: %[[CONSTANT_6:.*]] = arith.constant 7 : i64 ! CHECK: %[[CONVERT_2:.*]] = fir.convert %[[CONSTANT_6]] : (i64) -> index ! CHECK: %[[SUBI_0:.*]] = arith.subi %[[CONVERT_2]], %[[CONVERT_1]] : index ! CHECK: %[[ADDI_0:.*]] = arith.addi %[[SUBI_0]], %[[CONSTANT_4]] : index ! CHECK: %[[CMPI_0:.*]] = arith.cmpi sgt, %[[ADDI_0]], %[[CONSTANT_3]] : index ! CHECK: %[[SELECT_0:.*]] = arith.select %[[CMPI_0]], %[[ADDI_0]], %[[CONSTANT_3]] : index ! CHECK: %[[CONSTANT_7:.*]] = arith.constant 3 : i64 ! CHECK: %[[CONVERT_3:.*]] = fir.convert %[[CONSTANT_7]] : (i64) -> index ! CHECK: %[[CONSTANT_8:.*]] = arith.constant 102 : i64 ! CHECK: %[[CONVERT_4:.*]] = fir.convert %[[CONSTANT_8]] : (i64) -> index ! CHECK: %[[SUBI_1:.*]] = arith.subi %[[CONVERT_4]], %[[CONVERT_3]] : index ! CHECK: %[[ADDI_1:.*]] = arith.addi %[[SUBI_1]], %[[CONSTANT_4]] : index ! CHECK: %[[CMPI_1:.*]] = arith.cmpi sgt, %[[ADDI_1]], %[[CONSTANT_3]] : index ! CHECK: %[[SELECT_1:.*]] = arith.select %[[CMPI_1]], %[[ADDI_1]], %[[CONSTANT_3]] : index ! CHECK: %[[SHAPE_SHIFT_0:.*]] = fir.shape_shift %[[CONVERT_1]], %[[SELECT_0]], %[[CONVERT_3]], %[[SELECT_1]] : (index, index, index, index) -> !fir.shapeshift<2> ! CHECK: %[[REBOX_0:.*]] = fir.rebox %[[EMBOX_0]](%[[SHAPE_SHIFT_0]]) : (!fir.box>>, !fir.shapeshift<2>) -> !fir.box>> ! CHECK: fir.store %[[REBOX_0]] to %[[VAL_2]]#0 : !fir.ref>>> end subroutine subroutine alloc_comp(x) type t real, allocatable :: a(:) end type type(t) :: x(10) ! CHECK-LABEL: func.func @_QPalloc_comp( ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]](%[[VAL_2:[a-z0-9]*]]) {{.*}}Ex allocate(x(10_8)%a(100_8)) ! CHECK: %[[VAL_4:.*]] = arith.constant 10 : index ! CHECK: %[[VAL_5:.*]] = hlfir.designate %[[VAL_3]]#0 (%[[VAL_4]]) : (!fir.ref>>}>>>, index) -> !fir.ref>>}>> ! CHECK: %[[VAL_6:.*]] = hlfir.designate %[[VAL_5]]{"a"} {fortran_attrs = #fir.var_attrs} : (!fir.ref>>}>>) -> !fir.ref>>> ! CHECK: %[[VAL_7:.*]] = arith.constant 100 : i64 ! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (i64) -> index ! CHECK: %[[VAL_9:.*]] = arith.constant 0 : index ! CHECK: %[[VAL_10:.*]] = arith.cmpi sgt, %[[VAL_8]], %[[VAL_9]] : index ! CHECK: %[[VAL_11:.*]] = arith.select %[[VAL_10]], %[[VAL_8]], %[[VAL_9]] : index ! CHECK: %[[VAL_12:.*]] = fir.allocmem !fir.array, %[[VAL_11]] {fir.must_be_heap = true, uniq_name = "_QFalloc_compEa.alloc"} ! CHECK: %[[VAL_13:.*]] = fir.shape %[[VAL_11]] : (index) -> !fir.shape<1> ! CHECK: %[[VAL_14:.*]] = fir.embox %[[VAL_12]](%[[VAL_13]]) : (!fir.heap>, !fir.shape<1>) -> !fir.box>> ! CHECK: fir.store %[[VAL_14]] to %[[VAL_6]] : !fir.ref>>> end subroutine subroutine ptr_comp_assign(x, ziel) type t real, pointer :: p(:) end type type(t) :: x(10) ! CHECK-LABEL: func.func @_QPptr_comp_assign( ! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]](%[[VAL_3:[a-z0-9]*]]) {{.*}}Ex real, target :: ziel(100) x(9_8)%p => ziel ! CHECK: %[[VAL_5:.*]] = arith.constant 100 : index ! CHECK: %[[VAL_6:.*]] = fir.shape %[[VAL_5]] : (index) -> !fir.shape<1> ! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_1:[a-z0-9]*]](%[[VAL_6:[a-z0-9]*]]) dummy_scope %{{[0-9]+}} arg {{[0-9]+}} {fortran_attrs = #fir.var_attrs, {{.*}}Eziel ! CHECK: %[[VAL_8:.*]] = arith.constant 9 : index ! CHECK: %[[VAL_9:.*]] = hlfir.designate %[[VAL_4]]#0 (%[[VAL_8]]) : (!fir.ref>>}>>>, index) -> !fir.ref>>}>> ! CHECK: %[[VAL_10:.*]] = hlfir.designate %[[VAL_9]]{"p"} {fortran_attrs = #fir.var_attrs} : (!fir.ref>>}>>) -> !fir.ref>>> ! CHECK: %[[CAST:.*]] = fir.convert %[[VAL_7]]#0 : (!fir.ref>) -> !fir.ref> ! CHECK: %[[VAL_12:.*]] = fir.embox %[[CAST]](%[[VAL_6]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box>> ! CHECK: fir.store %[[VAL_12]] to %[[VAL_10]] : !fir.ref>>> end subroutine