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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Dec 31 07:58:04 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Nick Kreeger (nkreeger)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/174099.diff


1 Files Affected:

- (modified) mlir/lib/Rewrite/ByteCode.cpp (+9-7) 


``````````diff
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");

``````````

</details>


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


More information about the Mlir-commits mailing list