85 lines · plain
1! Test for PassBy::BaseAddressValueAttribute2! RUN: bbc -emit-hlfir %s -o - | FileCheck %s3 4!CHECK-LABEL: func @_QQmain()5program call_by_value_attr6 interface7 subroutine subri(val)8 integer, value :: val9 end subroutine subri10 subroutine subra(val)11 integer, value, dimension(10) :: val12 end subroutine subra13 end interface14 15 integer :: v16 integer, dimension(10) :: a17 integer, dimension(15) :: b18 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare{{.*}}a"19 ! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare{{.*}}b"20 ! CHECK: %[[VAL_9:.*]]:2 = hlfir.declare{{.*}}v"21 v = 1722 call subri(v)23 ! CHECK: %[[VAL_11:.*]] = fir.load %[[VAL_9]]#0 : !fir.ref<i32>24 ! CHECK: fir.call @_QPsubri(%[[VAL_11]]) fastmath<contract> : (i32) -> ()25 a = (/ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 /)26 call subra(a)27 ! CHECK: %[[VAL_16:.*]] = hlfir.as_expr %[[VAL_3]]#0 : (!fir.ref<!fir.array<10xi32>>) -> !hlfir.expr<10xi32>28 ! CHECK: %[[VAL_17:.*]]:3 = hlfir.associate %[[VAL_16]](%{{.*}}) {adapt.valuebyref} : (!hlfir.expr<10xi32>, !fir.shape<1>) -> (!fir.ref<!fir.array<10xi32>>, !fir.ref<!fir.array<10xi32>>, i1)29 ! CHECK: fir.call @_QPsubra(%[[VAL_17]]#0) fastmath<contract> : (!fir.ref<!fir.array<10xi32>>) -> ()30 31 b = (/ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 /)32 call subra(b(5:14))33 ! CHECK: %[[VAL_27:.*]] = hlfir.designate %[[VAL_7]]#034 ! CHECK: %[[VAL_28:.*]] = hlfir.as_expr %[[VAL_27]] : (!fir.ref<!fir.array<10xi32>>) -> !hlfir.expr<10xi32>35 ! CHECK: %[[VAL_29:.*]]:3 = hlfir.associate %[[VAL_28]](%{{.*}}) {adapt.valuebyref} : (!hlfir.expr<10xi32>, !fir.shape<1>) -> (!fir.ref<!fir.array<10xi32>>, !fir.ref<!fir.array<10xi32>>, i1)36 ! CHECK: fir.call @_QPsubra(%[[VAL_29]]#0) fastmath<contract> : (!fir.ref<!fir.array<10xi32>>) -> ()37end program call_by_value_attr38 39subroutine subri(val)40 integer, value :: val41 call test_numeric_scalar_value(val)42end subroutine subri43! CHECK-LABEL: func.func @_QPsubri(44! CHECK-SAME: %[[VAL_0:.*]]: i32 {fir.bindc_name = "val"}) {45! CHECK: %[[VAL_1:.*]] = fir.dummy_scope : !fir.dscope46! CHECK: %[[VAL_2:.*]] = fir.alloca i3247! CHECK: fir.store %[[VAL_0]] to %[[VAL_2]] : !fir.ref<i32>48! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_2]] dummy_scope %[[VAL_1]] arg {{[0-9]+}} {fortran_attrs = #fir.var_attrs<value>, uniq_name = "_QFsubriEval"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)49! CHECK: fir.call @_QPtest_numeric_scalar_value(%[[VAL_3]]#0) fastmath<contract> : (!fir.ref<i32>) -> ()50! CHECK: return51! CHECK: }52 53! CHECK-LABEL: func @_QPtest_litteral_copies_154subroutine test_litteral_copies_155 ! VALUE arguments can be modified by the callee, so the static storage of56 ! literal constants and named parameters must not be passed directly to them.57 interface58 subroutine takes_array_value(v)59 integer, value :: v(4)60 end subroutine61 end interface62 integer, parameter :: p(100) = 4263 call takes_array_value(p)64 ! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare {{.*}}"_QQro.100xi4.2"65 ! CHECK: %[[VAL_8:.*]] = hlfir.as_expr %[[VAL_7]]#0 : (!fir.ref<!fir.array<100xi32>>) -> !hlfir.expr<100xi32>66 ! CHECK: %[[VAL_9:.*]]:3 = hlfir.associate %[[VAL_8]](%{{.*}}) {adapt.valuebyref} : (!hlfir.expr<100xi32>, !fir.shape<1>) -> (!fir.ref<!fir.array<100xi32>>, !fir.ref<!fir.array<100xi32>>, i1)67 ! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_9]]#0 : (!fir.ref<!fir.array<100xi32>>) -> !fir.ref<!fir.array<4xi32>>68 ! CHECK: fir.call @_QPtakes_array_value(%[[VAL_10]]) fastmath<contract> : (!fir.ref<!fir.array<4xi32>>) -> ()69end subroutine70 71! CHECK-LABEL: func @_QPtest_litteral_copies_272subroutine test_litteral_copies_273 interface74 subroutine takes_char_value(v)75 character(*), value :: v76 end subroutine77 end interface78 call takes_char_value("a character string litteral that could be locally modfied by the callee")79 ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare {{.*}}"_QQcl80 ! CHECK: %[[VAL_3:.*]] = hlfir.as_expr %[[VAL_2]]#0 : (!fir.ref<!fir.char<1,71>>) -> !hlfir.expr<!fir.char<1,71>>81 ! CHECK: %[[VAL_4:.*]]:3 = hlfir.associate %[[VAL_3]] typeparams %{{.*}} {adapt.valuebyref} : (!hlfir.expr<!fir.char<1,71>>, index) -> (!fir.ref<!fir.char<1,71>>, !fir.ref<!fir.char<1,71>>, i1)82 ! CHECK: %[[VAL_5:.*]] = fir.emboxchar %[[VAL_4]]#0, %{{.*}} : (!fir.ref<!fir.char<1,71>>, index) -> !fir.boxchar<1>83 ! CHECK: fir.call @_QPtakes_char_value(%[[VAL_5]]) fastmath<contract> : (!fir.boxchar<1>) -> ()84end subroutine85