[PATCH] D71092: [VFS] Use path canonicalization on all paths

2019-12-05 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I would add, take a look at the existing unit tests 
(llvm/unittests/Support/VirtualFileSystemTests.cpp) and audit for _WIN32 ifdefs 
that we can remove after this change.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71092/new/

https://reviews.llvm.org/D71092



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71092: [VFS] Use path canonicalization on all paths

2019-12-05 Thread Adrian McCarthy via Phabricator via cfe-commits
amccarth planned changes to this revision.
amccarth added a comment.

Hold off on this one.  It needs an explicit test for canonicalization.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71092/new/

https://reviews.llvm.org/D71092



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71092: [VFS] Use path canonicalization on all paths

2019-12-05 Thread Adrian McCarthy via Phabricator via cfe-commits
amccarth created this revision.
amccarth added reviewers: rnk, vsapsai, arphaman.
Herald added subscribers: llvm-commits, dexonsmith, hiraditya.
Herald added a project: LLVM.

The virtual file system had an option to eliminate dots from paths (e.g., 
`/foo/./bar` -> `/foo/bar`).  Because of differences in Windows-style paths, 
this was disabled by default on Windows.

Once the earlier VFS portability fixes land we were just one away from enable 
canonicalization on Windows.  (See https://reviews.llvm.org/D70701)

Note that the old UsePathCanonicalization member could never be changed from 
the default, so now that we canonicalize on all systems, there was no need to 
keep the option nor the alternate code paths, so this patch deletes all of that.

Tested with ninja check-clang.


https://reviews.llvm.org/D71092

Files:
  clang/test/VFS/external-names.c
  llvm/include/llvm/Support/VirtualFileSystem.h
  llvm/lib/Support/VirtualFileSystem.cpp

Index: llvm/lib/Support/VirtualFileSystem.cpp
===
--- llvm/lib/Support/VirtualFileSystem.cpp
+++ llvm/lib/Support/VirtualFileSystem.cpp
@@ -1341,16 +1341,12 @@
   return nullptr;
 
 NameValueNode = I.getValue();
-if (FS->UseCanonicalizedPaths) {
-  SmallString<256> Path(Value);
-  // Guarantee that old YAML files containing paths with ".." and "."
-  // are properly canonicalized before read into the VFS.
-  Path = sys::path::remove_leading_dotslash(Path);
-  sys::path::remove_dots(Path, /*remove_dot_dot=*/true);
-  Name = Path.str();
-} else {
-  Name = Value;
-}
+// Guarantee that old YAML files containing paths with ".." and "."
+// are properly canonicalized before read into the VFS.
+SmallString<256> Path(Value);
+Path = sys::path::remove_leading_dotslash(Path);
+sys::path::remove_dots(Path, /*remove_dot_dot=*/true);
+Name = Path.str();
   } else if (Key == "type") {
 if (!parseScalarString(I.getValue(), Value, Buffer))
   return nullptr;
@@ -1403,12 +1399,11 @@
   FullPath = Value;
 }
 
-if (FS->UseCanonicalizedPaths) {
-  // Guarantee that old YAML files containing paths with ".." and "."
-  // are properly canonicalized before read into the VFS.
-  FullPath = sys::path::remove_leading_dotslash(FullPath);
-  sys::path::remove_dots(FullPath, /*remove_dot_dot=*/true);
-}
+// Guarantee that old YAML files containing paths with ".." and "."
+// are properly canonicalized before read into the VFS.
+FullPath = sys::path::remove_leading_dotslash(FullPath);
+sys::path::remove_dots(FullPath, /*remove_dot_dot=*/true);
+
 ExternalContentsPath = FullPath.str();
   } else if (Key == "use-external-name") {
 bool Val;
@@ -1653,13 +1648,11 @@
   if (std::error_code EC = makeAbsolute(Path))
 return EC;
 
-  // Canonicalize path by removing ".", "..", "./", etc components. This is
-  // a VFS request, do bot bother about symlinks in the path components
+  // Canonicalize path by removing ".", "..", "./", components. This is
+  // a VFS request, do not bother about symlinks in the path components
   // but canonicalize in order to perform the correct entry search.
-  if (UseCanonicalizedPaths) {
-Path = sys::path::remove_leading_dotslash(Path);
-sys::path::remove_dots(Path, /*remove_dot_dot=*/true);
-  }
+  Path = sys::path::remove_leading_dotslash(Path);
+  sys::path::remove_dots(Path, /*remove_dot_dot=*/true);
 
   if (Path.empty())
 return make_error_code(llvm::errc::invalid_argument);
@@ -1679,16 +1672,9 @@
 RedirectingFileSystem::lookupPath(sys::path::const_iterator Start,
   sys::path::const_iterator End,
   RedirectingFileSystem::Entry *From) const {
-#ifndef _WIN32
   assert(!isTraversalComponent(*Start) &&
  !isTraversalComponent(From->getName()) &&
  "Paths should not contain traversal components");
-#else
-  // FIXME: this is here to support windows, remove it once canonicalized
-  // paths become globally default.
-  if (Start->equals("."))
-++Start;
-#endif
 
   StringRef FromName = From->getName();
 
Index: llvm/include/llvm/Support/VirtualFileSystem.h
===
--- llvm/include/llvm/Support/VirtualFileSystem.h
+++ llvm/include/llvm/Support/VirtualFileSystem.h
@@ -705,16 +705,6 @@
   bool IsFallthrough = true;
   /// @}
 
-  /// Virtual file paths and external files could be canonicalized without "..",
-  /// "." and "./" in their paths. FIXME: some unittests currently fail on
-  /// win32 when using remove_dots and remove_leading_dotslash on paths.
-  bool UseCanonicalizedPaths =
-#ifdef _WIN32
-  false;
-#else
-  true;
-#endif
-