Convert from Windows to Unix paths in sys::path::native.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 8 Aug 2014 21:29:34 +0000 (21:29 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 8 Aug 2014 21:29:34 +0000 (21:29 +0000)
Part of pr20544. Test to follow in a second.

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

lib/Support/Path.cpp

index 2dd6741c73508b93c22029b03fd4f9930c580bbb..bc6543a572209d235bd56e26b77f7616cffd95f3 100644 (file)
@@ -540,9 +540,19 @@ void native(const Twine &path, SmallVectorImpl<char> &result) {
   native(result);
 }
 
-void native(SmallVectorImpl<char> &path) {
+void native(SmallVectorImpl<char> &Path) {
 #ifdef LLVM_ON_WIN32
   std::replace(path.begin(), path.end(), '/', '\\');
+#else
+  for (auto PI = Path.begin(), PE = Path.end(); PI < PE; ++PI) {
+    if (*PI == '\\') {
+      auto PN = PI + 1;
+      if (PN < PE && *PN == '\\')
+        ++PI; // increment once, the for loop will move over the escaped slash
+      else
+        *PI = '/';
+    }
+  }
 #endif
 }