Fix escaping in RewriterGen.cpp.

When we escape strings for C++, make sure we use C++ escape
sequences. (In particular, \x22 instead of \22)

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D112269
This commit is contained in:
Matthias Kramm 2021-10-21 21:30:31 +00:00 committed by Mogball
parent 910838f07d
commit 5c0369eceb
1 changed files with 3 additions and 1 deletions

View File

@ -50,10 +50,12 @@ struct format_provider<mlir::tblgen::Pattern::IdentifierLine> {
}; };
} // end namespace llvm } // end namespace llvm
// Escape a string for use inside a C++ literal.
// E.g. foo"bar -> foo\x22bar.
static std::string escapeString(StringRef value) { static std::string escapeString(StringRef value) {
std::string ret; std::string ret;
llvm::raw_string_ostream os(ret); llvm::raw_string_ostream os(ret);
llvm::printEscapedString(value, os); os.write_escaped(value, /*use_hex_escapes=*/true);
return os.str(); return os.str();
} }