1 // RUN: fir-opt --fir-polymorphic-op %s | FileCheck %s
3 // Test that cf.br for the default select case passes the blocks argument
10 // class(*),pointer :: fstar
17 // select type(y=>fstar())
25 // select type(y=>fstar())
34 // CHECK-LABEL: func.func @_QPtest() {
35 // CHECK: %[[VAL_0:.*]] = arith.constant 23 : i32
36 // CHECK: %[[VAL_1:.*]] = arith.constant false
37 // CHECK: %[[VAL_2:.*]] = arith.constant 9 : index
38 // CHECK: %[[VAL_3:.*]] = arith.constant 777 : i32
39 // CHECK: %[[VAL_4:.*]] = fir.alloca !fir.class<!fir.ptr<none>> {bindc_name = ".result"}
40 // CHECK: %[[VAL_5:.*]] = fir.alloca !fir.class<!fir.ptr<none>> {bindc_name = ".result"}
41 // CHECK: %[[VAL_6:.*]] = fir.call @_QPfstar() fastmath<contract> : () -> !fir.class<!fir.ptr<none>>
42 // CHECK: fir.save_result %[[VAL_6]] to %[[VAL_5]] : !fir.class<!fir.ptr<none>>, !fir.ref<!fir.class<!fir.ptr<none>>>
43 // CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_5]] : !fir.ref<!fir.class<!fir.ptr<none>>>
44 // CHECK: %[[VAL_8:.*]] = arith.constant 9 : i8
45 // CHECK: %[[VAL_9:.*]] = fir.box_typecode %[[VAL_7]] : (!fir.class<!fir.ptr<none>>) -> i8
46 // CHECK: %[[VAL_10:.*]] = arith.cmpi eq, %[[VAL_9]], %[[VAL_8]] : i8
47 // CHECK: cf.cond_br %[[VAL_10]], ^bb2, ^bb1
49 // CHECK: cf.br ^bb3(%[[VAL_7]] : !fir.class<!fir.ptr<none>>)
51 // CHECK: %[[VAL_11:.*]] = fir.box_addr %[[VAL_7]] : (!fir.class<!fir.ptr<none>>) -> !fir.ptr<i32>
52 // CHECK: fir.store %[[VAL_3]] to %[[VAL_11]] : !fir.ptr<i32>
53 // CHECK: %[[VAL_12:.*]] = fir.call @_QPfstar() fastmath<contract> : () -> !fir.class<!fir.ptr<none>>
54 // CHECK: fir.save_result %[[VAL_12]] to %[[VAL_4]] : !fir.class<!fir.ptr<none>>, !fir.ref<!fir.class<!fir.ptr<none>>>
55 // CHECK: %[[VAL_13:.*]] = fir.load %[[VAL_4]] : !fir.ref<!fir.class<!fir.ptr<none>>>
56 // CHECK: %[[VAL_14:.*]] = arith.constant 9 : i8
57 // CHECK: %[[VAL_15:.*]] = fir.box_typecode %[[VAL_13]] : (!fir.class<!fir.ptr<none>>) -> i8
58 // CHECK: %[[VAL_16:.*]] = arith.cmpi eq, %[[VAL_15]], %[[VAL_14]] : i8
59 // CHECK: cf.cond_br %[[VAL_16]], ^bb5, ^bb4
60 // CHECK: ^bb3(%[[VAL_17:.*]]: !fir.class<!fir.ptr<none>>):
61 // CHECK: %[[VAL_18:.*]] = fir.rebox %[[VAL_17]] : (!fir.class<!fir.ptr<none>>) -> !fir.class<none>
62 // CHECK: fir.call @_QPfoo(%[[VAL_18]]) fastmath<contract> : (!fir.class<none>) -> ()
63 // CHECK: %[[VAL_19:.*]] = fir.address_of(@_QQclX6661696C2074797065) : !fir.ref<!fir.char<1,9>>
64 // CHECK: %[[VAL_20:.*]] = fir.convert %[[VAL_19]] : (!fir.ref<!fir.char<1,9>>) -> !fir.ref<i8>
65 // CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_2]] : (index) -> i64
66 // CHECK: %[[VAL_22:.*]] = fir.call @_FortranAStopStatementText(%[[VAL_20]], %[[VAL_21]], %[[VAL_1]], %[[VAL_1]]) fastmath<contract> : (!fir.ref<i8>, i64, i1, i1) -> none
67 // CHECK: fir.unreachable
69 // CHECK: cf.br ^bb3(%[[VAL_13]] : !fir.class<!fir.ptr<none>>)
71 // CHECK: %[[VAL_23:.*]] = fir.box_addr %[[VAL_13]] : (!fir.class<!fir.ptr<none>>) -> !fir.ptr<i32>
72 // CHECK: fir.store %[[VAL_0]] to %[[VAL_23]] : !fir.ptr<i32>
75 func.func @_QPtest() {
76 %c23_i32 = arith.constant 23 : i32
77 %false = arith.constant false
78 %c9 = arith.constant 9 : index
79 %c777_i32 = arith.constant 777 : i32
80 %0 = fir.alloca !fir.class<!fir.ptr<none>> {bindc_name = ".result"}
81 %1 = fir.alloca !fir.class<!fir.ptr<none>> {bindc_name = ".result"}
82 %2 = fir.call @_QPfstar() fastmath<contract> : () -> !fir.class<!fir.ptr<none>>
83 fir.save_result %2 to %1 : !fir.class<!fir.ptr<none>>, !fir.ref<!fir.class<!fir.ptr<none>>>
84 %3 = fir.load %1 : !fir.ref<!fir.class<!fir.ptr<none>>>
85 fir.select_type %3 : !fir.class<!fir.ptr<none>> [#fir.type_is<i32>, ^bb1, unit, ^bb2(%3 : !fir.class<!fir.ptr<none>>)]
87 %4 = fir.box_addr %3 : (!fir.class<!fir.ptr<none>>) -> !fir.ptr<i32>
88 fir.store %c777_i32 to %4 : !fir.ptr<i32>
89 %5 = fir.call @_QPfstar() fastmath<contract> : () -> !fir.class<!fir.ptr<none>>
90 fir.save_result %5 to %0 : !fir.class<!fir.ptr<none>>, !fir.ref<!fir.class<!fir.ptr<none>>>
91 %6 = fir.load %0 : !fir.ref<!fir.class<!fir.ptr<none>>>
92 fir.select_type %6 : !fir.class<!fir.ptr<none>> [#fir.type_is<i32>, ^bb3, unit, ^bb2(%6 : !fir.class<!fir.ptr<none>>)]
93 ^bb2(%7: !fir.class<!fir.ptr<none>>): // 2 preds: ^bb0, ^bb1
94 %8 = fir.rebox %7 : (!fir.class<!fir.ptr<none>>) -> !fir.class<none>
95 fir.call @_QPfoo(%8) fastmath<contract> : (!fir.class<none>) -> ()
96 %9 = fir.address_of(@_QQclX6661696C2074797065) : !fir.ref<!fir.char<1,9>>
97 %10 = fir.convert %9 : (!fir.ref<!fir.char<1,9>>) -> !fir.ref<i8>
98 %11 = fir.convert %c9 : (index) -> i64
99 %12 = fir.call @_FortranAStopStatementText(%10, %11, %false, %false) fastmath<contract> : (!fir.ref<i8>, i64, i1, i1) -> none
102 %13 = fir.box_addr %6 : (!fir.class<!fir.ptr<none>>) -> !fir.ptr<i32>
103 fir.store %c23_i32 to %13 : !fir.ptr<i32>