xbolva00 updated this revision to Diff 165052.
xbolva00 added a comment.

- Fixed failing test


https://reviews.llvm.org/D51847

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


Index: test/Frontend/dependency-gen-escaping.c
===================================================================
--- test/Frontend/dependency-gen-escaping.c
+++ test/Frontend/dependency-gen-escaping.c
@@ -21,7 +21,7 @@
 // Backslash followed by # or space should escape both characters, because
 // that's what GNU Make wants.  GCC does the right thing with space, but not
 // #, so Clang does too. (There should be 3 backslashes before the #.)
-// SEP2F: a\b\\#c\\\ d.h
+// SEP2F: a{{[/\\]}}b{{[/\\]}}\#c{{/|\\\\}}\ d.h
 // With -fms-compatibility, Backslashes in #include are treated as path 
separators.
 // Backslashes are given in the emission for special characters, like 0x20 or 
0x23.
 // SEP5C: a{{[/\\]}}b{{[/\\]}}\#c{{/|\\\\}}\ d.h
Index: lib/Frontend/DependencyFile.cpp
===================================================================
--- lib/Frontend/DependencyFile.cpp
+++ lib/Frontend/DependencyFile.cpp
@@ -386,28 +386,32 @@
 /// for Windows file-naming info.
 static void PrintFilename(raw_ostream &OS, StringRef Filename,
                           DependencyOutputFormat OutputFormat) {
+  // Convert filename to platform native path
+  llvm::SmallString<256> NativePath;
+  llvm::sys::path::native(Filename.str(), NativePath);
+
   if (OutputFormat == DependencyOutputFormat::NMake) {
     // Add quotes if needed. These are the characters listed as "special" to
     // NMake, that are legal in a Windows filespec, and that could cause
     // misinterpretation of the dependency string.
-    if (Filename.find_first_of(" #${}^!") != StringRef::npos)
-      OS << '\"' << Filename << '\"';
+    if (NativePath.find_first_of(" #${}^!") != StringRef::npos)
+      OS << '\"' << NativePath << '\"';
     else
-      OS << Filename;
+      OS << NativePath;
     return;
   }
   assert(OutputFormat == DependencyOutputFormat::Make);
-  for (unsigned i = 0, e = Filename.size(); i != e; ++i) {
-    if (Filename[i] == '#') // Handle '#' the broken gcc way.
+  for (unsigned i = 0, e = NativePath.size(); i != e; ++i) {
+    if (NativePath[i] == '#') // Handle '#' the broken gcc way.
       OS << '\\';
-    else if (Filename[i] == ' ') { // Handle space correctly.
+    else if (NativePath[i] == ' ') { // Handle space correctly.
       OS << '\\';
       unsigned j = i;
-      while (j > 0 && Filename[--j] == '\\')
+      while (j > 0 && NativePath[--j] == '\\')
         OS << '\\';
-    } else if (Filename[i] == '$') // $ is escaped by $$.
+    } else if (NativePath[i] == '$') // $ is escaped by $$.
       OS << '$';
-    OS << Filename[i];
+    OS << NativePath[i];
   }
 }
 


Index: test/Frontend/dependency-gen-escaping.c
===================================================================
--- test/Frontend/dependency-gen-escaping.c
+++ test/Frontend/dependency-gen-escaping.c
@@ -21,7 +21,7 @@
 // Backslash followed by # or space should escape both characters, because
 // that's what GNU Make wants.  GCC does the right thing with space, but not
 // #, so Clang does too. (There should be 3 backslashes before the #.)
-// SEP2F: a\b\\#c\\\ d.h
+// SEP2F: a{{[/\\]}}b{{[/\\]}}\#c{{/|\\\\}}\ d.h
 // With -fms-compatibility, Backslashes in #include are treated as path separators.
 // Backslashes are given in the emission for special characters, like 0x20 or 0x23.
 // SEP5C: a{{[/\\]}}b{{[/\\]}}\#c{{/|\\\\}}\ d.h
Index: lib/Frontend/DependencyFile.cpp
===================================================================
--- lib/Frontend/DependencyFile.cpp
+++ lib/Frontend/DependencyFile.cpp
@@ -386,28 +386,32 @@
 /// for Windows file-naming info.
 static void PrintFilename(raw_ostream &OS, StringRef Filename,
                           DependencyOutputFormat OutputFormat) {
+  // Convert filename to platform native path
+  llvm::SmallString<256> NativePath;
+  llvm::sys::path::native(Filename.str(), NativePath);
+
   if (OutputFormat == DependencyOutputFormat::NMake) {
     // Add quotes if needed. These are the characters listed as "special" to
     // NMake, that are legal in a Windows filespec, and that could cause
     // misinterpretation of the dependency string.
-    if (Filename.find_first_of(" #${}^!") != StringRef::npos)
-      OS << '\"' << Filename << '\"';
+    if (NativePath.find_first_of(" #${}^!") != StringRef::npos)
+      OS << '\"' << NativePath << '\"';
     else
-      OS << Filename;
+      OS << NativePath;
     return;
   }
   assert(OutputFormat == DependencyOutputFormat::Make);
-  for (unsigned i = 0, e = Filename.size(); i != e; ++i) {
-    if (Filename[i] == '#') // Handle '#' the broken gcc way.
+  for (unsigned i = 0, e = NativePath.size(); i != e; ++i) {
+    if (NativePath[i] == '#') // Handle '#' the broken gcc way.
       OS << '\\';
-    else if (Filename[i] == ' ') { // Handle space correctly.
+    else if (NativePath[i] == ' ') { // Handle space correctly.
       OS << '\\';
       unsigned j = i;
-      while (j > 0 && Filename[--j] == '\\')
+      while (j > 0 && NativePath[--j] == '\\')
         OS << '\\';
-    } else if (Filename[i] == '$') // $ is escaped by $$.
+    } else if (NativePath[i] == '$') // $ is escaped by $$.
       OS << '$';
-    OS << Filename[i];
+    OS << NativePath[i];
   }
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATC... Dávid Bolvanský via Phabricator via cfe-commits
  • [PATC... Zachary Turner via Phabricator via cfe-commits
  • [PATC... Dávid Bolvanský via Phabricator via cfe-commits
    • ... Zachary Turner via cfe-commits
      • ... Zachary Turner via Phabricator via cfe-commits
  • [PATC... Dávid Bolvanský via Phabricator via cfe-commits
  • [PATC... Zachary Turner via Phabricator via cfe-commits
  • [PATC... Dávid Bolvanský via Phabricator via cfe-commits
  • [PATC... Zachary Turner via Phabricator via cfe-commits
  • [PATC... Dávid Bolvanský via Phabricator via cfe-commits
  • [PATC... Dávid Bolvanský via Phabricator via cfe-commits
    • ... Zachary Turner via cfe-commits
      • ... Mailing List "cfe-commits" via Phabricator via cfe-commits
  • [PATC... Dávid Bolvanský via Phabricator via cfe-commits
  • [PATC... Dávid Bolvanský via Phabricator via cfe-commits

Reply via email to