diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -359,8 +359,17 @@ // The emitter containing all of the locally emitted verification functions. const StaticVerifierFunctionEmitter &staticVerifierEmitter; }; + } // end anonymous namespace +// Escape a string using C++ encoding. E.g. foo"bar -> foo\x22bar. +static std::string escapeString(StringRef value) { + std::string ret; + llvm::raw_string_ostream os(ret); + llvm::printEscapedString(value, os); + return os.str(); +} + // Populate the format context `ctx` with substitutions of attributes, operands // and results. // - attrGet corresponds to the name of the function to call to get value of @@ -464,7 +473,7 @@ body << tgfmt(" if (!($0)) return $1\"attribute '$2' " "failed to satisfy constraint: $3\");\n", /*ctx=*/nullptr, tgfmt(condition, &ctx.withSelf(varName)), - emitErrorPrefix, attrName, attr.getSummary()); + emitErrorPrefix, attrName, escapeString(attr.getSummary())); if (allowMissingAttr) body << " }\n"; body << " }\n";