diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp --- a/mlir/lib/IR/AsmPrinter.cpp +++ b/mlir/lib/IR/AsmPrinter.cpp @@ -3101,7 +3101,11 @@ } void buildString(StringRef key, StringRef data) final { - printFn(key, [&](raw_ostream &os) { os << "\"" << data << "\""; }); + printFn(key, [&](raw_ostream &os) { + os << "\""; + llvm::printEscapedString(data, os); + os << "\""; + }); } void buildBlob(StringRef key, ArrayRef data, diff --git a/mlir/test/IR/pretty-resources-print.mlir b/mlir/test/IR/pretty-resources-print.mlir --- a/mlir/test/IR/pretty-resources-print.mlir +++ b/mlir/test/IR/pretty-resources-print.mlir @@ -13,7 +13,7 @@ // CHECK-NEXT: external_resources: { // CHECK-NEXT: external: { // CHECK-NEXT: bool: true, -// CHECK-NEXT: string: "string" +// CHECK-NEXT: string: "\22string\22" // CHECK-NEXT: }, // CHECK-NEXT: other_stuff: { // CHECK-NEXT: bool: true @@ -32,7 +32,7 @@ external: { blob: "0x08000000010000000000000002000000000000000300000000000000", bool: true, - string: "string" + string: "\"string\"" // with escape characters }, other_stuff: { bool: true