<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64280>64280</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR] In-place folds lead to invalid attributes being passed to `foldTraits`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
youngar
</td>
</tr>
</table>
<pre>
When an operation does an "in-place fold", we later call the `foldTraits` method using the same attribute array `operands` which was passed to the folder.
https://github.com/llvm/llvm-project/blob/29b1af7396b0839f076ca0a8ae3a5ac47ed55ee7/mlir/include/mlir/IR/OpDefinition.h#L1912-L1944
If the operation's folder modifies the op's operands, by adding, deleting, or shuffling, then the `operands` array will be invalid. The `operands` array should be updated each time any folder (op or trait) does an in-place fold.
Right now this is manifesting in a CIRCT folder, where an op gains an additional argument in its folder, and then crashes in the `commutative` folder as the `operands` array is short one element.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVE9vqzgQ_zTmMmpkDAQ4cHjbCilSVytVlfY84AFmZezINo3y7VcmvLZvpXfYSxLbMx7__gVD4NkSdaL6Q1QvGW5xcb67u83O6LPB6Xv390IW0IK7ksfIzoJ2FNKOUIrt09XgSDA5o4VSQj3DjcBgJA8jGgNxIRBnmc7fPXIM4ixhpbg4DVtgO-8VAVcCjNHzsEUC9B7vqW0favXedFt4XOCGAa4YAmmIbu9NV5M_Cfki5I_H5xLjNYjih1C9UP3McdmG0-hWoXpjPn5-PV29-4fGKFQ_GDcI1at2yHGqi_Y8yKZoJ1mfR5TYIBVY4VjWpKuKqBaqXw17oXq2o9k0fW1c3oTq_7q-0MSWE12nRajiNW9z9fSat2X5_Z2XaUfwSa1QdTjwwOo0T0zhqNiPPulQzzDcAbVmO6eFJkPx-O08hGWbJnOsYxLwkOE7nw-Sb2wMDARsP9CwPsH77yrD4jajU-121RhJA-G4QOQknb3_fLdQjbumR8Qkt1Dtp19-Mcsver3xvESw7gZx4QAcYEXLE4WECdgCwvPl7fn9mLG7bCFPD1_CjGz3CYmQxCMaQD9vK9mYujmGb51o9YOT0WNYKKSKg57RresWMfIHJdwHIgy_p49D4sVHcJaADKWRp0x3hW6LFjPq8nMrG9WeizJburKWjczzvMUWq7yW52HQtZY4VlXb4DRm3CmpClkXed5URVWeprLJ21HVucShrsdSlJJWZHNKBj45P2ccwkbduVSNzAwOZMKeZqUehlQp177b_T5scxClNBxi-LogcjT7P8Cfr5c3Ub3A5btOAQzhnrXDIV8xDTBQ0ucrjv8NerZ50_3vMO6IglD9DurfAAAA___nrYb4">