Rebase on top of the other depfile change.

http://reviews.llvm.org/D9208

Files:
  tools/clang/lib/Frontend/DependencyFile.cpp
  tools/clang/test/Frontend/dependency-gen-escaping.c

Index: tools/clang/lib/Frontend/DependencyFile.cpp
===================================================================
--- tools/clang/lib/Frontend/DependencyFile.cpp
+++ tools/clang/lib/Frontend/DependencyFile.cpp
@@ -293,8 +293,11 @@
 }
 
 /// PrintFilename - GCC escapes spaces, # and $, but apparently not ' or " or
-/// other scary characters. NMake/Jom has a different set of scary characters,
-/// but wraps filespecs in double-quotes to avoid misinterpreting them;
+/// other scary characters, because they aren't special to Make.  If one or
+/// more backslashes immediately precedes space or #, it is also escaped;
+/// backslash in other places is not escaped.
+/// NMake/Jom has a different set of scary characters, but wraps filespecs in
+/// double-quotes to avoid misinterpreting them; see
 /// https://msdn.microsoft.com/en-us/library/dd9y37ha.aspx for NMake info,
 /// 
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
 /// for Windows file-naming info.
@@ -311,9 +314,12 @@
     return;
   }
   for (unsigned i = 0, e = Filename.size(); i != e; ++i) {
-    if (Filename[i] == ' ' || Filename[i] == '#')
+    if (Filename[i] == ' ' || Filename[i] == '#') {
       OS << '\\';
-    else if (Filename[i] == '$') // $ is escaped by $$.
+      unsigned j = i;
+      while (j > 0 && Filename[--j] == '\\')
+        OS << '\\';
+    } else if (Filename[i] == '$') // $ is escaped by $$.
       OS << '$';
     OS << Filename[i];
   }
Index: tools/clang/test/Frontend/dependency-gen-escaping.c
===================================================================
--- tools/clang/test/Frontend/dependency-gen-escaping.c
+++ tools/clang/test/Frontend/dependency-gen-escaping.c
@@ -5,14 +5,17 @@
 // CHECK: \ \ \ \ .h
 // CHECK: $$$$.h
 // CHECK: \#\#.h
+// CHECK: a\b\\\#c\\\ d.h
 // NMAKE: "    .h"
 // NMAKE: "$$.h"
 // NMAKE: "##.h"
+// NMAKE: "a\b\#c\ d.h"
 // NMAKE-NOT: "
 // NMAKE: normal.h
 // NMAKE-NOT: "
 
 #include "    .h"
 #include "$$.h"
 #include "##.h"
+#include "a\b\#c\ d.h"
 #include "normal.h"

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: tools/clang/lib/Frontend/DependencyFile.cpp
===================================================================
--- tools/clang/lib/Frontend/DependencyFile.cpp
+++ tools/clang/lib/Frontend/DependencyFile.cpp
@@ -293,8 +293,11 @@
 }
 
 /// PrintFilename - GCC escapes spaces, # and $, but apparently not ' or " or
-/// other scary characters. NMake/Jom has a different set of scary characters,
-/// but wraps filespecs in double-quotes to avoid misinterpreting them;
+/// other scary characters, because they aren't special to Make.  If one or
+/// more backslashes immediately precedes space or #, it is also escaped;
+/// backslash in other places is not escaped.
+/// NMake/Jom has a different set of scary characters, but wraps filespecs in
+/// double-quotes to avoid misinterpreting them; see
 /// https://msdn.microsoft.com/en-us/library/dd9y37ha.aspx for NMake info,
 /// https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
 /// for Windows file-naming info.
@@ -311,9 +314,12 @@
     return;
   }
   for (unsigned i = 0, e = Filename.size(); i != e; ++i) {
-    if (Filename[i] == ' ' || Filename[i] == '#')
+    if (Filename[i] == ' ' || Filename[i] == '#') {
       OS << '\\';
-    else if (Filename[i] == '$') // $ is escaped by $$.
+      unsigned j = i;
+      while (j > 0 && Filename[--j] == '\\')
+        OS << '\\';
+    } else if (Filename[i] == '$') // $ is escaped by $$.
       OS << '$';
     OS << Filename[i];
   }
Index: tools/clang/test/Frontend/dependency-gen-escaping.c
===================================================================
--- tools/clang/test/Frontend/dependency-gen-escaping.c
+++ tools/clang/test/Frontend/dependency-gen-escaping.c
@@ -5,14 +5,17 @@
 // CHECK: \ \ \ \ .h
 // CHECK: $$$$.h
 // CHECK: \#\#.h
+// CHECK: a\b\\\#c\\\ d.h
 // NMAKE: "    .h"
 // NMAKE: "$$.h"
 // NMAKE: "##.h"
+// NMAKE: "a\b\#c\ d.h"
 // NMAKE-NOT: "
 // NMAKE: normal.h
 // NMAKE-NOT: "
 
 #include "    .h"
 #include "$$.h"
 #include "##.h"
+#include "a\b\#c\ d.h"
 #include "normal.h"
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to