[Mlir-commits] [mlir] [mlir][PDL] Handle inferReturnTypes failure in ByteCode executor (PR #174099)

Nick Kreeger llvmlistbot at llvm.org
Wed Dec 31 07:59:28 PST 2025


https://github.com/nkreeger updated https://github.com/llvm/llvm-project/pull/174099

>From a78dfbb0770215933c1e99413940fc1eadc33a6c Mon Sep 17 00:00:00 2001
From: Nick Kreeger <nick.kreeger at gmail.com>
Date: Wed, 31 Dec 2025 09:51:18 -0600
Subject: [PATCH] [mlir][PDL] Handle inferReturnTypes failure in ByteCode
 executor

Previously, when `inferReturnTypes` failed during operation creation in the PDL bytecode executor, the failure was silently ignored and the function returned early. This left the memory slot for the operation result uninitialized, potentially causing undefined behavior.
---
 mlir/lib/Rewrite/ByteCode.cpp | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/mlir/lib/Rewrite/ByteCode.cpp b/mlir/lib/Rewrite/ByteCode.cpp
index 159aa54686034..60188f020a4a6 100644
--- a/mlir/lib/Rewrite/ByteCode.cpp
+++ b/mlir/lib/Rewrite/ByteCode.cpp
@@ -1157,8 +1157,8 @@ class ByteCodeExecutor {
   void executeCheckTypes();
   void executeContinue();
   void executeCreateConstantTypeRange();
-  void executeCreateOperation(PatternRewriter &rewriter,
-                              Location mainRewriteLoc);
+  LogicalResult executeCreateOperation(PatternRewriter &rewriter,
+                                       Location mainRewriteLoc);
   template <typename T>
   void executeDynamicCreateRange(StringRef type);
   void executeEraseOp(PatternRewriter &rewriter);
@@ -1626,8 +1626,9 @@ void ByteCodeExecutor::executeCreateConstantTypeRange() {
                       rangeIndex);
 }
 
-void ByteCodeExecutor::executeCreateOperation(PatternRewriter &rewriter,
-                                              Location mainRewriteLoc) {
+LogicalResult
+ByteCodeExecutor::executeCreateOperation(PatternRewriter &rewriter,
+                                         Location mainRewriteLoc) {
   LDBG() << "Executing CreateOperation:";
 
   unsigned memIndex = read();
@@ -1648,12 +1649,11 @@ void ByteCodeExecutor::executeCreateOperation(PatternRewriter &rewriter,
     assert(inferInterface &&
            "expected operation to provide InferTypeOpInterface");
 
-    // TODO: Handle failure.
     if (failed(inferInterface->inferReturnTypes(
             state.getContext(), state.location, state.operands,
             state.attributes.getDictionary(state.getContext()),
             state.getRawProperties(), state.regions, state.types)))
-      return;
+      return failure();
   } else {
     // Otherwise, this is a fixed number of results.
     for (unsigned i = 0; i != numResults; ++i) {
@@ -1674,6 +1674,7 @@ void ByteCodeExecutor::executeCreateOperation(PatternRewriter &rewriter,
          << "\n  * Operands: " << llvm::interleaved(state.operands)
          << "\n  * Result Types: " << llvm::interleaved(state.types)
          << "\n  * Result: " << *resultOp;
+  return success();
 }
 
 template <typename T>
@@ -2153,7 +2154,8 @@ ByteCodeExecutor::execute(PatternRewriter &rewriter,
       executeCreateConstantTypeRange();
       break;
     case CreateOperation:
-      executeCreateOperation(rewriter, *mainRewriteLoc);
+      if (failed(executeCreateOperation(rewriter, *mainRewriteLoc)))
+        return failure();
       break;
     case CreateDynamicTypeRange:
       executeDynamicCreateRange<Type>("Type");



More information about the Mlir-commits mailing list