ctetreau created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
ctetreau added reviewers: efriedma, apazos, zzheng, dexonsmith, rnk.

Modify clang::FileManager::FixupRelativePath to use the existing path
separator style, if one exists. Prior to this change, if a path is set
for the FileSystemOpts workingDir that does not match the native path
separator style, this can result in a path with mixed separators. This
was causing an assertion failure in
clang::test/ClangScanDeps/vfsoverlay.cpp on my machine.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81041

Files:
  clang/lib/Basic/FileManager.cpp


Index: clang/lib/Basic/FileManager.cpp
===================================================================
--- clang/lib/Basic/FileManager.cpp
+++ clang/lib/Basic/FileManager.cpp
@@ -423,6 +423,8 @@
 }
 
 bool FileManager::FixupRelativePath(SmallVectorImpl<char> &path) const {
+  using namespace llvm::sys::path;
+
   StringRef pathRef(path.data(), path.size());
 
   if (FileSystemOpts.WorkingDir.empty()
@@ -430,7 +432,19 @@
     return false;
 
   SmallString<128> NewPath(FileSystemOpts.WorkingDir);
-  llvm::sys::path::append(NewPath, pathRef);
+  Style sepStyle = Style::native;
+
+  for (char c : NewPath) {
+    if (is_separator(c, Style::windows)) {
+      sepStyle = Style::windows;
+      break;
+    } else if (is_separator(c, Style::posix)) {
+      sepStyle = Style::posix;
+      break;
+    }
+  }
+
+  append(NewPath, sepStyle, pathRef);
   path = NewPath;
   return true;
 }


Index: clang/lib/Basic/FileManager.cpp
===================================================================
--- clang/lib/Basic/FileManager.cpp
+++ clang/lib/Basic/FileManager.cpp
@@ -423,6 +423,8 @@
 }
 
 bool FileManager::FixupRelativePath(SmallVectorImpl<char> &path) const {
+  using namespace llvm::sys::path;
+
   StringRef pathRef(path.data(), path.size());
 
   if (FileSystemOpts.WorkingDir.empty()
@@ -430,7 +432,19 @@
     return false;
 
   SmallString<128> NewPath(FileSystemOpts.WorkingDir);
-  llvm::sys::path::append(NewPath, pathRef);
+  Style sepStyle = Style::native;
+
+  for (char c : NewPath) {
+    if (is_separator(c, Style::windows)) {
+      sepStyle = Style::windows;
+      break;
+    } else if (is_separator(c, Style::posix)) {
+      sepStyle = Style::posix;
+      break;
+    }
+  }
+
+  append(NewPath, sepStyle, pathRef);
   path = NewPath;
   return true;
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to