make ast-print handle random non-printable characters correctly with octal escapes.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62337 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp
index ea96411..96f5403 100644
--- a/lib/AST/StmtPrinter.cpp
+++ b/lib/AST/StmtPrinter.cpp
@@ -663,9 +663,19 @@
 
   // FIXME: this doesn't print wstrings right.
   for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
-    switch (Str->getStrData()[i]) {
-    default: OS << Str->getStrData()[i]; break;
-    // Handle some common ones to make dumps prettier.
+    unsigned char Char = Str->getStrData()[i];
+    
+    switch (Char) {
+    default:
+      if (isprint(Char))
+        OS << (char)Char;
+      else  // Output anything hard as an octal escape.
+        OS << '\\'
+        << (char)('0'+ ((Char >> 6) & 7))
+        << (char)('0'+ ((Char >> 3) & 7))
+        << (char)('0'+ ((Char >> 0) & 7));
+      break;
+    // Handle some common non-printable cases to make dumps prettier.
     case '\\': OS << "\\\\"; break;
     case '"': OS << "\\\""; break;
     case '\n': OS << "\\n"; break;