[Mlir-commits] [mlir] [MLIR] Fix empty optional access in DialectConversion (PR #168331)

Vadim Curcă llvmlistbot at llvm.org
Mon Nov 17 00:22:00 PST 2025


https://github.com/VadimCurca created https://github.com/llvm/llvm-project/pull/168331

When both `MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS` and MLIR multithreading are enabled, `topLevelFingerPrint` is empty but its value is accessed. This adds a `has_value()` check before dereferencing the optional.

>From 3ed1138a42c621332516a45e9cdadeef7c11330a Mon Sep 17 00:00:00 2001
From: VadimCurca <vadimc at fondue.il.nextsilicon.com>
Date: Mon, 17 Nov 2025 08:51:25 +0100
Subject: [PATCH] [MLIR] Fix empty optional access in DialectConversion

When both `MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS` and MLIR
multithreading are enabled, `topLevelFingerPrint` is empty but its value
is accessed. This adds a `has_value()` check before dereferencing the
optional.
---
 mlir/lib/Transforms/Utils/DialectConversion.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 365bfddeaab73..b8e78d3287126 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -2766,7 +2766,7 @@ LogicalResult OperationLegalizer::legalizeWithPattern(Operation *op) {
       rewriterImpl.patternMaterializations.clear();
 #if MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS
       // Expensive pattern check that can detect API violations.
-      if (checkOp) {
+      if (checkOp && topLevelFingerPrint.has_value()) {
         OperationFingerPrint fingerPrintAfterPattern(checkOp);
         if (fingerPrintAfterPattern != *topLevelFingerPrint)
           llvm::report_fatal_error("pattern '" + pattern.getDebugName() +



More information about the Mlir-commits mailing list