1 ! Test passing pointers results to pointer dummy arguments
2 ! RUN: bbc -hlfir=false %s -o - | FileCheck %s
6 subroutine bar_scalar(x
)
10 real, pointer :: x(:, :)
12 function get_scalar_pointer()
13 real, pointer :: get_scalar_pointer
15 function get_pointer()
16 real, pointer :: get_pointer(:, :)
20 real, pointer :: xa(:, :)
23 ! CHECK-LABEL: test_scalar_null
24 subroutine test_scalar_null()
25 ! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.box<!fir.ptr<f32>>
26 ! CHECK: %[[VAL_1:.*]] = fir.zero_bits !fir.ptr<f32>
27 ! CHECK: %[[VAL_2:.*]] = fir.embox %[[VAL_1]] : (!fir.ptr<f32>) -> !fir.box<!fir.ptr<f32>>
28 ! CHECK: fir.store %[[VAL_2]] to %[[VAL_0]] : !fir.ref<!fir.box<!fir.ptr<f32>>>
29 ! CHECK: fir.call @_QPbar_scalar(%[[VAL_0]]) {{.*}}: (!fir.ref<!fir.box<!fir.ptr<f32>>>) -> ()
30 call bar_scalar(null())
33 ! CHECK-LABEL: test_scalar_null_mold
34 subroutine test_scalar_null_mold()
35 ! CHECK: %[[VAL_3:.*]] = fir.alloca !fir.box<!fir.ptr<f32>>
36 ! CHECK: %[[VAL_4:.*]] = fir.zero_bits !fir.ptr<f32>
37 ! CHECK: %[[VAL_5:.*]] = fir.embox %[[VAL_4]] : (!fir.ptr<f32>) -> !fir.box<!fir.ptr<f32>>
38 ! CHECK: fir.store %[[VAL_5]] to %[[VAL_3]] : !fir.ref<!fir.box<!fir.ptr<f32>>>
39 ! CHECK: fir.call @_QPbar_scalar(%[[VAL_3]]) {{.*}}: (!fir.ref<!fir.box<!fir.ptr<f32>>>) -> ()
40 call bar_scalar(null(x
))
43 ! CHECK-LABEL: test_scalar_result
44 subroutine test_scalar_result()
45 ! CHECK: %[[VAL_6:.*]] = fir.alloca !fir.box<!fir.ptr<f32>> {bindc_name = ".result"}
46 ! CHECK: %[[VAL_7:.*]] = fir.call @_QPget_scalar_pointer() {{.*}}: () -> !fir.box<!fir.ptr<f32>>
47 ! CHECK: fir.save_result %[[VAL_7]] to %[[VAL_6]] : !fir.box<!fir.ptr<f32>>, !fir.ref<!fir.box<!fir.ptr<f32>>>
48 ! CHECK: fir.call @_QPbar_scalar(%[[VAL_6]]) {{.*}}: (!fir.ref<!fir.box<!fir.ptr<f32>>>) -> ()
49 call bar_scalar(get_scalar_pointer())
52 ! CHECK-LABEL: test_null
53 subroutine test_null()
54 ! CHECK: %[[VAL_8:.*]] = arith.constant 0 : index
55 ! CHECK: %[[VAL_9:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?x?xf32>>>
56 ! CHECK: %[[VAL_10:.*]] = fir.zero_bits !fir.ptr<!fir.array<?x?xf32>>
57 ! CHECK: %[[VAL_11:.*]] = fir.shape %[[VAL_8]], %[[VAL_8]] : (index, index) -> !fir.shape<2>
58 ! CHECK: %[[VAL_12:.*]] = fir.embox %[[VAL_10]](%[[VAL_11]]) : (!fir.ptr<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.box<!fir.ptr<!fir.array<?x?xf32>>>
59 ! CHECK: fir.store %[[VAL_12]] to %[[VAL_9]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>
60 ! CHECK: fir.call @_QPbar(%[[VAL_9]]) {{.*}}: (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>) -> ()
64 ! CHECK-LABEL: test_null_mold
65 subroutine test_null_mold()
66 ! CHECK: %[[VAL_13:.*]] = arith.constant 0 : index
67 ! CHECK: %[[VAL_14:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?x?xf32>>>
68 ! CHECK: %[[VAL_15:.*]] = fir.zero_bits !fir.ptr<!fir.array<?x?xf32>>
69 ! CHECK: %[[VAL_16:.*]] = fir.shape %[[VAL_13]], %[[VAL_13]] : (index, index) -> !fir.shape<2>
70 ! CHECK: %[[VAL_17:.*]] = fir.embox %[[VAL_15]](%[[VAL_16]]) : (!fir.ptr<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.box<!fir.ptr<!fir.array<?x?xf32>>>
71 ! CHECK: fir.store %[[VAL_17]] to %[[VAL_14]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>
72 ! CHECK: fir.call @_QPbar(%[[VAL_14]]) {{.*}}: (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>) -> ()
76 ! CHECK-LABEL: test_result
77 subroutine test_result()
78 ! CHECK: %[[VAL_18:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?x?xf32>>> {bindc_name = ".result"}
79 ! CHECK: %[[VAL_19:.*]] = fir.call @_QPget_pointer() {{.*}}: () -> !fir.box<!fir.ptr<!fir.array<?x?xf32>>>
80 ! CHECK: fir.save_result %[[VAL_19]] to %[[VAL_18]] : !fir.box<!fir.ptr<!fir.array<?x?xf32>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>
81 ! CHECK: fir.call @_QPbar(%[[VAL_18]]) {{.*}}: (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>) -> ()
82 call bar(get_pointer())