<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/151640>151640</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir] `Operation::clone` doesn't clone properties of unregister ops
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
uenoku
</td>
</tr>
</table>
<pre>
@fabianschuiki and I have seen `Operation::clone` drops properties of unregistered ops in downstream projects. This is a reproducer using `test-clone` pass:
```mlir
$ cat test.mlir
"builtin.module"() ({
"func.func"() <{function_type = () -> (), sym_name = "func"}> ({
"unregistered.foo" ()<{bar = 1}> : () -> ()
}) : () -> ()
}) : () -> ()
$ mlir-opt test.mlir --pass-pipeline='builtin.module(func.func(test-clone))' -allow-unregistered-dialect -mlir-print-ir-before-all -mlir-print-ir-after-all
// -----// IR Dump Before (anonymous namespace)::ClonePass (test-clone) //----- //
func.func @func() {
"unregistered.foo"() <{bar = 1 : i64}> : () -> ()
}
notifyOperationInserted: unregistered.foo
// -----// IR Dump After (anonymous namespace)::ClonePass (test-clone) //----- //
func.func @func() {
"unregistered.foo"() : () -> ()
}
module {
func.func @func() {
"unregistered.foo"() : () -> ()
}
}
```
I debugged a bit and I think `getPropertiesStorage` in the following code always returns null for unregister ops. I think it's necessary to initialize OperationState's `propertiesAttr` for unregistered ops instead.
https://github.com/llvm/llvm-project/blob/9c90f848fda9992ab6294d33665c1e2eb0613c0a/mlir/lib/IR/Operation.cpp#L735-L736
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8VUuP2zYQ_jX0ZSCBot4HHbzrGlggQIOk94CiRjK7NCmQ1C7cX1-QshVn2-yiPcQQrMc8vplvyI_cOTlpxI6UD6Q87PjiT8Z2C2rzvOx6M1w6QvekoCPvJddOnBb5LIHrAZ7gxF8QHKIGUtHfZ7TcS6NJvif5XiijkVQUBmtmB7M1M1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