! Test lowering of pointer initial target ! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s ! ----------------------------------------------------------------------------- ! Test scalar initial data target that are simple names ! ----------------------------------------------------------------------------- subroutine scalar() real, save, target :: x real, pointer :: p => x ! CHECK-LABEL: fir.global internal @_QFscalarEp : !fir.box> ! CHECK: %[[xAddr:.*]] = fir.address_of(@_QFscalarEx) : !fir.ref ! CHECK: %[[x:.*]]:2 = hlfir.declare %[[xAddr]] {{.*}} : (!fir.ref) -> (!fir.ref, !fir.ref) ! CHECK: %[[box:.*]] = fir.embox %[[x]]#0 : (!fir.ref) -> !fir.box ! CHECK: %[[rebox:.*]] = fir.rebox %[[box]] : (!fir.box) -> !fir.box> ! CHECK: fir.has_value %[[rebox]] : !fir.box> end subroutine subroutine scalar_char() character(10), save, target :: x character(:), pointer :: p => x ! CHECK-LABEL: fir.global internal @_QFscalar_charEp : !fir.box>> ! CHECK: %[[xAddr:.*]] = fir.address_of(@_QFscalar_charEx) : !fir.ref> ! CHECK: %[[x:.*]]:2 = hlfir.declare %[[xAddr]] typeparams %{{.*}} {{.*}} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) ! CHECK: %[[box:.*]] = fir.embox %[[x]]#0 : (!fir.ref>) -> !fir.box> ! CHECK: %[[rebox:.*]] = fir.rebox %[[box]] : (!fir.box>) -> !fir.box>> ! CHECK: fir.has_value %[[rebox]] : !fir.box>> end subroutine subroutine scalar_char_2() character(10), save, target :: x character(10), pointer :: p => x ! CHECK-LABEL: fir.global internal @_QFscalar_char_2Ep : !fir.box>> ! CHECK: %[[xAddr:.*]] = fir.address_of(@_QFscalar_char_2Ex) : !fir.ref> ! CHECK: %[[x:.*]]:2 = hlfir.declare %[[xAddr]] typeparams %{{.*}} {{.*}} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) ! CHECK: %[[box:.*]] = fir.embox %[[x]]#0 : (!fir.ref>) -> !fir.box> ! CHECK: %[[rebox:.*]] = fir.rebox %[[box]] : (!fir.box>) -> !fir.box>> ! CHECK: fir.has_value %[[rebox]] : !fir.box>> end subroutine subroutine scalar_derived() type t real :: x integer :: i end type type(t), save, target :: x type(t), pointer :: p => x ! CHECK-LABEL: fir.global internal @_QFscalar_derivedEp : !fir.box>> ! CHECK: %[[xAddr:.*]] = fir.address_of(@_QFscalar_derivedEx) : !fir.ref> ! CHECK: %[[x:.*]]:2 = hlfir.declare %[[xAddr]] {{.*}} : (!fir.ref>) -> (!fir.ref>, !fir.ref>) ! CHECK: %[[box:.*]] = fir.embox %[[x]]#0 : (!fir.ref>) -> !fir.box> ! CHECK: %[[rebox:.*]] = fir.rebox %[[box]] : (!fir.box>) -> !fir.box>> ! CHECK: fir.has_value %[[rebox]] : !fir.box>> end subroutine subroutine scalar_null() real, pointer :: p => NULL() ! CHECK-LABEL: fir.global internal @_QFscalar_nullEp : !fir.box> ! CHECK: %[[zero:.*]] = fir.zero_bits !fir.ptr ! CHECK: %[[box:.*]] = fir.embox %[[zero]] : (!fir.ptr) -> !fir.box> ! CHECK: fir.has_value %[[box]] : !fir.box> end subroutine ! ----------------------------------------------------------------------------- ! Test array initial data target that are simple names ! ----------------------------------------------------------------------------- subroutine array() real, save, target :: x(100) real, pointer :: p(:) => x ! CHECK-LABEL: fir.global internal @_QFarrayEp : !fir.box>> ! CHECK: %[[xAddr:.*]] = fir.address_of(@_QFarrayEx) : !fir.ref> ! CHECK: %[[xShape:.*]] = fir.shape %c100{{.*}} : (index) -> !fir.shape<1> ! CHECK: %[[x:.*]]:2 = hlfir.declare %[[xAddr]](%[[xShape]]) {{.*}} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) ! CHECK: %[[shape:.*]] = fir.shape %c100{{.*}} : (index) -> !fir.shape<1> ! CHECK: %[[box:.*]] = fir.embox %[[x]]#0(%[[shape]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> ! CHECK: %[[rebox:.*]] = fir.rebox %[[box]] : (!fir.box>) -> !fir.box>> ! CHECK: fir.has_value %[[rebox]] : !fir.box>> end subroutine subroutine array_char() character(10), save, target :: x(20) character(:), pointer :: p(:) => x ! CHECK-LABEL: fir.global internal @_QFarray_charEp : !fir.box>>> ! CHECK: %[[xAddr:.*]] = fir.address_of(@_QFarray_charEx) : !fir.ref>> ! CHECK: %[[xShape:.*]] = fir.shape %c20{{.*}} : (index) -> !fir.shape<1> ! CHECK: %[[x:.*]]:2 = hlfir.declare %[[xAddr]](%[[xShape]]) typeparams %{{.*}} {{.*}} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.ref>>, !fir.ref>>) ! CHECK: %[[shape:.*]] = fir.shape %c20{{.*}} : (index) -> !fir.shape<1> ! CHECK: %[[box:.*]] = fir.embox %[[x]]#0(%[[shape]]) : (!fir.ref>>, !fir.shape<1>) -> !fir.box> ! CHECK: %[[rebox:.*]] = fir.rebox %[[box]] : (!fir.box>>) -> !fir.box>>> ! CHECK: fir.has_value %[[rebox]] : !fir.box>>> end subroutine subroutine array_char_2() character(10), save, target :: x(20) character(10), pointer :: p(:) => x ! CHECK-LABEL: fir.global internal @_QFarray_char_2Ep : !fir.box>>> ! CHECK: %[[xAddr:.*]] = fir.address_of(@_QFarray_char_2Ex) : !fir.ref>> ! CHECK: %[[xShape:.*]] = fir.shape %c20{{.*}} : (index) -> !fir.shape<1> ! CHECK: %[[x:.*]]:2 = hlfir.declare %[[xAddr]](%[[xShape]]) typeparams %{{.*}} {{.*}} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.ref>>, !fir.ref>>) ! CHECK: %[[shape:.*]] = fir.shape %c20{{.*}} : (index) -> !fir.shape<1> ! CHECK: %[[box:.*]] = fir.embox %[[x]]#0(%[[shape]]) : (!fir.ref>>, !fir.shape<1>) -> !fir.box>> ! CHECK: %[[rebox:.*]] = fir.rebox %[[box]] : (!fir.box>>) -> !fir.box>>> ! CHECK: fir.has_value %[[rebox]] : !fir.box>>> end subroutine subroutine array_derived() type t real :: x integer :: i end type type(t), save, target :: x(100) type(t), pointer :: p(:) => x ! CHECK-LABEL: fir.global internal @_QFarray_derivedEp : !fir.box>>> ! CHECK: %[[xAddr:.*]] = fir.address_of(@_QFarray_derivedEx) : !fir.ref>> ! CHECK: %[[xShape:.*]] = fir.shape %c100{{.*}} : (index) -> !fir.shape<1> ! CHECK: %[[x:.*]]:2 = hlfir.declare %[[xAddr]](%[[xShape]]) {{.*}} : (!fir.ref>>, !fir.shape<1>) -> (!fir.ref>>, !fir.ref>>) ! CHECK: %[[shape:.*]] = fir.shape %c100{{.*}} : (index) -> !fir.shape<1> ! CHECK: %[[box:.*]] = fir.embox %[[x]]#0(%[[shape]]) : (!fir.ref>>, !fir.shape<1>) -> !fir.box>> ! CHECK: %[[rebox:.*]] = fir.rebox %[[box]] : (!fir.box>>) -> !fir.box>>> ! CHECK: fir.has_value %[[rebox]] : !fir.box>>> end subroutine subroutine array_null() real, pointer :: p(:) => NULL() ! CHECK-LABEL: fir.global internal @_QFarray_nullEp : !fir.box>> ! CHECK: %[[zero:.*]] = fir.zero_bits !fir.ptr> ! CHECK: %[[shape:.*]] = fir.shape %c0{{.*}} : (index) -> !fir.shape<1> ! CHECK: %[[box:.*]] = fir.embox %[[zero]](%[[shape]]) : (!fir.ptr>, !fir.shape<1>) -> !fir.box>> ! CHECK: fir.has_value %[[box]] : !fir.box>> end subroutine ! ----------------------------------------------------------------------------- ! Test scalar initial data target that are data references ! ----------------------------------------------------------------------------- subroutine scalar_ref() real, save, target :: x(4:100) real, pointer :: p => x(50) ! CHECK-LABEL: fir.global internal @_QFscalar_refEp : !fir.box> { ! CHECK: %[[xAddr:.*]] = fir.address_of(@_QFscalar_refEx) : !fir.ref> ! CHECK: %[[xShape:.*]] = fir.shape_shift %c4{{.*}}, %c97{{.*}} : (index, index) -> !fir.shapeshift<1> ! CHECK: %[[x:.*]]:2 = hlfir.declare %[[xAddr]](%[[xShape]]) {{.*}} : (!fir.ref>, !fir.shapeshift<1>) -> (!fir.box>, !fir.ref>) ! CHECK: %[[elt:.*]] = hlfir.designate %[[x]]#0 (%c50{{.*}}) : (!fir.box>, index) -> !fir.ref ! CHECK: %[[box:.*]] = fir.embox %[[elt]] : (!fir.ref) -> !fir.box ! CHECK: %[[rebox:.*]] = fir.rebox %[[box]] : (!fir.box) -> !fir.box> ! CHECK: fir.has_value %[[rebox]] : !fir.box> end subroutine subroutine scalar_char_ref() character(20), save, target :: x(100) character(10), pointer :: p => x(6)(7:16) ! CHECK-LABEL: fir.global internal @_QFscalar_char_refEp : !fir.box>> ! CHECK: %[[xAddr:.*]] = fir.address_of(@_QFscalar_char_refEx) : !fir.ref>> ! CHECK: %[[xShape:.*]] = fir.shape %c100{{.*}} : (index) -> !fir.shape<1> ! CHECK: %[[x:.*]]:2 = hlfir.declare %[[xAddr]](%[[xShape]]) typeparams %c20{{.*}} {{.*}} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.ref>>, !fir.ref>>) ! CHECK: %[[elt:.*]] = hlfir.designate %[[x]]#0 (%c6{{.*}}) substr %c7{{.*}}, %c16{{.*}} typeparams %c10{{.*}} : (!fir.ref>>, index, index, index, index) -> !fir.ref> ! CHECK: %[[box:.*]] = fir.embox %[[elt]] : (!fir.ref>) -> !fir.box> ! CHECK: %[[rebox:.*]] = fir.rebox %[[box]] : (!fir.box>) -> !fir.box>> ! CHECK: fir.has_value %[[rebox]] : !fir.box>> end subroutine ! ----------------------------------------------------------------------------- ! Test array initial data target that are data references ! ----------------------------------------------------------------------------- subroutine array_ref() real, save, target :: x(4:103, 5:104) real, pointer :: p(:) => x(10, 20:100:2) end subroutine ! CHECK-LABEL: fir.global internal @_QFarray_refEp : !fir.box>> { ! CHECK: %[[VAL_0:.*]] = fir.address_of(@_QFarray_refEx) : !fir.ref> ! CHECK: %[[VAL_1:.*]] = arith.constant 4 : index ! CHECK: %[[VAL_2:.*]] = arith.constant 100 : index ! CHECK: %[[VAL_3:.*]] = arith.constant 5 : index ! CHECK: %[[VAL_4:.*]] = arith.constant 100 : index ! CHECK: %[[VAL_SHAPE:.*]] = fir.shape_shift %[[VAL_1]], %[[VAL_2]], %[[VAL_3]], %[[VAL_4]] : (index, index, index, index) -> !fir.shapeshift<2> ! CHECK: %[[VAL_X:.*]]:2 = hlfir.declare %[[VAL_0]](%[[VAL_SHAPE]]) {{.*}} : (!fir.ref>, !fir.shapeshift<2>) -> (!fir.box>, !fir.ref>) ! CHECK: %[[VAL_25:.*]] = hlfir.designate %[[VAL_X]]#0 (%c10{{.*}}, %c20{{.*}}:%c100{{.*}}:%c2{{.*}}) shape %{{.*}} : (!fir.box>, index, index, index, index, !fir.shape<1>) -> !fir.box> ! CHECK: %[[VAL_26:.*]] = fir.rebox %[[VAL_25]] : (!fir.box>) -> !fir.box>> ! CHECK: fir.has_value %[[VAL_26]] : !fir.box>> ! CHECK: }