1 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
5 ! CHECK-LABEL: func @_QMmax_testPdynamic_optional(
6 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "a"},
7 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "b"},
8 ! CHECK-SAME: %[[VAL_2:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "c", fir.optional}) {
9 subroutine dynamic_optional(a
, b
, c
)
11 integer, optional
:: c(:)
12 ! CHECK: %[[VAL_10:.*]] = fir.array_load %[[VAL_0]] : (!fir.box<!fir.array<?xi32>>) -> !fir.array<?xi32>
13 ! CHECK: %[[VAL_11:.*]] = fir.array_load %[[VAL_1]] : (!fir.box<!fir.array<?xi32>>) -> !fir.array<?xi32>
14 ! CHECK: %[[VAL_12:.*]] = fir.is_present %[[VAL_2]] : (!fir.box<!fir.array<?xi32>>) -> i1
15 ! CHECK: %[[VAL_17:.*]] = arith.select %[[VAL_12]], %[[VAL_2]], %{{.*}} : !fir.box<!fir.array<?xi32>>
16 ! CHECK: %[[VAL_18:.*]] = fir.array_load %[[VAL_17]] {fir.optional} : (!fir.box<!fir.array<?xi32>>) -> !fir.array<?xi32>
17 ! CHECK: fir.do_loop %[[VAL_26:.*]] = %{{.*}} to %{{.*}} step %{{.*}} unordered iter_args(%[[VAL_27:.*]] = %{{.*}}) -> (!fir.array<?xi32>) {
18 ! CHECK: %[[VAL_28:.*]] = fir.array_fetch %[[VAL_10]], %[[VAL_26]] : (!fir.array<?xi32>, index) -> i32
19 ! CHECK: %[[VAL_29:.*]] = fir.array_fetch %[[VAL_11]], %[[VAL_26]] : (!fir.array<?xi32>, index) -> i32
20 ! CHECK: %[[VAL_30:.*]] = arith.cmpi sgt, %[[VAL_28]], %[[VAL_29]] : i32
21 ! CHECK: %[[VAL_31:.*]] = arith.select %[[VAL_30]], %[[VAL_28]], %[[VAL_29]] : i32
22 ! CHECK: %[[VAL_32:.*]] = fir.if %[[VAL_12]] -> (i32) {
23 ! CHECK: %[[VAL_33:.*]] = fir.array_fetch %[[VAL_18]], %[[VAL_26]] : (!fir.array<?xi32>, index) -> i32
24 ! CHECK: %[[VAL_34:.*]] = arith.cmpi sgt, %[[VAL_31]], %[[VAL_33]] : i32
25 ! CHECK: %[[VAL_35:.*]] = arith.select %[[VAL_34]], %[[VAL_31]], %[[VAL_33]] : i32
26 ! CHECK: fir.result %[[VAL_35]] : i32
28 ! CHECK: fir.result %[[VAL_31]] : i32
30 ! CHECK: %[[VAL_36:.*]] = fir.array_update %[[VAL_27]], %[[VAL_32]], %[[VAL_26]] : (!fir.array<?xi32>, i32, index) -> !fir.array<?xi32>
31 ! CHECK: fir.result %[[VAL_36]] : !fir.array<?xi32>
36 ! CHECK-LABEL: func @_QMmax_testPdynamic_optional_array_expr_scalar_optional(
37 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "a"},
38 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "b"},
39 ! CHECK-SAME: %[[VAL_2:.*]]: !fir.ref<i32> {fir.bindc_name = "c", fir.optional}) {
40 subroutine dynamic_optional_array_expr_scalar_optional(a
, b
, c
)
42 integer, optional
:: c
44 ! CHECK: %[[VAL_10:.*]] = fir.array_load %[[VAL_0]] : (!fir.box<!fir.array<?xi32>>) -> !fir.array<?xi32>
45 ! CHECK: %[[VAL_11:.*]] = fir.array_load %[[VAL_1]] : (!fir.box<!fir.array<?xi32>>) -> !fir.array<?xi32>
46 ! CHECK: %[[VAL_12:.*]] = fir.is_present %[[VAL_2]] : (!fir.ref<i32>) -> i1
47 ! CHECK: fir.do_loop %[[VAL_20:.*]] = %{{.*}} to %{{.*}} step %{{.*}} unordered iter_args(%[[VAL_21:.*]] = %{{.*}}) -> (!fir.array<?xi32>) {
48 ! CHECK: %[[VAL_22:.*]] = fir.array_fetch %[[VAL_10]], %[[VAL_20]] : (!fir.array<?xi32>, index) -> i32
49 ! CHECK: %[[VAL_23:.*]] = fir.array_fetch %[[VAL_11]], %[[VAL_20]] : (!fir.array<?xi32>, index) -> i32
50 ! CHECK: %[[VAL_24:.*]] = arith.cmpi sgt, %[[VAL_22]], %[[VAL_23]] : i32
51 ! CHECK: %[[VAL_25:.*]] = arith.select %[[VAL_24]], %[[VAL_22]], %[[VAL_23]] : i32
52 ! CHECK: %[[VAL_26:.*]] = fir.if %[[VAL_12]] -> (i32) {
53 ! CHECK: %[[VAL_27:.*]] = fir.load %[[VAL_2]] : !fir.ref<i32>
54 ! CHECK: %[[VAL_28:.*]] = arith.cmpi sgt, %[[VAL_25]], %[[VAL_27]] : i32
55 ! CHECK: %[[VAL_29:.*]] = arith.select %[[VAL_28]], %[[VAL_25]], %[[VAL_27]] : i32
56 ! CHECK: fir.result %[[VAL_29]] : i32
58 ! CHECK: fir.result %[[VAL_25]] : i32
60 ! CHECK: %[[VAL_30:.*]] = fir.array_update %[[VAL_21]], %[[VAL_26]], %[[VAL_20]] : (!fir.array<?xi32>, i32, index) -> !fir.array<?xi32>
61 ! CHECK: fir.result %[[VAL_30]] : !fir.array<?xi32>
65 ! CHECK-LABEL: func @_QMmax_testPdynamic_optional_scalar(
66 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32> {fir.bindc_name = "a"},
67 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i32> {fir.bindc_name = "b"},
68 ! CHECK-SAME: %[[VAL_2:.*]]: !fir.ref<i32> {fir.bindc_name = "c", fir.optional}) {
69 subroutine dynamic_optional_scalar(a
, b
, c
)
71 integer, optional
:: c
73 ! CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_0]] : !fir.ref<i32>
74 ! CHECK: %[[VAL_9:.*]] = fir.load %[[VAL_1]] : !fir.ref<i32>
75 ! CHECK: %[[VAL_10:.*]] = fir.is_present %[[VAL_2]] : (!fir.ref<i32>) -> i1
76 ! CHECK: %[[VAL_11:.*]] = arith.cmpi sgt, %[[VAL_8]], %[[VAL_9]] : i32
77 ! CHECK: %[[VAL_12:.*]] = arith.select %[[VAL_11]], %[[VAL_8]], %[[VAL_9]] : i32
78 ! CHECK: %[[VAL_13:.*]] = fir.if %[[VAL_10]] -> (i32) {
79 ! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_2]] : !fir.ref<i32>
80 ! CHECK: %[[VAL_15:.*]] = arith.cmpi sgt, %[[VAL_12]], %[[VAL_14]] : i32
81 ! CHECK: %[[VAL_16:.*]] = arith.select %[[VAL_15]], %[[VAL_12]], %[[VAL_14]] : i32
82 ! CHECK: fir.result %[[VAL_16]] : i32
84 ! CHECK: fir.result %[[VAL_12]] : i32
86 ! CHECK: fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[VAL_13]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
89 ! CHECK-LABEL: func @_QMmax_testPdynamic_optional_weird(
90 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32> {fir.bindc_name = "a"},
91 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i32> {fir.bindc_name = "b"},
92 ! CHECK-SAME: %[[VAL_2:.*]]: !fir.ref<i32> {fir.bindc_name = "c", fir.optional},
93 ! CHECK-SAME: %[[VAL_3:.*]]: !fir.ref<i32> {fir.bindc_name = "d"},
94 ! CHECK-SAME: %[[VAL_4:.*]]: !fir.ref<i32> {fir.bindc_name = "e", fir.optional}) {
95 subroutine dynamic_optional_weird(a
, b
, c
, d
, e
)
97 integer, optional
:: c
, e
98 ! a3, a4, a6, a8 statically missing. a5, a9 dynamically optional.
99 print *, max(a1
=a
, a2
=b
, a5
=c
, a7
=d
, a9
= e
)
100 ! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_0]] : !fir.ref<i32>
101 ! CHECK: %[[VAL_11:.*]] = fir.load %[[VAL_1]] : !fir.ref<i32>
102 ! CHECK: %[[VAL_12:.*]] = fir.is_present %[[VAL_2]] : (!fir.ref<i32>) -> i1
103 ! CHECK: %[[VAL_13:.*]] = fir.load %[[VAL_3]] : !fir.ref<i32>
104 ! CHECK: %[[VAL_14:.*]] = fir.is_present %[[VAL_4]] : (!fir.ref<i32>) -> i1
105 ! CHECK: %[[VAL_15:.*]] = arith.cmpi sgt, %[[VAL_10]], %[[VAL_11]] : i32
106 ! CHECK: %[[VAL_16:.*]] = arith.select %[[VAL_15]], %[[VAL_10]], %[[VAL_11]] : i32
107 ! CHECK: %[[VAL_17:.*]] = fir.if %[[VAL_12]] -> (i32) {
108 ! CHECK: %[[VAL_18:.*]] = fir.load %[[VAL_2]] : !fir.ref<i32>
109 ! CHECK: %[[VAL_19:.*]] = arith.cmpi sgt, %[[VAL_16]], %[[VAL_18]] : i32
110 ! CHECK: %[[VAL_20:.*]] = arith.select %[[VAL_19]], %[[VAL_16]], %[[VAL_18]] : i32
111 ! CHECK: fir.result %[[VAL_20]] : i32
113 ! CHECK: fir.result %[[VAL_16]] : i32
115 ! CHECK: %[[VAL_21:.*]] = arith.cmpi sgt, %[[VAL_17]], %[[VAL_13]] : i32
116 ! CHECK: %[[VAL_23:.*]] = arith.select %[[VAL_21]], %[[VAL_17]], %[[VAL_13]] : i32
117 ! CHECK: %[[VAL_24:.*]] = fir.if %[[VAL_14]] -> (i32) {
118 ! CHECK: %[[VAL_25:.*]] = fir.load %[[VAL_4]] : !fir.ref<i32>
119 ! CHECK: %[[VAL_26:.*]] = arith.cmpi sgt, %[[VAL_23]], %[[VAL_25]] : i32
120 ! CHECK: %[[VAL_27:.*]] = arith.select %[[VAL_26]], %[[VAL_23]], %[[VAL_25]] : i32
121 ! CHECK: fir.result %[[VAL_27]] : i32
123 ! CHECK: fir.result %[[VAL_23]] : i32
125 ! CHECK: fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[VAL_24]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
130 integer :: a(4) = [1,12,23, 34]
131 integer :: b(4) = [31,22,13, 4]
132 integer :: c(4) = [21,32,3, 14]
133 call dynamic_optional(a
, b
)
134 call dynamic_optional(a
, b
, c
)
135 call dynamic_optional_array_expr_scalar_optional(a
, b
)
136 call dynamic_optional_array_expr_scalar_optional(a
, b
, c(2))
137 call dynamic_optional_scalar(a(2), b(2))
138 call dynamic_optional_scalar(a(2), b(2), c(2))