[Mlir-commits] [mlir] [mlir][IR] Initialize empty dialect resource handles (PR #220585)

Mehdi Amini llvmlistbot at llvm.org
Wed Sep 2 06:11:13 PDT 2026


https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/220585

A default AsmDialectResourceHandle leaves its dialect pointer indeterminate. Initialize the pointer to null and test all default-handle accessors.

Valgrind pre-fix trace:

```
  OpImplementationTest.cpp:19: Failure
  Expected equality of handle.getDialect() and nullptr
  handle.getDialect() was 0x120b508
  1 FAILED TEST
```

Found by Coverity.

Assisted-by: Codex

>From 23d855d4818b9d96a15f72c691cf6ba935dd4b07 Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Wed, 2 Sep 2026 06:01:38 -0700
Subject: [PATCH] [mlir][IR] Initialize empty dialect resource handles

A default AsmDialectResourceHandle leaves its dialect pointer indeterminate.
Initialize the pointer to null and test all default-handle accessors.

Valgrind pre-fix trace:

  OpImplementationTest.cpp:19: Failure
  Expected equality of handle.getDialect() and nullptr
  handle.getDialect() was 0x120b508
  1 FAILED TEST

Found by Coverity.

Assisted-by: Codex
---
 mlir/include/mlir/IR/OpImplementation.h    |  2 +-
 mlir/unittests/IR/CMakeLists.txt           |  1 +
 mlir/unittests/IR/OpImplementationTest.cpp | 21 +++++++++++++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 mlir/unittests/IR/OpImplementationTest.cpp

diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h
index ce26c4b4c9cbf..85021653da9be 100644
--- a/mlir/include/mlir/IR/OpImplementation.h
+++ b/mlir/include/mlir/IR/OpImplementation.h
@@ -68,7 +68,7 @@ class AsmDialectResourceHandle {
   /// The type of the resource referenced.
   TypeID opaqueID;
   /// The dialect owning the given resource.
-  Dialect *dialect;
+  Dialect *dialect = nullptr;
 };
 
 /// This class represents a CRTP base class for dialect resource handles. It
diff --git a/mlir/unittests/IR/CMakeLists.txt b/mlir/unittests/IR/CMakeLists.txt
index 560f10eb9815b..ce9b230222f62 100644
--- a/mlir/unittests/IR/CMakeLists.txt
+++ b/mlir/unittests/IR/CMakeLists.txt
@@ -14,6 +14,7 @@ add_mlir_unittest(MLIRIRTests
   LocationTest.cpp
   MLIRContextResetTest.cpp
   MemrefLayoutTest.cpp
+  OpImplementationTest.cpp
   OperationSupportTest.cpp
   PatternMatchTest.cpp
   RemarkTest.cpp  
diff --git a/mlir/unittests/IR/OpImplementationTest.cpp b/mlir/unittests/IR/OpImplementationTest.cpp
new file mode 100644
index 0000000000000..9049e57cf6fc1
--- /dev/null
+++ b/mlir/unittests/IR/OpImplementationTest.cpp
@@ -0,0 +1,21 @@
+//===- OpImplementationTest.cpp - Operation implementation tests ----------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/IR/OpImplementation.h"
+#include "gtest/gtest.h"
+
+using namespace mlir;
+
+namespace {
+TEST(AsmDialectResourceHandleTest, DefaultHandle) {
+  AsmDialectResourceHandle handle;
+  EXPECT_EQ(handle.getResource(), nullptr);
+  EXPECT_EQ(handle.getTypeID(), TypeID::get<void>());
+  EXPECT_EQ(handle.getDialect(), nullptr);
+}
+} // namespace



More information about the Mlir-commits mailing list