rjmccall added a comment. I'm not sure what you're saying. The existing function PrintEscapedString in AsmWriter.cpp does exactly what you want; you just need to call it from getAsString as well. You'll need to expose it somewhere, of course. https://reviews.llvm.org/D23792