summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2013-08-29 01:42:42 +0000
committerEli Friedman <eli.friedman@gmail.com>2013-08-29 01:42:42 +0000
commit80e45b8cd4cce838cd314cbbe83bea819e6e1d1e (patch)
treed352ebdecdaafc3edaad2d86e906adc79e355875 /clang
parent9a83a76b1b83e74143599717a930f27360355a7f (diff)
downloadbcm5719-llvm-80e45b8cd4cce838cd314cbbe83bea819e6e1d1e.tar.gz
bcm5719-llvm-80e45b8cd4cce838cd314cbbe83bea819e6e1d1e.zip
Properly escape filenames in line directives.
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. llvm-svn: 189557
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Frontend/PrintPreprocessedOutput.cpp5
-rw-r--r--clang/lib/Rewrite/Frontend/InclusionRewriter.cpp4
-rw-r--r--clang/test/Preprocessor/line-directive-output.c3
3 files changed, 8 insertions, 4 deletions
diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
index 83b2a271ec3..e0ec08fb90a 100644
--- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -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) {
diff --git a/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp b/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp
index a2297f9179d..3fba6905e1e 100644
--- a/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp
+++ b/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp
@@ -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)
diff --git a/clang/test/Preprocessor/line-directive-output.c b/clang/test/Preprocessor/line-directive-output.c
index bd3ea949ebd..5c0aef8b321 100644
--- a/clang/test/Preprocessor/line-directive-output.c
+++ b/clang/test/Preprocessor/line-directive-output.c
@@ -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"
OpenPOWER on IntegriCloud