[Mlir-commits] [mlir] [MLIR][Linalg] Fix ASAN bug from #222959 (PR #223683)

Renato Golin llvmlistbot at llvm.org
Tue Sep 15 05:49:38 PDT 2026


https://github.com/rengolin created https://github.com/llvm/llvm-project/pull/223683

None

>From 9e3307d3fe03d0ddc6fc765ce51a7a1714d6df22 Mon Sep 17 00:00:00 2001
From: rengolin <rengolin at systemcall.eu>
Date: Tue, 15 Sep 2026 05:49:03 -0700
Subject: [PATCH] [MLIR][Linalg] Fix ASAN bug from #222959

---
 .../lib/Dialect/Linalg/Transforms/Generalization.cpp | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/mlir/lib/Dialect/Linalg/Transforms/Generalization.cpp b/mlir/lib/Dialect/Linalg/Transforms/Generalization.cpp
index 5a51328b3eee4..2b37a635dac1a 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Generalization.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Generalization.cpp
@@ -70,16 +70,22 @@ static FailureOr<LinalgOp> generalizeToContractOp(RewriterBase &rewriter,
       castAttr && castAttr.getValue() == TypeFn::cast_unsigned)
     attributes.push_back(rewriter.getNamedAttr("cast", castAttr));
 
+  // Capture the operands and discardable attributes before `namedOp` is erased
+  // by the replacement below.
+  Value lhs = namedOp.getDpsInputs()[0];
+  Value rhs = namedOp.getDpsInputs()[1];
+  Value init = namedOp.getDpsInits()[0];
+  DictionaryAttr discardableAttrs = namedOp->getDiscardableAttrDictionary();
+
   LinalgOp contractOp = rewriter.replaceOpWithNewOp<ContractOp>(
-      namedOp, ValueRange{namedOp.getDpsInputs()[0], namedOp.getDpsInputs()[1]},
-      ValueRange{namedOp.getDpsInits()[0]}, attributes);
+      namedOp, ValueRange{lhs, rhs}, ValueRange{init}, attributes);
 
   // Discardable attributes carry user-defined metadata (e.g., annotations for
   // downstream passes). Generalization is a semantics-preserving
   // transformation, so dropping this metadata would be unexpected. This is safe
   // because discardable attributes are by definition independent of op
   // semantics.
-  contractOp->setDiscardableAttrs(namedOp->getDiscardableAttrDictionary());
+  contractOp->setDiscardableAttrs(discardableAttrs);
 
   return contractOp;
 }



More information about the Mlir-commits mailing list