248 lines · plain
1! RUN: bbc -emit-hlfir -frepack-arrays -fstack-repack-arrays -frepack-arrays-continuity-whole %s -o - -I nowhere | FileCheck --check-prefixes=ALL,STACK,WHOLE %s2! RUN: bbc -emit-hlfir -frepack-arrays -fstack-repack-arrays=false -frepack-arrays-continuity-whole %s -o - -I nowhere | FileCheck --check-prefixes=ALL,HEAP,WHOLE %s3! RUN: bbc -emit-hlfir -frepack-arrays -fstack-repack-arrays -frepack-arrays-continuity-whole=false %s -o - -I nowhere | FileCheck --check-prefixes=ALL,STACK,INNER %s4! RUN: bbc -emit-hlfir -frepack-arrays -fstack-repack-arrays=false -frepack-arrays-continuity-whole=false %s -o - -I nowhere | FileCheck --check-prefixes=ALL,HEAP,INNER %s5 6! ALL-LABEL: func.func @_QPtest1(7! ALL-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x"}) {8subroutine test1(x)9 real :: x(:)10! ALL: %[[VAL_2:.*]] = fir.pack_array %[[VAL_0]]11! STACK-SAME: stack12! HEAP-SAME: heap13! WHOLE-SAME: whole14! ALL-NOT: no_copy15! ALL-SAME : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>16! ALL: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_2]] dummy_scope %{{.*}} {uniq_name = "_QFtest1Ex"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)17! ALL: fir.unpack_array %[[VAL_2]] to %[[VAL_0]]18! STACK-SAME: stack19! HEAP-SAME: heap20! ALL-NOT: no_copy21! ALL-SAME: : !fir.box<!fir.array<?xf32>>22end subroutine test123 24! ALL-LABEL: func.func @_QPtest2(25! ALL-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !fir.ref<i32> {fir.bindc_name = "n"},26! ALL-SAME: %[[VAL_1:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !fir.box<!fir.array<?x?x!fir.char<1,?>>> {fir.bindc_name = "x"}) {27subroutine test2(n, x)28 integer :: n29 character(n) :: x(:,:)30! ALL: %[[VAL_8:.*]] = fir.pack_array %[[VAL_1]]31! STACK-SAME: stack32! HEAP-SAME: heap33! WHOLE-SAME: whole34! INNER-SAME: innermost35! ALL-NOT: no_copy36! ALL-SAME: typeparams %[[VAL_7:.*]] : (!fir.box<!fir.array<?x?x!fir.char<1,?>>>, i32) -> !fir.box<!fir.array<?x?x!fir.char<1,?>>>37! ALL: %[[VAL_9:.*]]:2 = hlfir.declare %[[VAL_8]] typeparams %[[VAL_7]] dummy_scope %{{.*}} {uniq_name = "_QFtest2Ex"} : (!fir.box<!fir.array<?x?x!fir.char<1,?>>>, i32, !fir.dscope) -> (!fir.box<!fir.array<?x?x!fir.char<1,?>>>, !fir.box<!fir.array<?x?x!fir.char<1,?>>>)38! ALL: fir.unpack_array %[[VAL_8]] to %[[VAL_1]]39! STACK-SAME: stack40! HEAP-SAME: heap41! ALL-NOT: no_copy42! ALL-SAME: : !fir.box<!fir.array<?x?x!fir.char<1,?>>>43end subroutine test244 45! ALL-LABEL: func.func @_QPtest3(46! ALL-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !fir.box<!fir.array<?x?x!fir.type<_QFtest3Tt>>> {fir.bindc_name = "x"}) {47subroutine test3(x)48 type t49 end type t50 type(t) :: x(:,:)51! ALL: %[[VAL_2:.*]] = fir.pack_array %[[VAL_0]]52! STACK-SAME: stack53! HEAP-SAME: heap54! WHOLE-SAME: whole55! INNER-SAME: innermost56! ALL-NOT: no_copy57! ALL-SAME: : (!fir.box<!fir.array<?x?x!fir.type<_QFtest3Tt>>>) -> !fir.box<!fir.array<?x?x!fir.type<_QFtest3Tt>>>58! ALL: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_2]] dummy_scope %{{.*}} {uniq_name = "_QFtest3Ex"} : (!fir.box<!fir.array<?x?x!fir.type<_QFtest3Tt>>>, !fir.dscope) -> (!fir.box<!fir.array<?x?x!fir.type<_QFtest3Tt>>>, !fir.box<!fir.array<?x?x!fir.type<_QFtest3Tt>>>)59! ALL: fir.unpack_array %[[VAL_2]] to %[[VAL_0]]60! STACK-SAME: stack61! HEAP-SAME: heap62! ALL-NOT: no_copy63! ALL-SAME: : !fir.box<!fir.array<?x?x!fir.type<_QFtest3Tt>>>64end subroutine test365 66! ALL-LABEL: func.func @_QPtest4(67! ALL-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x"}) {68subroutine test4(x)69 real, intent(inout) :: x(:)70! ALL: %[[VAL_2:.*]] = fir.pack_array %[[VAL_0]]71! STACK-SAME: stack72! HEAP-SAME: heap73! WHOLE-SAME: whole74! ALL-NOT: no_copy75! ALL-SAME : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>76! ALL: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_2]] dummy_scope %{{.*}} {fortran_attrs = #fir.var_attrs<intent_inout>, uniq_name = "_QFtest4Ex"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)77! ALL: fir.unpack_array %[[VAL_2]] to %[[VAL_0]]78! STACK-SAME: stack79! HEAP-SAME: heap80! ALL-NOT: no_copy81! ALL-SAME : !fir.box<!fir.array<?xf32>>82end subroutine test483 84! ALL-LABEL: func.func @_QPtest5(85! ALL-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x"}) {86subroutine test5(x)87 real, intent(in) :: x(:)88! ALL: %[[VAL_2:.*]] = fir.pack_array %[[VAL_0]]89! STACK-SAME: stack90! HEAP-SAME: heap91! WHOLE-SAME: whole92! ALL-NOT: no_copy93! ALL-SAME: (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>94! ALL: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_2]] dummy_scope %{{.*}} {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QFtest5Ex"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)95! ALL: fir.unpack_array %[[VAL_2]] to %[[VAL_0]]96! STACK-SAME: stack97! HEAP-SAME: heap98! ALL-SAME no_copy : !fir.box<!fir.array<?xf32>>99end subroutine test5100 101! ALL-LABEL: func.func @_QPtest6(102! ALL-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x"}) {103subroutine test6(x)104 real, intent(out) :: x(:)105! ALL: %[[VAL_2:.*]] = fir.pack_array %[[VAL_0]]106! STACK-SAME: stack107! HEAP-SAME: heap108! WHOLE-SAME: whole109! ALL-SAME no_copy : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>110! ALL: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_2]] dummy_scope %{{.*}} {fortran_attrs = #fir.var_attrs<intent_out>, uniq_name = "_QFtest6Ex"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)111! ALL: fir.unpack_array %[[VAL_2]] to %[[VAL_0]]112! STACK-SAME: stack113! HEAP-SAME: heap114! ALL-NOT: no_copy115! ALL-SAME : !fir.box<!fir.array<?xf32>>116end subroutine test6117 118! ALL-LABEL: func.func @_QPtest7(119! ALL-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !fir.class<!fir.array<?x!fir.type<_QFtest7Tt>>> {fir.bindc_name = "x"}) {120subroutine test7(x)121 type t122 end type t123 class(t) :: x(:)124! ALL: %[[VAL_2:.*]] = fir.pack_array %[[VAL_0]]125! STACK-SAME: stack126! HEAP-SAME: heap127! WHOLE-SAME: whole128! ALL-NOT: no_copy129! ALL-SAME : (!fir.class<!fir.array<?x!fir.type<_QFtest7Tt>>>) -> !fir.class<!fir.array<?x!fir.type<_QFtest7Tt>>>130! ALL: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_2]] dummy_scope %{{.*}} {uniq_name = "_QFtest7Ex"} : (!fir.class<!fir.array<?x!fir.type<_QFtest7Tt>>>, !fir.dscope) -> (!fir.class<!fir.array<?x!fir.type<_QFtest7Tt>>>, !fir.class<!fir.array<?x!fir.type<_QFtest7Tt>>>)131! ALL: fir.unpack_array %[[VAL_2]] to %[[VAL_0]]132! STACK-SAME: stack133! HEAP-SAME: heap134! ALL-NOT: no_copy135! ALL-SAME : !fir.class<!fir.array<?x!fir.type<_QFtest7Tt>>>136end subroutine test7137 138! ALL-LABEL: func.func @_QPtest8(139! ALL-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x"}) {140subroutine test8(x)141 real :: x(:)142! ALL: %[[VAL_2:.*]] = fir.pack_array %[[VAL_0]]143! STACK-SAME: stack144! HEAP-SAME: heap145! WHOLE-SAME: whole146! ALL-NOT: no_copy147! ALL-SAME : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>148! ALL: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_2]] dummy_scope %{{.*}} {uniq_name = "_QFtest8Ex"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)149 call inner(x(1))150! ALL: fir.call @_QFtest8Pinner151! ALL: fir.unpack_array %[[VAL_2]] to %[[VAL_0]]152! STACK-SAME: stack153! HEAP-SAME: heap154! ALL-NOT: no_copy155! ALL-SAME : !fir.box<!fir.array<?xf32>>156contains157! ALL-LABEL: func.func private @_QFtest8Pinner(158 subroutine inner(y)159! ALL-NOT: fir.pack_array160! ALL-NOT: fir.unpack_array161 real :: y162 y = 1.0163 end subroutine inner164end subroutine test8165 166! ALL-LABEL: func.func @_QPtest9(167! ALL-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x"}) -> f32 {168real function test9(x)169 real :: x(:)170! ALL: %[[VAL_6:.*]] = fir.pack_array %[[VAL_0]]171! STACK-SAME: stack172! HEAP-SAME: heap173! WHOLE-SAME: whole174! ALL-NOT: no_copy175! ALL-SAME : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>176! ALL: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_6]] dummy_scope %{{.*}} {uniq_name = "_QFtest9Ex"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)177 real :: y(10)178 test9 = x(1)179! ALL: fir.unpack_array %[[VAL_6]] to %[[VAL_0]]180! STACK-SAME: stack181! HEAP-SAME: heap182! ALL-NOT: no_copy183! ALL-SAME : !fir.box<!fir.array<?xf32>>184! ALL-NEXT: return185 return186 187! ALL-LABEL: func.func @_QPtest9_alt(188 entry test9_alt(y)189! ALL-NOT: fir.pack_array190! ALL-NOT: fir.unpack_array191 rest9_ = y(1)192end function test9193 194! ALL-LABEL: func.func @_QPtest10(195! ALL-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !fir.box<!fir.array<?x?xf32>> {fir.bindc_name = "x", fir.optional}) {196subroutine test10(x)197 real, optional :: x(:,:)198! ALL: %[[VAL_2:.*]] = fir.pack_array %[[VAL_0]]199! STACK-SAME: stack200! HEAP-SAME: heap201! WHOLE-SAME: whole202! INNER-SAME: innermost203! ALL-NOT: no_copy204! ALL-SAME: : (!fir.box<!fir.array<?x?xf32>>) -> !fir.box<!fir.array<?x?xf32>>205! ALL: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_2]] dummy_scope %{{.*}} {fortran_attrs = #fir.var_attrs<optional>, uniq_name = "_QFtest10Ex"} : (!fir.box<!fir.array<?x?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?x?xf32>>, !fir.box<!fir.array<?x?xf32>>)206! ALL: fir.unpack_array %[[VAL_2]] to %[[VAL_0]]207! STACK-SAME: stack208! HEAP-SAME: heap209! ALL-NOT: no_copy210! ALL-SAME: : !fir.box<!fir.array<?x?xf32>>211end subroutine test10212 213! ALL-LABEL: func.func @_QPtest11(214! ALL-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !fir.box<!fir.array<?x!fir.char<1,10>>> {fir.bindc_name = "x"}) {215subroutine test11(x)216 character(10) :: x(:)217! ALL: %[[VAL_3:.*]] = fir.pack_array %[[VAL_0]]218! STACK-SAME: stack219! HEAP-SAME: heap220! WHOLE-SAME: whole221! INNER-SAME: whole222! ALL-NOT: no_copy223! ALL-SAME: : (!fir.box<!fir.array<?x!fir.char<1,10>>>) -> !fir.box<!fir.array<?x!fir.char<1,10>>>224! ALL: fir.unpack_array %[[VAL_3]] to %[[VAL_0]]225! STACK-SAME: stack226! HEAP-SAME: heap227! ALL-NOT: no_copy228! ALL-SAME: : !fir.box<!fir.array<?x!fir.char<1,10>>>229end subroutine test11230 231! ALL-LABEL: func.func @_QPtest12(232! ALL-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !fir.box<!fir.array<?x!fir.char<1,?>>> {fir.bindc_name = "x"}) {233subroutine test12(x)234 character(*) :: x(:)235! ALL: %[[VAL_2:.*]] = fir.pack_array %[[VAL_0]]236! STACK-SAME: stack237! HEAP-SAME: heap238! WHOLE-SAME: whole239! INNER-SAME: whole240! ALL-NOT: no_copy241! ALL-SAME: : (!fir.box<!fir.array<?x!fir.char<1,?>>>) -> !fir.box<!fir.array<?x!fir.char<1,?>>>242! ALL: fir.unpack_array %[[VAL_2]] to %[[VAL_0]]243! STACK-SAME: stack244! HEAP-SAME: heap245! ALL-NOT: no_copy246! ALL-SAME: : !fir.box<!fir.array<?x!fir.char<1,?>>>247end subroutine test12248