[Mlir-commits] [mlir] [mlir][ods] Fix string interpolation at end of description (PR #209744)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Jul 15 05:11:23 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Luke Hutton (lhutton1)
<details>
<summary>Changes</summary>
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) << "";
```
---
Full diff: https://github.com/llvm/llvm-project/pull/209744.diff
2 Files Affected:
- (modified) mlir/lib/TableGen/CodeGenHelpers.cpp (+6-8)
- (modified) mlir/test/mlir-tblgen/constraint-unique.td (+2-2)
``````````diff
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.*]](
``````````
</details>
https://github.com/llvm/llvm-project/pull/209744
More information about the Mlir-commits
mailing list