Implement a FIXME: correctly stringify filenames generated by __LINE__.

llvm-svn: 38622
diff --git a/clang/Lex/Preprocessor.cpp b/clang/Lex/Preprocessor.cpp
index a8890f0..2361c40 100644
--- a/clang/Lex/Preprocessor.cpp
+++ b/clang/Lex/Preprocessor.cpp
@@ -622,8 +622,16 @@
       }
     }
     
-    // FIXME: Escape this filename correctly.
-    std::string FN = '"' + SourceMgr.getSourceName(Loc) + '"';
+    // Escape this filename.  Turn '\' -> '\\' '"' -> '\"'
+    std::string FN = SourceMgr.getSourceName(Loc);
+    for (unsigned i = 0, e = FN.size(); i != e; ++i)
+      if (FN[i] == '\\' || FN[i] == '"') {
+        FN.insert(FN.begin()+i, '\\');
+        ++i; ++e;
+      }
+    
+    // Add quotes.
+    FN = '"' + FN + '"';
     Tok.SetKind(tok::string_literal);
     Tok.SetLength(FN.size());
     Tok.SetLocation(ScratchBuf->getToken(&FN[0], FN.size(), Tok.getLocation()));