! RUN: bbc -emit-hlfir -I nw %s -o - | FileCheck %s module components_test type t1 integer :: i(6) real :: r(5) end type t1 type t2 type(t1) :: g1(3,3), g2(4,4,4) integer :: g3(5) end type t2 type t3 type(t1) :: h1(3) type(t2) :: h2(4) end type t3 type(t3) :: instance contains subroutine s1(i,j) i = instance%h2(2)%g2(1,2,3)%i(j) end subroutine s1 ! CHECK-LABEL: func.func @_QMcomponents_testPs1( ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref {fir.bindc_name = "i"}, ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref {fir.bindc_name = "j"}) { ! CHECK: %[[VAL_2:.*]] = fir.dummy_scope : !fir.dscope ! CHECK: %[[VAL_3:.*]] = fir.address_of(@_QMcomponents_testEinstance) : !fir.ref, !fir.dscope) -> (!fir.ref, !fir.ref) ! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_1]] dummy_scope %[[VAL_2]] arg {{[0-9]+}} {uniq_name = "_QMcomponents_testFs1Ej"} : (!fir.ref, !fir.dscope) -> (!fir.ref, !fir.ref) ! CHECK: %[[VAL_7:.*]] = arith.constant 4 : index ! CHECK: %[[VAL_8:.*]] = fir.shape %[[VAL_7]] : (index) -> !fir.shape<1> ! CHECK: %[[VAL_9:.*]] = arith.constant 2 : index ! CHECK: %[[VAL_10:.*]] = hlfir.designate %[[VAL_4]]#0{"h2"} <%[[VAL_8]]> (%[[VAL_9]]) : (!fir.ref !fir.shape<3> ! CHECK: %[[VAL_15:.*]] = arith.constant 1 : index ! CHECK: %[[VAL_16:.*]] = arith.constant 2 : index ! CHECK: %[[VAL_17:.*]] = arith.constant 3 : index ! CHECK: %[[VAL_18:.*]] = hlfir.designate %[[VAL_10]]{"g2"} <%[[VAL_14]]> (%[[VAL_15]], %[[VAL_16]], %[[VAL_17]]) : (!fir.ref !fir.shape<1> ! CHECK: %[[VAL_21:.*]] = fir.load %[[VAL_6]]#0 : !fir.ref ! CHECK: %[[VAL_22:.*]] = fir.convert %[[VAL_21]] : (i32) -> i64 ! CHECK: %[[VAL_23:.*]] = hlfir.designate %[[VAL_18]]{"i"} <%[[VAL_20]]> (%[[VAL_22]]) : (!fir.ref ! CHECK: hlfir.assign %[[VAL_24]] to %[[VAL_5]]#0 : i32, !fir.ref ! CHECK: return ! CHECK: } end module components_test subroutine sliced_base() interface subroutine takes_int_array(i) integer :: i(:) end subroutine end interface type t real :: x integer :: y end type type(t) :: a(100) a(1:50)%y = 42 call takes_int_array(a(1:50)%y) end subroutine ! CHECK-LABEL: func.func @_QPsliced_base() { ! CHECK: %[[VAL_0:.*]] = arith.constant 100 : index ! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.array<100x!fir.type<_QFsliced_baseTt ! CHECK: %[[VAL_2:.*]] = fir.shape %[[VAL_0]] : (index) -> !fir.shape<1> ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_1]](%[[VAL_2]]) {uniq_name = "_QFsliced_baseEa"} : (!fir.ref !fir.shape<1> ! CHECK: %[[VAL_10:.*]] = hlfir.designate %[[VAL_3]]#0 (%[[VAL_5]]:%[[VAL_6]]:%[[VAL_7]]) shape %[[VAL_9]] : (!fir.ref> ! CHECK: %[[VAL_12:.*]] = arith.constant 1 : index ! CHECK: %[[VAL_13:.*]] = arith.constant 50 : index ! CHECK: %[[VAL_14:.*]] = arith.constant 1 : index ! CHECK: %[[VAL_15:.*]] = arith.constant 50 : index ! CHECK: %[[VAL_16:.*]] = fir.shape %[[VAL_15]] : (index) -> !fir.shape<1> ! CHECK: %[[VAL_17:.*]] = hlfir.designate %[[VAL_3]]#0 (%[[VAL_12]]:%[[VAL_13]]:%[[VAL_14]]) shape %[[VAL_16]] : (!fir.ref>) -> !fir.box> ! CHECK: fir.call @_QPtakes_int_array(%[[VAL_19]]) fastmath : (!fir.box>) -> () ! CHECK: return ! CHECK: } subroutine issue772(a, x) ! Verify that sub-expressions inside a component reference are ! only evaluated once. type t real :: b(100) end type real :: x(100) type(t) :: a(100) x = a(ifoo())%b(1:100:1) print *, a(20)%b(1:ibar():1) end subroutine ! CHECK-LABEL: func.func @_QPissue772( ! CHECK: fir.call @_QPifoo() ! CHECK-NOT: fir.call @_QPifoo() ! CHECK: fir.call @_QPibar() ! CHECK-NOT: fir.call @_QPibar() ! CHECK: return ! ----------------------------------------------------------------------------- ! Test array%character array sections ! ----------------------------------------------------------------------------- subroutine lhs_char_section(a) type t character(5) :: c end type type(t) :: a(10) a%c = "hello" end subroutine ! CHECK-LABEL: func.func @_QPlhs_char_section( ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref !fir.shape<1> ! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_0]](%[[VAL_3]]) dummy_scope %[[VAL_1]] arg {{[0-9]+}} {uniq_name = "_QFlhs_char_sectionEa"} : (!fir.ref> ! CHECK: %[[VAL_6:.*]] = arith.constant 5 : index ! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_5]] typeparams %[[VAL_6]] {fortran_attrs = #fir.var_attrs, uniq_name = "_QQclX68656C6C6F"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) ! CHECK: %[[VAL_8:.*]] = arith.constant 5 : index ! CHECK: %[[VAL_9:.*]] = hlfir.designate %[[VAL_4]]#0{"c"} shape %[[VAL_3]] typeparams %[[VAL_8]] : (!fir.ref>, !fir.ref>> ! CHECK: return ! CHECK: } subroutine rhs_char_section(a, c) type t character(10) :: c end type type(t) :: a(10) character(10) :: c(10) c = a%c end subroutine ! CHECK-LABEL: func.func @_QPrhs_char_section( ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref {fir.bindc_name = "c"}) { ! CHECK: %[[VAL_2:.*]] = fir.dummy_scope : !fir.dscope ! CHECK: %[[VAL_3:.*]] = arith.constant 10 : index ! CHECK: %[[VAL_4:.*]] = fir.shape %[[VAL_3]] : (index) -> !fir.shape<1> ! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_0]](%[[VAL_4]]) dummy_scope %[[VAL_2]] arg {{[0-9]+}} {uniq_name = "_QFrhs_char_sectionEa"} : (!fir.ref) -> (!fir.ref>, index) ! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_6]]#0 : (!fir.ref>) -> !fir.ref>> ! CHECK: %[[VAL_8:.*]] = arith.constant 10 : index ! CHECK: %[[VAL_9:.*]] = arith.constant 10 : index ! CHECK: %[[VAL_10:.*]] = fir.shape %[[VAL_9]] : (index) -> !fir.shape<1> ! CHECK: %[[VAL_11:.*]]:2 = hlfir.declare %[[VAL_7]](%[[VAL_10]]) typeparams %[[VAL_8]] dummy_scope %[[VAL_2]] arg {{[0-9]+}} {uniq_name = "_QFrhs_char_sectionEc"} : (!fir.ref>>, !fir.shape<1>, index, !fir.dscope) -> (!fir.ref>>, !fir.ref>>) ! CHECK: %[[VAL_12:.*]] = arith.constant 10 : index ! CHECK: %[[VAL_13:.*]] = hlfir.designate %[[VAL_5]]#0{"c"} shape %[[VAL_4]] typeparams %[[VAL_12]] : (!fir.ref>>, !fir.ref>> ! CHECK: return ! CHECK: } subroutine elemental_char_section(a, i) type t character(10) :: c end type type(t) :: a(10) integer :: i(10) i = scan(a%c, "hello") end subroutine ! CHECK-LABEL: func.func @_QPelemental_char_section( ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref> {fir.bindc_name = "i"}) { ! CHECK: %[[VAL_2:.*]] = fir.dummy_scope : !fir.dscope ! CHECK: %[[VAL_3:.*]] = arith.constant 10 : index ! CHECK: %[[VAL_4:.*]] = fir.shape %[[VAL_3]] : (index) -> !fir.shape<1> ! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_0]](%[[VAL_4]]) dummy_scope %[[VAL_2]] arg {{[0-9]+}} {uniq_name = "_QFelemental_char_sectionEa"} : (!fir.ref !fir.shape<1> ! CHECK: %[[VAL_8:.*]]:2 = hlfir.declare %[[VAL_1]](%[[VAL_7]]) dummy_scope %[[VAL_2]] arg {{[0-9]+}} {uniq_name = "_QFelemental_char_sectionEi"} : (!fir.ref>, !fir.shape<1>, !fir.dscope) -> (!fir.ref>, !fir.ref>) ! CHECK: %[[VAL_9:.*]] = arith.constant 10 : index ! CHECK: %[[VAL_10:.*]] = hlfir.designate %[[VAL_5]]#0{"c"} shape %[[VAL_4]] typeparams %[[VAL_9]] : (!fir.ref> ! CHECK: %[[VAL_12:.*]] = arith.constant 5 : index ! CHECK: %[[VAL_13:.*]]:2 = hlfir.declare %[[VAL_11]] typeparams %[[VAL_12]] {fortran_attrs = #fir.var_attrs, uniq_name = "_QQclX68656C6C6F"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) ! CHECK: %[[VAL_14:.*]] = hlfir.elemental %[[VAL_4]] unordered : (!fir.shape<1>) -> !hlfir.expr<10xi32> { ! CHECK: ^bb0(%[[VAL_15:.*]]: index): ! CHECK: %[[VAL_16:.*]] = hlfir.designate %[[VAL_10]] (%[[VAL_15]]) typeparams %[[VAL_9]] : (!fir.ref>>, index, index) -> !fir.ref> ! CHECK: %[[VAL_17:.*]] = arith.constant false ! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_16]] : (!fir.ref>) -> !fir.ref ! CHECK: %[[VAL_19:.*]] = fir.convert %[[VAL_9]] : (index) -> i64 ! CHECK: %[[VAL_20:.*]] = fir.convert %[[VAL_13]]#0 : (!fir.ref>) -> !fir.ref ! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_12]] : (index) -> i64 ! CHECK: %[[VAL_22:.*]] = fir.call @_FortranAScan1(%[[VAL_18]], %[[VAL_19]], %[[VAL_20]], %[[VAL_21]], %[[VAL_17]]) fastmath : (!fir.ref, i64, !fir.ref, i64, i1) -> i64 ! CHECK: %[[VAL_23:.*]] = fir.convert %[[VAL_22]] : (i64) -> i32 ! CHECK: hlfir.yield_element %[[VAL_23]] : i32 ! CHECK: } ! CHECK: hlfir.assign %[[VAL_14]] to %[[VAL_8]]#0 : !hlfir.expr<10xi32>, !fir.ref> ! CHECK: hlfir.destroy %[[VAL_14]] : !hlfir.expr<10xi32> ! CHECK: return ! CHECK: } ! CHECK-LABEL: func.func @_QPextended_type_components() { subroutine extended_type_components type t1 integer :: t1i end type t1 type, extends(t1) :: t2 integer :: t2i end type t2 type, extends(t2) :: t3 integer :: t3i end type t3 type, extends(t3) :: t4 integer :: t4i end type t4 ! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.box>> ! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.box>> ! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.box>> ! CHECK: %[[VAL_3:.*]] = fir.alloca !fir.box>> ! CHECK: %[[VAL_4:.*]] = fir.alloca !fir.type<_QFextended_type_componentsTu3 ! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_4]] {uniq_name = "_QFextended_type_componentsEu3v"} : (!fir.ref !fir.shape<1> ! CHECK: %[[VAL_9:.*]]:2 = hlfir.declare %[[VAL_7]](%[[VAL_8]]) {uniq_name = "_QFextended_type_componentsEu3va"} : (!fir.ref : (!fir.ref) -> () call foo2(u3v%u2%u2t3%t2%t1%t1i) ! different syntax for the previous value ! CHECK: %[[VAL_15:.*]] = hlfir.designate %[[VAL_5]]#0{"u2"} : (!fir.ref : (!fir.ref) -> () call foo3(u3v%u2t4%t1i) ! CHECK: %[[VAL_20:.*]] = hlfir.designate %[[VAL_5]]#0{"u2"} : (!fir.ref : (!fir.ref) -> () call foo4(u3v%u2t4%t2i) ! CHECK: %[[VAL_25:.*]] = hlfir.designate %[[VAL_5]]#0{"u2"} : (!fir.ref : (!fir.ref) -> () call foo5(u3va%u2t3%t1i) ! CHECK: %[[VAL_29:.*]] = hlfir.designate %[[VAL_9]]#0{"u2"} shape %[[VAL_8]] : (!fir.ref>, !fir.ref>>>) -> (!fir.box>, i1) ! CHECK: %[[VAL_35:.*]] = fir.box_addr %[[VAL_34]]#0 : (!fir.box>) -> !fir.ref> ! CHECK: fir.call @_QPfoo5(%[[VAL_35]]) fastmath : (!fir.ref>) -> () call foo6(u3va%u2%u2t3%t2%t1%t1i) ! different syntax for the previous value ! CHECK: %[[VAL_36:.*]] = hlfir.designate %[[VAL_9]]#0{"u2"} shape %[[VAL_8]] : (!fir.ref>, !fir.ref>>>) -> (!fir.box>, i1) ! CHECK: %[[VAL_42:.*]] = fir.box_addr %[[VAL_41]]#0 : (!fir.box>) -> !fir.ref> ! CHECK: fir.call @_QPfoo6(%[[VAL_42]]) fastmath : (!fir.ref>) -> () call foo7(u3va%u2t4%t1i) ! CHECK: %[[VAL_43:.*]] = hlfir.designate %[[VAL_9]]#0{"u2"} shape %[[VAL_8]] : (!fir.ref>, !fir.ref>>>) -> (!fir.box>, i1) ! CHECK: %[[VAL_49:.*]] = fir.box_addr %[[VAL_48]]#0 : (!fir.box>) -> !fir.ref> ! CHECK: fir.call @_QPfoo7(%[[VAL_49]]) fastmath : (!fir.ref>) -> () call foo8(u3va%u2t4%t2i) ! CHECK: %[[VAL_50:.*]] = hlfir.designate %[[VAL_9]]#0{"u2"} shape %[[VAL_8]] : (!fir.ref>, !fir.ref>>>) -> (!fir.box>, i1) ! CHECK: %[[VAL_55:.*]] = fir.box_addr %[[VAL_54]]#0 : (!fir.box>) -> !fir.ref> ! CHECK: fir.call @_QPfoo8(%[[VAL_55]]) fastmath : (!fir.ref>) -> () end subroutine extended_type_components