98 lines · plain
1! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s2 3! Test passing arrays to assumed shape dummy arguments4 5! CHECK-LABEL: func @_QPfoo()6subroutine foo()7 interface8 subroutine bar(x)9 ! lbounds are meaningless on caller side, some are added10 ! here to check they are ignored.11 real :: x(1:, 10:, :)12 end subroutine13 end interface14 real :: x(42, 55, 12)15 ! CHECK-DAG: %[[c42:.*]] = arith.constant 42 : index16 ! CHECK-DAG: %[[c55:.*]] = arith.constant 55 : index17 ! CHECK-DAG: %[[c12:.*]] = arith.constant 12 : index18 ! CHECK-DAG: %[[addr:.*]] = fir.alloca !fir.array<42x55x12xf32> {{{.*}}uniq_name = "_QFfooEx"}19 20 call bar(x)21 ! CHECK: %[[shape:.*]] = fir.shape %[[c42]], %[[c55]], %[[c12]] : (index, index, index) -> !fir.shape<3>22 ! CHECK: %[[embox:.*]] = fir.embox %[[addr]](%[[shape]]) : (!fir.ref<!fir.array<42x55x12xf32>>, !fir.shape<3>) -> !fir.box<!fir.array<42x55x12xf32>>23 ! CHECK: %[[castedBox:.*]] = fir.convert %[[embox]] : (!fir.box<!fir.array<42x55x12xf32>>) -> !fir.box<!fir.array<?x?x?xf32>>24 ! CHECK: fir.call @_QPbar(%[[castedBox]]) {{.*}}: (!fir.box<!fir.array<?x?x?xf32>>) -> ()25end subroutine26 27 28! Test passing character array as assumed shape.29! CHECK-LABEL: func @_QPfoo_char(%arg0: !fir.boxchar<1>{{.*}})30subroutine foo_char(x)31 interface32 subroutine bar_char(x)33 character(*) :: x(1:, 10:, :)34 end subroutine35 end interface36 character(*) :: x(42, 55, 12)37 ! CHECK-DAG: %[[x:.*]]:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)38 ! CHECK-DAG: %[[addr:.*]] = fir.convert %[[x]]#0 : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<!fir.array<42x55x12x!fir.char<1,?>>>39 ! CHECK-DAG: %[[c42:.*]] = arith.constant 42 : index40 ! CHECK-DAG: %[[c55:.*]] = arith.constant 55 : index41 ! CHECK-DAG: %[[c12:.*]] = arith.constant 12 : index42 43 call bar_char(x)44 ! CHECK: %[[shape:.*]] = fir.shape %[[c42]], %[[c55]], %[[c12]] : (index, index, index) -> !fir.shape<3>45 ! CHECK: %[[embox:.*]] = fir.embox %[[addr]](%[[shape]]) typeparams %[[x]]#1 : (!fir.ref<!fir.array<42x55x12x!fir.char<1,?>>>, !fir.shape<3>, index) -> !fir.box<!fir.array<42x55x12x!fir.char<1,?>>>46 ! CHECK: %[[castedBox:.*]] = fir.convert %[[embox]] : (!fir.box<!fir.array<42x55x12x!fir.char<1,?>>>) -> !fir.box<!fir.array<?x?x?x!fir.char<1,?>>>47 ! CHECK: fir.call @_QPbar_char(%[[castedBox]]) {{.*}}: (!fir.box<!fir.array<?x?x?x!fir.char<1,?>>>) -> ()48end subroutine49 50! CHECK-LABEL: func @_QPtest_vector_subcripted_section_to_box(51! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "v"},52! CHECK-SAME: %[[VAL_1:.*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x"}) {53subroutine test_vector_subcripted_section_to_box(v, x)54 ! Test that a copy is made when passing a vector subscripted variable to55 ! an assumed shape argument.56 interface57 subroutine takes_box(y)58 real :: y(:)59 end subroutine60 end interface61 integer :: v(:)62 real :: x(:)63 call takes_box(x(v))64! CHECK: %[[VAL_2:.*]] = arith.constant 1 : index65! CHECK: %[[VAL_3:.*]] = arith.constant 0 : index66! CHECK: %[[VAL_4:.*]]:3 = fir.box_dims %[[VAL_1]], %[[VAL_3]] : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)67! CHECK: %[[VAL_5:.*]] = arith.constant 0 : index68! CHECK: %[[VAL_6:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_5]] : (!fir.box<!fir.array<?xi32>>, index) -> (index, index, index)69! CHECK: %[[VAL_7:.*]] = fir.array_load %[[VAL_0]] : (!fir.box<!fir.array<?xi32>>) -> !fir.array<?xi32>70! CHECK: %[[VAL_8:.*]] = arith.cmpi sgt, %[[VAL_6]]#1, %[[VAL_4]]#1 : index71! CHECK: %[[VAL_9:.*]] = arith.select %[[VAL_8]], %[[VAL_4]]#1, %[[VAL_6]]#1 : index72! CHECK: %[[VAL_10:.*]] = fir.array_load %[[VAL_1]] : (!fir.box<!fir.array<?xf32>>) -> !fir.array<?xf32>73! CHECK: %[[VAL_11:.*]] = fir.allocmem !fir.array<?xf32>, %[[VAL_9]] {uniq_name = ".array.expr"}74! CHECK: %[[VAL_12:.*]] = fir.shape %[[VAL_9]] : (index) -> !fir.shape<1>75! CHECK: %[[VAL_13:.*]] = fir.array_load %[[VAL_11]](%[[VAL_12]]) : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.array<?xf32>76! CHECK: %[[VAL_14:.*]] = arith.constant 1 : index77! CHECK: %[[VAL_15:.*]] = arith.constant 0 : index78! CHECK: %[[VAL_16:.*]] = arith.subi %[[VAL_9]], %[[VAL_14]] : index79! CHECK: %[[VAL_17:.*]] = fir.do_loop %[[VAL_18:.*]] = %[[VAL_15]] to %[[VAL_16]] step %[[VAL_14]] unordered iter_args(%[[VAL_19:.*]] = %[[VAL_13]]) -> (!fir.array<?xf32>) {80! CHECK: %[[VAL_20:.*]] = fir.array_fetch %[[VAL_7]], %[[VAL_18]] : (!fir.array<?xi32>, index) -> i3281! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_20]] : (i32) -> index82! CHECK: %[[VAL_22:.*]] = arith.subi %[[VAL_21]], %[[VAL_2]] : index83! CHECK: %[[VAL_23:.*]] = fir.array_fetch %[[VAL_10]], %[[VAL_22]] : (!fir.array<?xf32>, index) -> f3284! CHECK: %[[VAL_24:.*]] = fir.array_update %[[VAL_19]], %[[VAL_23]], %[[VAL_18]] : (!fir.array<?xf32>, f32, index) -> !fir.array<?xf32>85! CHECK: fir.result %[[VAL_24]] : !fir.array<?xf32>86! CHECK: }87! CHECK: fir.array_merge_store %[[VAL_13]], %[[VAL_25:.*]] to %[[VAL_11]] : !fir.array<?xf32>, !fir.array<?xf32>, !fir.heap<!fir.array<?xf32>>88! CHECK: %[[VAL_26:.*]] = fir.shape %[[VAL_9]] : (index) -> !fir.shape<1>89! CHECK: %[[VAL_27:.*]] = fir.embox %[[VAL_11]](%[[VAL_26]]) : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>90! CHECK: fir.call @_QPtakes_box(%[[VAL_27]]) {{.*}}: (!fir.box<!fir.array<?xf32>>) -> ()91! CHECK: fir.freemem %[[VAL_11]] : !fir.heap<!fir.array<?xf32>>92end subroutine93 94! Test external function declarations95 96! CHECK: func private @_QPbar(!fir.box<!fir.array<?x?x?xf32>>)97! CHECK: func private @_QPbar_char(!fir.box<!fir.array<?x?x?x!fir.char<1,?>>>)98