[Mlir-commits] [mlir] [mlir:tblgen] Qualify access to `getContext` to fix #218872. (PR #218951)
Ingo Müller
llvmlistbot at llvm.org
Wed Aug 26 08:09:25 PDT 2026
https://github.com/ingomueller-net created https://github.com/llvm/llvm-project/pull/218951
With #218872, some code generated by `tblgen` containing `getContext()` now uses `OpTyp::getContext()` if that op has a `context` property instead of the intendend `Operation::getContext()`. This PR qualifies the access such that the intended function is always called.
>From e787a3173cca21ffa1ef3195ec17d393f4d1500f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ingo=20M=C3=BCller?= <ingomueller at google.com>
Date: Wed, 26 Aug 2026 17:06:52 +0200
Subject: [PATCH] [mlir:tblgen] Qualify access to `getContext` to fix #218872.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
With #218872, some code generated by `tblgen` containing `getContext()`
now uses `OpTyp::getContext()` if that op has a `context` property
instead of the intendend `Operation::getContext()`. This PR qualifies
the access such that the intended function is always called.
Signed-off-by: Ingo Müller <ingomueller at google.com>
---
mlir/test/mlir-tblgen/op-format.td | 6 ++++++
mlir/tools/mlir-tblgen/OpFormatGen.cpp | 8 ++++----
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/mlir/test/mlir-tblgen/op-format.td b/mlir/test/mlir-tblgen/op-format.td
index 8c6359b89d88a..530005ca4973f 100644
--- a/mlir/test/mlir-tblgen/op-format.td
+++ b/mlir/test/mlir-tblgen/op-format.td
@@ -27,6 +27,12 @@ class TestStrictPropertiesFormat_Op<string fmt, list<Trait> traits = []>
// custom
//===----------------------------------------------------------------------===//
+// CHECK-LABEL: AttrDictContextOperand::print
+// CHECK: _odsPrinter.printOptionalAttrDict(_odsAttrs.getDictionary((*this)->getContext()).getValue(), elidedAttrs);
+def AttrDictContextOperand : TestFormat_Op<[{
+ $context `:` type($context) attr-dict
+}]>, Arguments<(ins AnyType:$context)>;
+
// CHECK-LABEL: AttrDictDefaultInherentAttr::parse
// CHECK: verifyInherentAttrs
def AttrDictDefaultInherentAttr : TestFormat_Op<[{
diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index 4a3b9f57e90ad..d0cce5b75f842 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -2549,7 +2549,7 @@ static void genPropDictPrinter(OperationFormat &fmt, Operator &op,
std::string(tgfmt(attr.getConstBuilderTemplate(), &fctx,
tgfmt(attr.getDefaultValue(), &fctx)));
body << " {\n";
- body << " ::mlir::Builder odsBuilder(getContext());\n";
+ body << " ::mlir::Builder odsBuilder((*this)->getContext());\n";
body << " ::mlir::Attribute attr = " << op.getGetterName(name)
<< "Attr();\n";
body << " if(attr && (attr == " << defaultValue << "))\n";
@@ -2572,7 +2572,7 @@ static void genPropDictPrinter(OperationFormat &fmt, Operator &op,
// The `printProperties` method is responsible for printing out a leading
// space so that empty `prop-dict`s don't produce stray whitespace.
if (fmt.useProperties) {
- body << " printProperties(this->getContext(), _odsPrinter, "
+ body << " printProperties((*this)->getContext(), _odsPrinter, "
"getProperties(), elidedProps);\n";
}
}
@@ -2602,7 +2602,7 @@ static void genAttrDictPrinter(OperationFormat &fmt, Operator &op,
std::string(tgfmt(attr.getConstBuilderTemplate(), &fctx,
tgfmt(attr.getDefaultValue(), &fctx)));
body << " {\n";
- body << " ::mlir::Builder odsBuilder(getContext());\n";
+ body << " ::mlir::Builder odsBuilder((*this)->getContext());\n";
body << " ::mlir::Attribute attr = " << op.getGetterName(name)
<< "Attr();\n";
body << " if(attr && (attr == " << defaultValue << "))\n";
@@ -2624,7 +2624,7 @@ static void genAttrDictPrinter(OperationFormat &fmt, Operator &op,
" });\n"
" _odsPrinter.printOptionalAttrDict"
<< (withKeyword ? "WithKeyword" : "")
- << "(_odsAttrs.getDictionary(getContext()).getValue(), "
+ << "(_odsAttrs.getDictionary((*this)->getContext()).getValue(), "
"elidedAttrs);\n";
}
}
More information about the Mlir-commits
mailing list