! Test lowering of pointer initial target ! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s ! This tests focus on the scope context of initial data target. ! More complete tests regarding the initial data target expression ! are done in pointer-initial-target.f90. ! Test pointer initial data target with pointer in common blocks block data real, pointer :: p real, save, target :: b common /a/ p data p /b/ ! CHECK-LABEL: fir.global @a_ : tuple>> ! CHECK: %[[undef:.*]] = fir.zero_bits tuple>> ! CHECK: %[[b:.*]] = fir.address_of(@_QEb) : !fir.ref ! CHECK: %[[box:.*]] = fir.embox %[[b]] : (!fir.ref) -> !fir.box ! CHECK: %[[rebox:.*]] = fir.rebox %[[box]] : (!fir.box) -> !fir.box> ! CHECK: %[[a:.*]] = fir.insert_value %[[undef]], %[[rebox]], [0 : index] : (tuple>>, !fir.box>) -> tuple>> ! CHECK: fir.has_value %[[a]] : tuple>> end block data ! Test two common depending on each others because of initial data ! targets block data tied real, target :: x1 = 42 real, target :: x2 = 43 real, pointer :: p1 => x2 real, pointer :: p2 => x1 common /c1/ x1, p1 common /c2/ x2, p2 ! CHECK-LABEL: fir.global @c1_ : tuple, !fir.box>> ! CHECK: fir.address_of(@c2_) : !fir.ref, !fir.box>>> ! CHECK-LABEL: fir.global @c2_ : tuple, !fir.box>> ! CHECK: fir.address_of(@c1_) : !fir.ref, !fir.box>>> end block data ! Test pointer in a common with initial target in the same common. block data bdsnake integer, target :: b = 42 integer, pointer :: p => b common /snake/ p, b ! CHECK-LABEL: fir.global @snake_ : tuple>, i32> ! CHECK: %[[tuple0:.*]] = fir.zero_bits tuple>, i32> ! CHECK: %[[snakeAddr:.*]] = fir.address_of(@snake_) : !fir.ref>, i32>> ! CHECK: %[[byteView:.*]] = fir.convert %[[snakeAddr:.*]] : (!fir.ref>, i32>>) -> !fir.ref> ! CHECK: %[[coor:.*]] = fir.coordinate_of %[[byteView]], %c24{{.*}} : (!fir.ref>, index) -> !fir.ref ! CHECK: %[[bAddr:.*]] = fir.convert %[[coor]] : (!fir.ref) -> !fir.ref ! CHECK: %[[box:.*]] = fir.embox %[[bAddr]] : (!fir.ref) -> !fir.box ! CHECK: %[[rebox:.*]] = fir.rebox %[[box]] : (!fir.box) -> !fir.box> ! CHECK: %[[tuple1:.*]] = fir.insert_value %[[tuple0]], %[[rebox]], [0 : index] : (tuple>, i32>, !fir.box>) -> tuple>, i32> ! CHECK: %[[tuple2:.*]] = fir.insert_value %[[tuple1]], %c42{{.*}}, [1 : index] : (tuple>, i32>, i32) -> tuple>, i32> ! CHECK: fir.has_value %[[tuple2]] : tuple>, i32> end block data ! Test pointer initial data target in modules module some_mod real, target :: x(100) real, pointer :: p(:) => x ! CHECK-LABEL: fir.global @_QMsome_modEp : !fir.box>> { ! CHECK: %[[x:.*]] = fir.address_of(@_QMsome_modEx) : !fir.ref> ! CHECK: %[[shape:.*]] = fir.shape %c100{{.*}} : (index) -> !fir.shape<1> ! CHECK: %[[box:.*]] = fir.embox %[[x]](%[[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 module ! Test initial data target in a common block module some_mod_2 real, target :: x(100), y(10:209) common /com/ x, y save :: /com/ real, pointer :: p(:) => y ! CHECK-LABEL: fir.global @_QMsome_mod_2Ep : !fir.box>> { ! CHECK: %[[c:.*]] = fir.address_of(@com_) : !fir.ref> ! CHECK: %[[com:.*]] = fir.convert %[[c]] : (!fir.ref>) -> !fir.ref> ! CHECK: %[[yRaw:.*]] = fir.coordinate_of %[[com]], %c400{{.*}} : (!fir.ref>, index) -> !fir.ref ! CHECK: %[[y:.*]] = fir.convert %[[yRaw]] : (!fir.ref) -> !fir.ref> ! CHECK: %[[shape:.*]] = fir.shape_shift %c10{{.*}}, %c200{{.*}} : (index, index) -> !fir.shapeshift<1> ! CHECK: %[[box:.*]] = fir.embox %[[y]](%[[shape]]) : (!fir.ref>, !fir.shapeshift<1>) -> !fir.box> ! CHECK: %[[shift:.*]] = fir.shift %c10{{.*}} : (index) -> !fir.shift<1> ! CHECK: %[[rebox:.*]] = fir.rebox %[[box]](%[[shift]]) : (!fir.box>, !fir.shift<1>) -> !fir.box>> ! CHECK: fir.has_value %[[rebox]] : !fir.box>> end module