| 1 |
! Test lowering of NOPASS procedure pointers components. |
| 2 |
! RUN: bbc -emit-hlfir -o - %s | FileCheck %s |
| 3 |
|
| 4 |
module proc_comp_defs |
| 5 |
interface |
| 6 |
real function iface(x) |
| 7 |
real :: x |
| 8 |
end function |
| 9 |
subroutine takes_proc_pointer(p) |
| 10 |
import iface |
| 11 |
procedure(iface), pointer :: p |
| 12 |
end subroutine |
| 13 |
end interface |
| 14 |
type t |
| 15 |
integer :: j |
| 16 |
procedure(iface), nopass, pointer :: p |
| 17 |
end type |
| 18 |
end module |
| 19 |
|
| 20 |
real function test1(x) |
| 21 |
use proc_comp_defs, only : t |
| 22 |
type(t) :: x |
| 23 |
test1 = x%p(42.) |
| 24 |
end function |
| 25 |
! CHECK-LABEL: func.func @_QPtest1( |
| 26 |
! CHECK: %[[VAL_1:.*]] = fir.alloca f32 {bindc_name = "test1", uniq_name = "_QFtest1Etest1"} |
| 27 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_1:[a-z0-9]*]] {{.*}}Etest1 |
| 28 |
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ex |
| 29 |
! CHECK: %[[VAL_4:.*]] = arith.constant 4.200000e+01 : f32 |
| 30 |
! CHECK: %[[VAL_5:.*]]:3 = hlfir.associate %[[VAL_4]] {adapt.valuebyref} : (f32) -> (!fir.ref<f32>, !fir.ref<f32>, i1) |
| 31 |
! CHECK: %[[VAL_6:.*]] = hlfir.designate %[[VAL_3]]#1{"p"} {fortran_attrs = #fir.var_attrs<pointer>} : (!fir.ref<!fir.type<_QMproc_comp_defsTt{j:i32,p:!fir.boxproc<(!fir.ref<f32>) -> f32>}>>) -> !fir.ref<!fir.boxproc<(!fir.ref<f32>) -> f32>> |
| 32 |
! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_6]] : !fir.ref<!fir.boxproc<(!fir.ref<f32>) -> f32>> |
| 33 |
! CHECK: %[[VAL_8:.*]] = fir.box_addr %[[VAL_7]] : (!fir.boxproc<(!fir.ref<f32>) -> f32>) -> ((!fir.ref<f32>) -> f32) |
| 34 |
! CHECK: %[[VAL_9:.*]] = fir.call %[[VAL_8]](%[[VAL_5]]#1) fastmath<contract> : (!fir.ref<f32>) -> f32 |
| 35 |
! CHECK: hlfir.end_associate %[[VAL_5]]#1, %[[VAL_5]]#2 : !fir.ref<f32>, i1 |
| 36 |
! CHECK: hlfir.assign %[[VAL_9]] to %[[VAL_2]]#0 : f32, !fir.ref<f32> |
| 37 |
|
| 38 |
subroutine test2(x) |
| 39 |
use proc_comp_defs, only : t, iface |
| 40 |
type(t) :: x |
| 41 |
procedure(iface) :: ptarget |
| 42 |
x%p => ptarget |
| 43 |
end subroutine |
| 44 |
! CHECK-LABEL: func.func @_QPtest2( |
| 45 |
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ex |
| 46 |
! CHECK: %[[VAL_2:.*]] = hlfir.designate %[[VAL_1]]#1{"p"} {fortran_attrs = #fir.var_attrs<pointer>} : (!fir.ref<!fir.type<_QMproc_comp_defsTt{j:i32,p:!fir.boxproc<(!fir.ref<f32>) -> f32>}>>) -> !fir.ref<!fir.boxproc<(!fir.ref<f32>) -> f32>> |
| 47 |
! CHECK: %[[VAL_3:.*]] = fir.address_of(@_QPptarget) : (!fir.ref<f32>) -> f32 |
| 48 |
! CHECK: %[[VAL_4:.*]] = fir.emboxproc %[[VAL_3]] : ((!fir.ref<f32>) -> f32) -> !fir.boxproc<() -> ()> |
| 49 |
! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (!fir.boxproc<() -> ()>) -> !fir.boxproc<(!fir.ref<f32>) -> f32> |
| 50 |
! CHECK: fir.store %[[VAL_5]] to %[[VAL_2]] : !fir.ref<!fir.boxproc<(!fir.ref<f32>) -> f32>> |
| 51 |
|
| 52 |
subroutine test3(x) |
| 53 |
use proc_comp_defs, only : t |
| 54 |
type(t) :: x |
| 55 |
x%p => null() |
| 56 |
end subroutine |
| 57 |
! CHECK-LABEL: func.func @_QPtest3( |
| 58 |
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ex |
| 59 |
! CHECK: %[[VAL_2:.*]] = hlfir.designate %[[VAL_1]]#1{"p"} {fortran_attrs = #fir.var_attrs<pointer>} : (!fir.ref<!fir.type<_QMproc_comp_defsTt{j:i32,p:!fir.boxproc<(!fir.ref<f32>) -> f32>}>>) -> !fir.ref<!fir.boxproc<(!fir.ref<f32>) -> f32>> |
| 60 |
! CHECK: %[[VAL_3:.*]] = fir.zero_bits () -> () |
| 61 |
! CHECK: %[[VAL_4:.*]] = fir.emboxproc %[[VAL_3]] : (() -> ()) -> !fir.boxproc<() -> ()> |
| 62 |
! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (!fir.boxproc<() -> ()>) -> !fir.boxproc<(!fir.ref<f32>) -> f32> |
| 63 |
! CHECK: fir.store %[[VAL_5]] to %[[VAL_2]] : !fir.ref<!fir.boxproc<(!fir.ref<f32>) -> f32>> |
| 64 |
|
| 65 |
subroutine test4(x) |
| 66 |
use proc_comp_defs, only : t |
| 67 |
type(t) :: x |
| 68 |
x%p => x%p |
| 69 |
end subroutine |
| 70 |
! CHECK-LABEL: func.func @_QPtest4( |
| 71 |
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ex |
| 72 |
! CHECK: %[[VAL_2:.*]] = hlfir.designate %[[VAL_1]]#1{"p"} {fortran_attrs = #fir.var_attrs<pointer>} : (!fir.ref<!fir.type<_QMproc_comp_defsTt{j:i32,p:!fir.boxproc<(!fir.ref<f32>) -> f32>}>>) -> !fir.ref<!fir.boxproc<(!fir.ref<f32>) -> f32>> |
| 73 |
! CHECK: %[[VAL_3:.*]] = hlfir.designate %[[VAL_1]]#1{"p"} {fortran_attrs = #fir.var_attrs<pointer>} : (!fir.ref<!fir.type<_QMproc_comp_defsTt{j:i32,p:!fir.boxproc<(!fir.ref<f32>) -> f32>}>>) -> !fir.ref<!fir.boxproc<(!fir.ref<f32>) -> f32>> |
| 74 |
! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]] : !fir.ref<!fir.boxproc<(!fir.ref<f32>) -> f32>> |
| 75 |
! CHECK: fir.store %[[VAL_4]] to %[[VAL_2]] : !fir.ref<!fir.boxproc<(!fir.ref<f32>) -> f32>> |
| 76 |
|
| 77 |
subroutine test5(x) |
| 78 |
use proc_comp_defs, only : t, takes_proc_pointer |
| 79 |
type(t) :: x |
| 80 |
call takes_proc_pointer(x%p) |
| 81 |
end subroutine |
| 82 |
! CHECK-LABEL: func.func @_QPtest5( |
| 83 |
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ex |
| 84 |
! CHECK: %[[VAL_2:.*]] = hlfir.designate %[[VAL_1]]#1{"p"} {fortran_attrs = #fir.var_attrs<pointer>} : (!fir.ref<!fir.type<_QMproc_comp_defsTt{j:i32,p:!fir.boxproc<(!fir.ref<f32>) -> f32>}>>) -> !fir.ref<!fir.boxproc<(!fir.ref<f32>) -> f32>> |
| 85 |
! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.ref<!fir.boxproc<(!fir.ref<f32>) -> f32>>) -> !fir.ref<!fir.boxproc<() -> ()>> |
| 86 |
! CHECK: fir.call @_QPtakes_proc_pointer(%[[VAL_3]]) fastmath<contract> : (!fir.ref<!fir.boxproc<() -> ()>>) -> () |
| 87 |
|
| 88 |
subroutine test6(x) |
| 89 |
use proc_comp_defs, only : t |
| 90 |
type(t) :: x |
| 91 |
nullify(x%p) |
| 92 |
end subroutine |
| 93 |
! CHECK-LABEL: func.func @_QPtest6( |
| 94 |
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ex |
| 95 |
! CHECK: %[[VAL_2:.*]] = hlfir.designate %[[VAL_1]]#1{"p"} {fortran_attrs = #fir.var_attrs<pointer>} : (!fir.ref<!fir.type<_QMproc_comp_defsTt{j:i32,p:!fir.boxproc<(!fir.ref<f32>) -> f32>}>>) -> !fir.ref<!fir.boxproc<(!fir.ref<f32>) -> f32>> |
| 96 |
! CHECK: %[[VAL_3:.*]] = fir.zero_bits () -> () |
| 97 |
! CHECK: %[[VAL_4:.*]] = fir.emboxproc %[[VAL_3]] : (() -> ()) -> !fir.boxproc<() -> ()> |
| 98 |
! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (!fir.boxproc<() -> ()>) -> !fir.boxproc<(!fir.ref<f32>) -> f32> |
| 99 |
! CHECK: fir.store %[[VAL_5]] to %[[VAL_2]] : !fir.ref<!fir.boxproc<(!fir.ref<f32>) -> f32>> |
| 100 |
|
| 101 |
subroutine test7(x, y) |
| 102 |
use proc_comp_defs, only : t |
| 103 |
type(t) :: x, y |
| 104 |
x = y |
| 105 |
end subroutine |
| 106 |
! CHECK-LABEL: func.func @_QPtest7( |
| 107 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ex |
| 108 |
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_1:[a-z0-9]*]] {{.*}}Ey |
| 109 |
! CHECK: hlfir.assign %[[VAL_3]]#0 to %[[VAL_2]]#0 : !fir.ref<!fir.type<_QMproc_comp_defsTt{j:i32,p:!fir.boxproc<(!fir.ref<f32>) -> f32>}>>, !fir.ref<!fir.type<_QMproc_comp_defsTt{j:i32,p:!fir.boxproc<(!fir.ref<f32>) -> f32>}>> |
| 110 |
|
| 111 |
subroutine test8(x, y) |
| 112 |
use proc_comp_defs, only : t |
| 113 |
type(t) :: x(10), y(10) |
| 114 |
x = y |
| 115 |
end subroutine |
| 116 |
! CHECK-LABEL: func.func @_QPtest8( |
| 117 |
! CHECK: %[[VAL_2:.*]] = arith.constant 10 : index |
| 118 |
! CHECK: %[[VAL_3:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1> |
| 119 |
! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]](%[[VAL_3:[a-z0-9]*]]) {{.*}}Ex |
| 120 |
! CHECK: %[[VAL_5:.*]] = arith.constant 10 : index |
| 121 |
! CHECK: %[[VAL_6:.*]] = fir.shape %[[VAL_5]] : (index) -> !fir.shape<1> |
| 122 |
! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_1:[a-z0-9]*]](%[[VAL_6:[a-z0-9]*]]) {{.*}}Ey |
| 123 |
! CHECK: hlfir.assign %[[VAL_7]]#0 to %[[VAL_4]]#0 : !fir.ref<!fir.array<10x!fir.type<_QMproc_comp_defsTt{j:i32,p:!fir.boxproc<(!fir.ref<f32>) -> f32>}>>>, !fir.ref<!fir.array<10x!fir.type<_QMproc_comp_defsTt{j:i32,p:!fir.boxproc<(!fir.ref<f32>) -> f32>}>>> |