| 1 |
! Test lowering of derived types passed with VALUE attribute in BIND(C) |
| 2 |
! interface. They are passed as fir.type<T> value. The actual C struct |
| 3 |
! passing ABI is done in code generation according to the target. |
| 4 |
|
| 5 |
! RUN: bbc -emit-hlfir -o - -I nw %s 2>&1 | FileCheck %s |
| 6 |
|
| 7 |
module bindc_byval |
| 8 |
type, bind(c) :: t |
| 9 |
integer :: i |
| 10 |
end type |
| 11 |
contains |
| 12 |
subroutine test(x) bind(c) |
| 13 |
type(t), value :: x |
| 14 |
call use_it(x%i) |
| 15 |
end subroutine |
| 16 |
! CHECK-LABEL: func.func @test( |
| 17 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.type<_QMbindc_byvalTt{i:i32}> {fir.bindc_name = "x"}) attributes {fir.bindc_name = "test"} { |
| 18 |
! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.type<_QMbindc_byvalTt{i:i32}> |
| 19 |
! CHECK: fir.store %[[VAL_0]] to %[[VAL_1]] : !fir.ref<!fir.type<_QMbindc_byvalTt{i:i32}>> |
| 20 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_1]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<value>, uniq_name = "_QMbindc_byvalFtestEx"} : (!fir.ref<!fir.type<_QMbindc_byvalTt{i:i32}>>, !fir.dscope) -> (!fir.ref<!fir.type<_QMbindc_byvalTt{i:i32}>>, !fir.ref<!fir.type<_QMbindc_byvalTt{i:i32}>>) |
| 21 |
! CHECK: %[[VAL_3:.*]] = hlfir.designate %[[VAL_2]]#0{"i"} : (!fir.ref<!fir.type<_QMbindc_byvalTt{i:i32}>>) -> !fir.ref<i32> |
| 22 |
! CHECK: fir.call @_QPuse_it(%[[VAL_3]]) fastmath<contract> : (!fir.ref<i32>) -> () |
| 23 |
! CHECK: return |
| 24 |
! CHECK: } |
| 25 |
|
| 26 |
subroutine call_it(x) |
| 27 |
type(t) x |
| 28 |
call test(x) |
| 29 |
end subroutine |
| 30 |
! CHECK-LABEL: func.func @_QMbindc_byvalPcall_it( |
| 31 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<_QMbindc_byvalTt{i:i32}>> {fir.bindc_name = "x"}) { |
| 32 |
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMbindc_byvalFcall_itEx"} : (!fir.ref<!fir.type<_QMbindc_byvalTt{i:i32}>>, !fir.dscope) -> (!fir.ref<!fir.type<_QMbindc_byvalTt{i:i32}>>, !fir.ref<!fir.type<_QMbindc_byvalTt{i:i32}>>) |
| 33 |
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_1]]#1 : !fir.ref<!fir.type<_QMbindc_byvalTt{i:i32}>> |
| 34 |
! CHECK: fir.call @test(%[[VAL_2]]) fastmath<contract> {is_bind_c} : (!fir.type<_QMbindc_byvalTt{i:i32}>) -> () |
| 35 |
! CHECK: return |
| 36 |
! CHECK: } |
| 37 |
end module |