]> granicus.if.org Git - clang/commitdiff
Properly escape filenames in line directives.
authorEli Friedman <eli.friedman@gmail.com>
Thu, 29 Aug 2013 01:42:42 +0000 (01:42 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Thu, 29 Aug 2013 01:42:42 +0000 (01:42 +0000)
Fixes PR17018.  Only partial test coverage because I don't want
to try to write a test which generates a file whose name contains a newline.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189557 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/PrintPreprocessedOutput.cpp
lib/Rewrite/Frontend/InclusionRewriter.cpp
test/Preprocessor/line-directive-output.c

index 83b2a271ec360e63542ad2578c1758bf8f68ecaa..e0ec08fb90a1b93909aec1d4e758ec61a029bffb 100644 (file)
@@ -190,11 +190,11 @@ void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo,
   // Emit #line directives or GNU line markers depending on what mode we're in.
   if (UseLineDirective) {
     OS << "#line" << ' ' << LineNo << ' ' << '"';
-    OS.write(CurFilename.data(), CurFilename.size());
+    OS.write_escaped(CurFilename);
     OS << '"';
   } else {
     OS << '#' << ' ' << LineNo << ' ' << '"';
-    OS.write(CurFilename.data(), CurFilename.size());
+    OS.write_escaped(CurFilename);
     OS << '"';
 
     if (ExtraLen)
@@ -285,7 +285,6 @@ void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc,
 
   CurFilename.clear();
   CurFilename += UserLoc.getFilename();
-  Lexer::Stringify(CurFilename);
   FileType = NewFileType;
 
   if (DisableLineMarkers) {
index a2297f9179d33c0fa661383003ced297dd07bb78..3fba6905e1ef9208b1590cd87922c0c9c13901de 100644 (file)
@@ -114,7 +114,9 @@ void InclusionRewriter::WriteLineInfo(const char *Filename, int Line,
   } else {
     // Use GNU linemarkers as described here:
     // http://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html
-    OS << '#' << ' ' << Line << ' ' << '"' << Filename << '"';
+    OS << '#' << ' ' << Line << ' ' << '"';
+    OS.write_escaped(Filename);
+    OS << '"';
     if (!Extra.empty())
       OS << Extra;
     if (FileType == SrcMgr::C_System)
index bd3ea949ebd9686e20eca5db3f88d546656934be..5c0aef8b32198eaa04b9cf6fbd4f1f5fc4849791 100644 (file)
@@ -73,3 +73,6 @@ extern int z;
 # 42 "A.c"
 # 44 "A.c"
 # 49 "A.c"
+
+// CHECK: # 50 "a\n.c"
+# 50 "a\012.c"