From 54c2c6adc232e22a2b2fbaa1623712a974203eea Mon Sep 17 00:00:00 2001 From: Alex Zinenko Date: Thu, 5 Dec 2024 12:55:10 +0100 Subject: [PATCH] correctly check uses of pattern descriptor transform ops In the transform dialect use-after-free chcker pass, account for pattern descriptor operations that intentionally have no declared side effects. They are not destroying any handles. Closes #118761. --- .../lib/Dialect/Transform/Transforms/CheckUses.cpp | 2 ++ .../Dialect/Transform/check-use-after-free.mlir | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/mlir/lib/Dialect/Transform/Transforms/CheckUses.cpp b/mlir/lib/Dialect/Transform/Transforms/CheckUses.cpp index e6db819b51c22..bfe1d9682177d 100644 --- a/mlir/lib/Dialect/Transform/Transforms/CheckUses.cpp +++ b/mlir/lib/Dialect/Transform/Transforms/CheckUses.cpp @@ -338,6 +338,8 @@ class TransformOpMemFreeAnalysis { void collectFreedValues(Operation *root) { SmallVector instances; root->walk([&](Operation *child) { + if (isa(child)) + return; // TODO: extend this to conservatively handle operations with undeclared // side effects as maybe freeing the operands. auto iface = cast(child); diff --git a/mlir/test/Dialect/Transform/check-use-after-free.mlir b/mlir/test/Dialect/Transform/check-use-after-free.mlir index 742c5dcc78f60..0fe8b5da17355 100644 --- a/mlir/test/Dialect/Transform/check-use-after-free.mlir +++ b/mlir/test/Dialect/Transform/check-use-after-free.mlir @@ -177,3 +177,17 @@ transform.sequence failures(propagate) { ^bb0(%arg1: !transform.any_op): } } + +// ----- + +// This should not crash. + +module attributes {transform.with_named_sequence} { + transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) { + %0 = transform.structured.match ops{["func.func"]} in %arg0 : (!transform.any_op) -> !transform.any_op + transform.apply_patterns to %0 { + transform.apply_patterns.memref.extract_address_computations + } : !transform.any_op + transform.yield + } +}