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

Igor Wodiany llvmlistbot at llvm.org
Mon Apr 7 04:06:35 PDT 2025


https://github.com/IgWod-IMG created https://github.com/llvm/llvm-project/pull/134610

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.

>From 6d9028c7e880564c04f6be7d53c585687cd0d5c7 Mon Sep 17 00:00:00 2001
From: Igor Wodiany <igor.wodiany at imgtec.com>
Date: Mon, 7 Apr 2025 11:27:16 +0100
Subject: [PATCH] [mlir][spirv] Fix incorrect argument erasure in deserializer

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.
---
 mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

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



More information about the Mlir-commits mailing list