]> granicus.if.org Git - clang/commitdiff
Escape # and $ in dependency files.
authorBenjamin Kramer <benny.kra@googlemail.com>
Tue, 2 Apr 2013 13:38:48 +0000 (13:38 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Tue, 2 Apr 2013 13:38:48 +0000 (13:38 +0000)
Fixes PR15642.

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

lib/Frontend/DependencyFile.cpp
test/Frontend/dependency-gen-escaping.c [new file with mode: 0644]

index 53ea8befbc09fff0c846344df87b6c7db8f74ad8..628def68e5e0e1a2a344939565b0467a16198d2b 100644 (file)
@@ -151,12 +151,14 @@ void DependencyFileCallback::AddFilename(StringRef Filename) {
     Files.push_back(Filename);
 }
 
-/// PrintFilename - GCC escapes spaces, but apparently not ' or " or other
-/// scary characters.
+/// PrintFilename - GCC escapes spaces, # and $, but apparently not ' or " or
+/// other scary characters.
 static void PrintFilename(raw_ostream &OS, StringRef Filename) {
   for (unsigned i = 0, e = Filename.size(); i != e; ++i) {
-    if (Filename[i] == ' ')
+    if (Filename[i] == ' ' || Filename[i] == '#')
       OS << '\\';
+    else if (Filename[i] == '$') // $ is escaped by $$.
+      OS << '$';
     OS << Filename[i];
   }
 }
diff --git a/test/Frontend/dependency-gen-escaping.c b/test/Frontend/dependency-gen-escaping.c
new file mode 100644 (file)
index 0000000..84eb242
--- /dev/null
@@ -0,0 +1,17 @@
+// REQUIRES: shell
+// PR15642
+// RUN: rm -rf %t.dir
+// RUN: mkdir -p %t.dir
+// RUN: echo > '%t.dir/    .h'
+// RUN: echo > '%t.dir/$$.h'
+// RUN: echo > '%t.dir/##.h'
+// RUN: cd %t.dir
+// RUN: %clang -MD -MF - %s -fsyntax-only -I. | FileCheck -strict-whitespace %s
+
+// CHECK: \ \ \ \ .h
+// CHECK: $$$$.h
+// CHECK: \#\#.h
+
+#include "    .h"
+#include "$$.h"
+#include "##.h"