[Mlir-commits] [mlir] [mlir][spirv] Fix incorrect argument erasure in deserializer (PR #134610)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Apr 7 04:07:11 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-spirv

Author: Igor Wodiany (IgWod-IMG)

<details>
<summary>Changes</summary>

The current implementation iterates and modifies the list of arguments at the same time. Depending on the number of arguments this will trigger an assert: `assert(index < arguments.size())`. This change replaces loop with a range based erasure.

---
Full diff: https://github.com/llvm/llvm-project/pull/134610.diff


1 Files Affected:

- (modified) mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp (+1-2) 


``````````diff
diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
index d471d9a8e3d6c..25749ec598f00 100644
--- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
+++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
@@ -2077,8 +2077,7 @@ LogicalResult ControlFlowStructurizer::structurize() {
     // block arguments from the original merge block.
     for (unsigned i = 0, e = outsideUses.size(); i != e; ++i)
       outsideUses[i].replaceAllUsesWith(selectionOp.getResult(i));
-    for (unsigned i = 0, e = mergeBlock->getNumArguments(); i != e; ++i)
-      mergeBlock->eraseArgument(i);
+    mergeBlock->eraseArguments(0, mergeBlock->getNumArguments());
   }
 
   // Check that whether some op in the to-be-erased blocks still has uses. Those

``````````

</details>


https://github.com/llvm/llvm-project/pull/134610


More information about the Mlir-commits mailing list