[Mlir-commits] [mlir] [mlir][ods] Fix string interpolation at end of description (PR #209744)
Luke Hutton
llvmlistbot at llvm.org
Wed Jul 15 05:10:46 PDT 2026
https://github.com/lhutton1 created https://github.com/llvm/llvm-project/pull/209744
Updates the error streaming string logic to handle the case where string interpolation used at the end of the description. Previously this could generate malformed code that would not compile e.g.:
```
"' failed to satisfy constraint: another attribute " << reformat(attr)";
```
With this change the above example would now generate:
```
"' failed to satisfy constraint: another attribute " << reformat(attr) << "";
```
>From 43c7776c342274861c25a69100ecac05ba64e312 Mon Sep 17 00:00:00 2001
From: Luke Hutton <luke.hutton at arm.com>
Date: Thu, 9 Jul 2026 23:18:38 +0100
Subject: [PATCH] [mlir][ods] Fix string interpolation at end of description
Updates the error streaming string logic to handle the case
where string interpolation used at the end of the description.
Previously this could generate malformed code that would not
compile e.g.:
```
"' failed to satisfy constraint: another attribute " << reformat(attr)";
```
With this change the above example would now generate:
```
"' failed to satisfy constraint: another attribute " << reformat(attr) << "";
```
Change-Id: Iea9bd52064b5e19a9a258f955b3b70eb01f26415
---
mlir/lib/TableGen/CodeGenHelpers.cpp | 14 ++++++--------
mlir/test/mlir-tblgen/constraint-unique.td | 4 ++--
2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/mlir/lib/TableGen/CodeGenHelpers.cpp b/mlir/lib/TableGen/CodeGenHelpers.cpp
index c8c419669f3d4..19439eddcb333 100644
--- a/mlir/lib/TableGen/CodeGenHelpers.cpp
+++ b/mlir/lib/TableGen/CodeGenHelpers.cpp
@@ -157,18 +157,16 @@ std::string mlir::tblgen::buildErrorStreamingString(
os << " << " << tgfmt(var, &ctx);
- if (rest.empty())
- break;
-
- split = rest.split("{{");
- if (split.second.empty() &&
- errorStreamType == ErrorStreamType::InsideOpError) {
+ if (errorStreamType == ErrorStreamType::InsideOpError) {
// To enable having part of string post, this adds a parenthesis before
// the last string segment to match the existing one.
- os << " << (\"" << split.first;
+ os << " << (\"";
} else {
- os << " << \"" << split.first;
+ os << " << \"";
}
+
+ split = rest.split("{{");
+ os << split.first;
msg = split.second;
}
diff --git a/mlir/test/mlir-tblgen/constraint-unique.td b/mlir/test/mlir-tblgen/constraint-unique.td
index 5fdaf368c323a..55d6a56e3fc80 100644
--- a/mlir/test/mlir-tblgen/constraint-unique.td
+++ b/mlir/test/mlir-tblgen/constraint-unique.td
@@ -17,7 +17,7 @@ def OtherType : Type<ATypePred, "another type">;
def AnAttrPred : CPred<"attrPred($_self, $_op)">;
def AnAttr : Attr<AnAttrPred, "an attribute (got {{reformat($_self)}})">;
-def OtherAttr : Attr<AnAttrPred, "another attribute">;
+def OtherAttr : Attr<AnAttrPred, "another attribute {{reformat($_self)}}">;
def ASuccessorPred : CPred<"successorPred($_self, $_op)">;
def ASuccessor : Successor<ASuccessorPred, "a successor">;
@@ -81,7 +81,7 @@ def OpC : NS_Op<"op_c"> {
// CHECK: static ::llvm::LogicalResult [[$O_ATTR_CONSTRAINT:__mlir_ods_local_attr_constraint.*]](
// CHECK: if (attr && !((attrPred(attr, *op))))
// CHECK-NEXT: return emitError() << "attribute '" << attrName
-// CHECK-NEXT: << "' failed to satisfy constraint: another attribute";
+// CHECK-NEXT: << "' failed to satisfy constraint: another attribute " << reformat(attr) << "";
/// Test that a successor contraint was generated.
// CHECK: static ::llvm::LogicalResult [[$A_SUCCESSOR_CONSTRAINT:__mlir_ods_local_successor_constraint.*]](
More information about the Mlir-commits
mailing list