Index: mlir/lib/IR/AsmPrinter.cpp =================================================================== --- mlir/lib/IR/AsmPrinter.cpp +++ mlir/lib/IR/AsmPrinter.cpp @@ -1516,8 +1516,9 @@ return; } - // TODO: escape the symbol name, it could contain " characters. - os << "<\"" << symString << "\">"; + os << "<\""; + llvm::printEscapedString(symString, os); + os << "\">"; } /// Returns true if the given string can be represented as a bare identifier. Index: mlir/test/IR/parser.mlir =================================================================== --- mlir/test/IR/parser.mlir +++ mlir/test/IR/parser.mlir @@ -1239,6 +1239,12 @@ return } +// CHECK-LABEL: func private @parse_opaque_attr_escape +func private @parse_opaque_attr_escape() { + // CHECK: value = #foo<"\22escaped\\\0A\22"> + "foo.constant"() {value = #foo<"\"escaped\\\n\"">} : () -> () +} + // CHECK-LABEL: func private @string_attr_name // CHECK-SAME: {"0 . 0", nested = {"0 . 0"}} func private @string_attr_name() attributes {"0 . 0", nested = {"0 . 0"}}