<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/129216>129216</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir][td] check-use-after-free.mlir failing (AppleSillcon + shared libs)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
banach-space
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
banach-space
</td>
</tr>
</table>
<pre>
Hi,
[check-use-after-free.mlir](https://github.com/llvm/llvm-project/blob/main/mlir/test/Dialect/Transform/check-use-after-free.mlir) fails for for me on **AppleSilicon** (checked on M3 and M4) with:
* -DBUILD_SHARED_LIBS=**On**
(static libs build is fine).
I've tracked it down to the TD logic incorrectly assuming that at runtime there will be only one instance of [DerivedResource](https://github.com/llvm/llvm-project/blob/78c96aa24f0406e630674d82eef073ea3d4c8141/mlir/include/mlir/Interfaces/SideEffectInterfaces.h#L90-L93). That assumption is effectively made here: https://github.com/llvm/llvm-project/blob/78c96aa24f0406e630674d82eef073ea3d4c8141/mlir/include/mlir/Interfaces/SideEffectInterfaceBase.td#L132
I actually end up with **two** instances of that class at runtime, both are instantiations of:
```cpp
mlir::SideEffects::Resource::Base<mlir::transform::TransformMappingResource, mlir::SideEffects::Resource>:
```
* one instance "lives" in `libMLIRTransformDialectInterfaces.dylib`,
* another instances "lives" in `libMLIRTransformDialectTransforms.dylib`.
**QUESITON:**
Should I update [getEffectsOnResource](https://github.com/llvm/llvm-project/blob/78c96aa24f0406e630674d82eef073ea3d4c8141/mlir/include/mlir/Interfaces/SideEffectInterfaceBase.td#L132) to compare `ResourceID` instead?
```cpp
return it.getResource()->getResourceID() != resource->getResourceID();
```
https://github.com/llvm/llvm-project/blob/78c96aa24f0406e630674d82eef073ea3d4c8141/mlir/include/mlir/Interfaces/SideEffectInterfaces.h#L108
Alternatively, we could explore ways to ensure that there is only one instance across all shared objects, but I’m not sure how best to achieve that.
@ftynse, could you take a look when you get a chance? "git log" wasn’t very helpful here (this logic depends on quite a few components), and you’re my go-to TD expert. 🙂
—Andrzej
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUll-P2jgQwD-NeRmBHCdA8sBD2Cwq0u5V190-V44zIW6NnbMdKPfpT3YC7LVXqad76UmgKBN7PDP-zR_unDxoxA1ZbgljNddcdHPXc4GEMbKsZnzwnbGbt19mtWkum3eSsAdCy_BbbkWH4st8cDjnrUc7by3i4qikJcuKsLzzvnckLQnbEbY7SN8N9UKYI2E7pU7Xx7y35jMKT9iuVqYmbHfkUodHUMR2Hl34VkmuxlWvlmvXGhsU_NgCVkDLpXLQGhv_RwQwGggrCSvLvlf4IpUURo8SICyP2rAJy55T4LqB5ywoOkvfBT9oXDivth_3T9Wnl3flh8fq09N--0LSatTyftI2hYjlznMvBShZO6gHqRqQDlqpkbBiAeOyPWHrE4K3PJ4uPTTmrMEb8B3CawXKHKQAqYWxFoVXF-DODUepD-A77oF7sIP28ohhh0U4S6WgRjBaXcBoBKmd51ogmBbIcluhlSdsPqAzgxX4365rnYtixTnLWprRFa5SulpnTc4QW7pOkadNJvIkS-5XKrVQQ4N3wV57tC0X6AjbvcgGH9sWhb-LFx1h6VNB509FGiP3Gv0OUei9NDpEFeMeeUJ1gSNvEEIoSFrCL-zYljtc-CY4l6RswgG48ANX6gKoGxj6yN8Erj-bidfrlbpwpxEDobhzb2Ag7AFq4zvg9kqAlzyEK-yZgF7R8Sf6ntAymp2WJC3vxrpRcIMlvgXDSfpwX-9vWRlfb0n6zPte6sNtN3uAnzrk8Rv7rhlV_p1nwpiSpxBeBlIDWVEl6-en_YebAVPheMNSc1GyDirZA0w6uTYhc94E9acV397vihc3Ywkrf__4-LJ_ff9bBPBeG146M6gG9jD0DfcYsvKAfgrGe_2_Sc1vCGZFqFvCHPsAHVnRqyP7iqxojC_yhqS779mz6AerQfrFAf2dl5ywYk7SxzfCfTWKgbCEpBXYSf6DZSTdfk_SLxzSqdolNB9NL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