Skip to content

Commit aaf7f92

Browse files
authored
FoldBinaryThroughQDQ: prevent invalid read access (#470)
1 parent 8139ea5 commit aaf7f92

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Dialect/ONNX/Transforms/DQBinaryQOpt.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,10 @@ struct FoldBinaryThroughQDQ : public OpRewritePattern<BinOp> {
538538
rewriter.replaceOp(op, dqAct.getResult());
539539

540540
// STEP 7: Remove Q->DQ chain
541-
for (Operation *user : quantOutputOp.getY().getUsers()) {
541+
542+
// prevent iterating and removing elements
543+
auto users = llvm::make_early_inc_range(quantOutputOp.getY().getUsers());
544+
for (Operation *user : users) {
542545
if (auto tailDQ = llvm::dyn_cast<ONNXDequantizeLinearOp>(user)) {
543546
(void)tryRemoveQThenDQChain(rewriter, tailDQ);
544547
}

0 commit comments

Comments
 (0)