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 @@ -151,6 +151,14 @@ return str; } +// Escape a string using LLVM/MLIR encoding. E.g. foo"bar -> foo\22bar. +static std::string escapeString(StringRef value) { + std::string ret; + llvm::raw_string_ostream os(ret); + llvm::printEscapedString(value, os); + return os.str(); +} + // Returns whether the record has a value of the given name that can be returned // via getValueAsString. static inline bool hasStringAttribute(const Record &record, @@ -359,6 +367,7 @@ // The emitter containing all of the locally emitted verification functions. const StaticVerifierFunctionEmitter &staticVerifierEmitter; }; + } // end anonymous namespace // Populate the format context `ctx` with substitutions of attributes, operands @@ -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";