Debian Codegraph @

flang/test/Lower/HLFIR/assumed-rank-calls.f90

raw
1 ! Test passing of assumed-ranks that require creating a
2 ! a new descriptor for the dummy argument (different lower bounds,
3 ! attribute, or dynamic type)
4 ! RUN: bbc -emit-hlfir -allow-assumed-rank -o - %s | FileCheck %s
5
6 subroutine test_alloc_to_nonalloc(x)
7 real, allocatable :: x(..)
8 interface
9 subroutine takes_assumed_rank(x)
10 real :: x(..)
11 end subroutine
12 end interface
13 call takes_assumed_rank(x)
14 end subroutine
15 ! CHECK-LABEL: func.func @_QPtest_alloc_to_nonalloc(
16 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>> {fir.bindc_name = "x"}) {
17 ! CHECK: %[[VAL_1:.*]] = fir.dummy_scope : !fir.dscope
18 ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %[[VAL_1]] {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtest_alloc_to_nonallocEx"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>)
19 ! CHECK: %[[VAL_3:.*]] = fir.load %[[VAL_2]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>
20 ! CHECK: %[[VAL_4:.*]] = fir.rebox_assumed_rank %[[VAL_3]] lbs ones : (!fir.box<!fir.heap<!fir.array<*:f32>>>) -> !fir.box<!fir.array<*:f32>>
21 ! CHECK: fir.call @_QPtakes_assumed_rank(%[[VAL_4]]) fastmath<contract> : (!fir.box<!fir.array<*:f32>>) -> ()
22 ! CHECK: return
23 ! CHECK: }
24
25 subroutine test_to_bindc(x)
26 real :: x(..)
27 interface
28 subroutine bindc_func(x) bind(c)
29 real :: x(..)
30 end subroutine
31 end interface
32 call bindc_func(x)
33 end subroutine
34 ! CHECK-LABEL: func.func @_QPtest_to_bindc(
35 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<*:f32>> {fir.bindc_name = "x"}) {
36 ! CHECK: %[[VAL_1:.*]] = fir.dummy_scope : !fir.dscope
37 ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %[[VAL_1]] {uniq_name = "_QFtest_to_bindcEx"} : (!fir.box<!fir.array<*:f32>>, !fir.dscope) -> (!fir.box<!fir.array<*:f32>>, !fir.box<!fir.array<*:f32>>)
38 ! CHECK: %[[VAL_3:.*]] = fir.rebox_assumed_rank %[[VAL_2]]#0 lbs zeroes : (!fir.box<!fir.array<*:f32>>) -> !fir.box<!fir.array<*:f32>>
39 ! CHECK: fir.call @bindc_func(%[[VAL_3]]) fastmath<contract> {is_bind_c} : (!fir.box<!fir.array<*:f32>>) -> ()
40 ! CHECK: return
41 ! CHECK: }
42
43 subroutine test_target_to_pointer(x)
44 real, target :: x(..)
45 interface
46 subroutine takes_target_as_pointer(x)
47 real, pointer, intent(in) :: x(..)
48 end subroutine
49 end interface
50 call takes_target_as_pointer(x)
51 end subroutine
52 ! CHECK-LABEL: func.func @_QPtest_target_to_pointer(
53 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<*:f32>> {fir.bindc_name = "x", fir.target}) {
54 ! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<*:f32>>>
55 ! CHECK: %[[VAL_2:.*]] = fir.dummy_scope : !fir.dscope
56 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %[[VAL_2]] {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFtest_target_to_pointerEx"} : (!fir.box<!fir.array<*:f32>>, !fir.dscope) -> (!fir.box<!fir.array<*:f32>>, !fir.box<!fir.array<*:f32>>)
57 ! CHECK: %[[VAL_4:.*]] = fir.rebox_assumed_rank %[[VAL_3]]#0 lbs preserve : (!fir.box<!fir.array<*:f32>>) -> !fir.box<!fir.ptr<!fir.array<*:f32>>>
58 ! CHECK: fir.store %[[VAL_4]] to %[[VAL_1]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<*:f32>>>>
59 ! CHECK: fir.call @_QPtakes_target_as_pointer(%[[VAL_1]]) fastmath<contract> : (!fir.ref<!fir.box<!fir.ptr<!fir.array<*:f32>>>>) -> ()
60
61 subroutine test_poly_to_nonepoly(x)
62 type t
63 integer :: i
64 end type
65 class(t) :: x(..)
66 interface
67 subroutine takes_assumed_rank_t(x)
68 import :: t
69 type(t) :: x(..)
70 end subroutine
71 end interface
72 call takes_assumed_rank_t(x)
73 end subroutine
74 ! CHECK-LABEL: func.func @_QPtest_poly_to_nonepoly(
75 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.class<!fir.array<*:!fir.type<_QFtest_poly_to_nonepolyTt{i:i32}>>> {fir.bindc_name = "x"}) {
76 ! CHECK: %[[VAL_1:.*]] = fir.dummy_scope : !fir.dscope
77 ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %[[VAL_1]] {uniq_name = "_QFtest_poly_to_nonepolyEx"} : (!fir.class<!fir.array<*:!fir.type<_QFtest_poly_to_nonepolyTt{i:i32}>>>, !fir.dscope) -> (!fir.class<!fir.array<*:!fir.type<_QFtest_poly_to_nonepolyTt{i:i32}>>>, !fir.class<!fir.array<*:!fir.type<_QFtest_poly_to_nonepolyTt{i:i32}>>>)
78 ! CHECK: %[[VAL_3:.*]] = fir.rebox_assumed_rank %[[VAL_2]]#0 lbs ones : (!fir.class<!fir.array<*:!fir.type<_QFtest_poly_to_nonepolyTt{i:i32}>>>) -> !fir.box<!fir.array<*:!fir.type<_QFtest_poly_to_nonepolyTt{i:i32}>>>
79 ! CHECK: fir.call @_QPtakes_assumed_rank_t(%[[VAL_3]]) fastmath<contract> : (!fir.box<!fir.array<*:!fir.type<_QFtest_poly_to_nonepolyTt{i:i32}>>>) -> ()
80 ! CHECK: return
81 ! CHECK: }
82
83
84 subroutine test_copy_in_out(x)
85 real :: x(..)
86 interface
87 subroutine takes_contiguous(x)
88 real, contiguous :: x(..)
89 end subroutine
90 end interface
91 call takes_contiguous(x)
92 end subroutine
93 ! CHECK-LABEL: func.func @_QPtest_copy_in_out(
94 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<*:f32>> {fir.bindc_name = "x"}) {
95 ! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<*:f32>>>
96 ! CHECK: %[[VAL_2:.*]] = fir.dummy_scope : !fir.dscope
97 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %[[VAL_2]] {uniq_name = "_QFtest_copy_in_outEx"} : (!fir.box<!fir.array<*:f32>>, !fir.dscope) -> (!fir.box<!fir.array<*:f32>>, !fir.box<!fir.array<*:f32>>)
98 ! CHECK: %[[VAL_4:.*]]:2 = hlfir.copy_in %[[VAL_3]]#0 to %[[VAL_1]] : (!fir.box<!fir.array<*:f32>>, !fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>) -> (!fir.box<!fir.array<*:f32>>, i1)
99 ! CHECK: fir.call @_QPtakes_contiguous(%[[VAL_4]]#0) fastmath<contract> : (!fir.box<!fir.array<*:f32>>) -> ()
100 ! CHECK: hlfir.copy_out %[[VAL_1]], %[[VAL_4]]#1 to %[[VAL_3]]#0 : (!fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>, i1, !fir.box<!fir.array<*:f32>>) -> ()
101
102 subroutine test_copy_in_out_2(x)
103 real :: x(..)
104 interface
105 subroutine takes_contiguous_intentin(x)
106 real, intent(in), contiguous :: x(..)
107 end subroutine
108 end interface
109 call takes_contiguous_intentin(x)
110 end subroutine
111 ! CHECK-LABEL: func.func @_QPtest_copy_in_out_2(
112 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<*:f32>> {fir.bindc_name = "x"}) {
113 ! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<*:f32>>>
114 ! CHECK: %[[VAL_2:.*]] = fir.dummy_scope : !fir.dscope
115 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %[[VAL_2]] {uniq_name = "_QFtest_copy_in_out_2Ex"} : (!fir.box<!fir.array<*:f32>>, !fir.dscope) -> (!fir.box<!fir.array<*:f32>>, !fir.box<!fir.array<*:f32>>)
116 ! CHECK: %[[VAL_4:.*]]:2 = hlfir.copy_in %[[VAL_3]]#0 to %[[VAL_1]] : (!fir.box<!fir.array<*:f32>>, !fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>) -> (!fir.box<!fir.array<*:f32>>, i1)
117 ! CHECK: fir.call @_QPtakes_contiguous_intentin(%[[VAL_4]]#0) fastmath<contract> : (!fir.box<!fir.array<*:f32>>) -> ()
118 ! CHECK: hlfir.copy_out %[[VAL_1]], %[[VAL_4]]#1 : (!fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>, i1) -> ()