[Mlir-commits] [mlir] 5c0369e - Fix escaping in RewriterGen.cpp.

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Oct 21 14:33:23 PDT 2021


Author: Matthias Kramm
Date: 2021-10-21T21:33:19Z
New Revision: 5c0369eceb2c64b80bf2db57ca6cac7db3e3957b

URL: https://github.com/llvm/llvm-project/commit/5c0369eceb2c64b80bf2db57ca6cac7db3e3957b
DIFF: https://github.com/llvm/llvm-project/commit/5c0369eceb2c64b80bf2db57ca6cac7db3e3957b.diff

LOG: 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

Added: 
    

Modified: 
    mlir/tools/mlir-tblgen/RewriterGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/tools/mlir-tblgen/RewriterGen.cpp b/mlir/tools/mlir-tblgen/RewriterGen.cpp
index 9ce6eea4259ca..617e6b29254b7 100644
--- a/mlir/tools/mlir-tblgen/RewriterGen.cpp
+++ b/mlir/tools/mlir-tblgen/RewriterGen.cpp
@@ -50,10 +50,12 @@ struct format_provider<mlir::tblgen::Pattern::IdentifierLine> {
 };
 } // end namespace llvm
 
+// Escape a string for use inside a C++ literal.
+// 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);
+  os.write_escaped(value, /*use_hex_escapes=*/true);
   return os.str();
 }
 


        


More information about the Mlir-commits mailing list