1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
// RUN: mlir-opt %s --transform-dialect-check-uses --split-input-file --verify-diagnostics
func.func @use_after_free_branching_control_flow() {
// expected-note @below {{allocated here}}
%0 = transform.test_produce_self_handle_or_forward_operand : () -> !transform.any_op
transform.test_transform_op_with_regions {
"transform.test_branching_transform_op_terminator"() : () -> ()
},
{
^bb0:
"transform.test_branching_transform_op_terminator"()[^bb1, ^bb2] : () -> ()
^bb1:
// expected-note @below {{freed here}}
transform.test_consume_operand_of_op_kind_or_fail %0, "transform.test_produce_self_handle_or_forward_operand" : !transform.any_op
"transform.test_branching_transform_op_terminator"()[^bb3] : () -> ()
^bb2:
"transform.test_branching_transform_op_terminator"()[^bb3] : () -> ()
^bb3:
// expected-warning @below {{operand #0 may be used after free}}
transform.sequence %0 : !transform.any_op failures(propagate) {
^bb0(%arg0: !transform.any_op):
}
"transform.test_branching_transform_op_terminator"() : () -> ()
}
return
}
// -----
func.func @use_after_free_in_nested_op() {
// expected-note @below {{allocated here}}
%0 = transform.test_produce_self_handle_or_forward_operand : () -> !transform.any_op
// expected-note @below {{freed here}}
transform.test_transform_op_with_regions {
"transform.test_branching_transform_op_terminator"() : () -> ()
},
{
^bb0:
"transform.test_branching_transform_op_terminator"()[^bb1, ^bb2] : () -> ()
^bb1:
transform.test_consume_operand_of_op_kind_or_fail %0, "transform.test_produce_self_handle_or_forward_operand" : !transform.any_op
"transform.test_branching_transform_op_terminator"()[^bb3] : () -> ()
^bb2:
"transform.test_branching_transform_op_terminator"()[^bb3] : () -> ()
^bb3:
"transform.test_branching_transform_op_terminator"() : () -> ()
}
// expected-warning @below {{operand #0 may be used after free}}
transform.sequence %0 : !transform.any_op failures(propagate) {
^bb0(%arg0: !transform.any_op):
}
return
}
// -----
func.func @use_after_free_recursive_side_effects() {
transform.sequence failures(propagate) {
^bb0(%arg0: !transform.any_op):
// expected-note @below {{allocated here}}
%0 = transform.sequence %arg0 : !transform.any_op -> !transform.any_op failures(propagate) attributes { ord = 1 } {
^bb1(%arg1: !transform.any_op):
yield %arg1 : !transform.any_op
}
transform.sequence %0 : !transform.any_op failures(propagate) attributes { ord = 2 } {
^bb2(%arg2: !transform.any_op):
}
transform.sequence %0 : !transform.any_op failures(propagate) attributes { ord = 3 } {
^bb3(%arg3: !transform.any_op):
}
// `transform.sequence` has recursive side effects so it has the same "free"
// as the child op it contains.
// expected-note @below {{freed here}}
transform.sequence %0 : !transform.any_op failures(propagate) attributes { ord = 4 } {
^bb4(%arg4: !transform.any_op):
test_consume_operand_of_op_kind_or_fail %0, "transform.sequence" : !transform.any_op
}
// expected-warning @below {{operand #0 may be used after free}}
transform.sequence %0 : !transform.any_op failures(propagate) attributes { ord = 5 } {
^bb3(%arg3: !transform.any_op):
}
}
return
}
// -----
func.func @use_after_free() {
transform.sequence failures(propagate) {
^bb0(%arg0: !transform.any_op):
// expected-note @below {{allocated here}}
%0 = transform.sequence %arg0 : !transform.any_op -> !transform.any_op failures(propagate) attributes { ord = 1 } {
^bb1(%arg1: !transform.any_op):
yield %arg1 : !transform.any_op
}
transform.sequence %0 : !transform.any_op failures(propagate) attributes { ord = 2 } {
^bb2(%arg2: !transform.any_op):
}
transform.sequence %0 : !transform.any_op failures(propagate) attributes { ord = 3 } {
^bb3(%arg3: !transform.any_op):
}
// expected-note @below {{freed here}}
test_consume_operand_of_op_kind_or_fail %0, "transform.sequence" : !transform.any_op
// expected-warning @below {{operand #0 may be used after free}}
transform.sequence %0 : !transform.any_op failures(propagate) attributes { ord = 5 } {
^bb3(%arg3: !transform.any_op):
}
}
return
}
// -----
// In the case of a control flow cycle, the operation that uses the value may
// precede the one that frees it in the same block. Both operations should
// be reported as use-after-free.
func.func @use_after_free_self_cycle() {
// expected-note @below {{allocated here}}
%0 = transform.test_produce_self_handle_or_forward_operand : () -> !transform.any_op
transform.test_transform_op_with_regions {
"transform.test_branching_transform_op_terminator"() : () -> ()
},
{
^bb0:
"transform.test_branching_transform_op_terminator"()[^bb1] : () -> ()
^bb1:
// expected-warning @below {{operand #0 may be used after free}}
transform.sequence %0 : !transform.any_op failures(propagate) {
^bb0(%arg0: !transform.any_op):
}
// expected-warning @below {{operand #0 may be used after free}}
// expected-note @below {{freed here}}
transform.test_consume_operand_of_op_kind_or_fail %0, "transform.test_produce_self_handle_or_forward_operand" : !transform.any_op
"transform.test_branching_transform_op_terminator"()[^bb1, ^bb2] : () -> ()
^bb2:
"transform.test_branching_transform_op_terminator"() : () -> ()
}
return
}
// -----
// Check that the "free" that happens in a cycle is also reported as potential
// use-after-free.
func.func @use_after_free_cycle() {
// expected-note @below {{allocated here}}
%0 = transform.test_produce_self_handle_or_forward_operand : () -> !transform.any_op
transform.test_transform_op_with_regions {
"transform.test_branching_transform_op_terminator"() : () -> ()
},
{
^bb0:
"transform.test_branching_transform_op_terminator"()[^bb1, ^bb2] : () -> ()
^bb1:
// expected-warning @below {{operand #0 may be used after free}}
// expected-note @below {{freed here}}
transform.test_consume_operand_of_op_kind_or_fail %0, "transform.test_produce_self_handle_or_forward_operand" : !transform.any_op
"transform.test_branching_transform_op_terminator"()[^bb2, ^bb3] : () -> ()
^bb2:
"transform.test_branching_transform_op_terminator"()[^bb1] : () -> ()
^bb3:
"transform.test_branching_transform_op_terminator"() : () -> ()
}
return
}
// -----
// This should not crash.
transform.sequence failures(propagate) {
^bb0(%arg0: !transform.any_op):
alternatives %arg0 : !transform.any_op {
^bb0(%arg1: !transform.any_op):
}
}
|