[llvm] 7e2afe8 - [Windows] Don't try to wildcard expand paths starting with \\?\

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 1 01:26:42 PDT 2022


Author: Martin Storsjö
Date: 2022-06-01T11:25:49+03:00
New Revision: 7e2afe83e88d5d50c878492f27c69c6850e31582

URL: https://github.com/llvm/llvm-project/commit/7e2afe83e88d5d50c878492f27c69c6850e31582
DIFF: https://github.com/llvm/llvm-project/commit/7e2afe83e88d5d50c878492f27c69c6850e31582.diff

LOG: [Windows] Don't try to wildcard expand paths starting with \\?\

Paths that start with `\\?\` are absolute paths, and aren't expected
to be used with wildcard expressions.

Previously, the `?` at the start of the path triggered the condition
for a potential wildcard, which caused the path to be split and
reassembled. In builds with `LLVM_WINDOWS_PREFER_FORWARD_SLASH=ON`,
this caused a path like e.g. `\\?\D:\tmp\hello.cpp` to be reassembled
into `\\?\D:\tmp/hello.cpp` which isn't a valid path (as such
absolute paths must use backslashes consistently).

This fixes https://github.com/mstorsjo/llvm-mingw/issues/280.

I'm not sure if there's any straightforward way to add a test
for this case, unfortunately.

Differential Revision: https://reviews.llvm.org/D126675

Added: 
    

Modified: 
    llvm/lib/Support/Windows/Process.inc

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/Windows/Process.inc b/llvm/lib/Support/Windows/Process.inc
index e4156747ca686..b0c55a77bc93e 100644
--- a/llvm/lib/Support/Windows/Process.inc
+++ b/llvm/lib/Support/Windows/Process.inc
@@ -156,9 +156,10 @@ static std::error_code WildcardExpand(StringRef Arg,
 
   // Don't expand Arg if it does not contain any wildcard characters. This is
   // the common case. Also don't wildcard expand /?. Always treat it as an
-  // option.
+  // option. Paths that start with \\?\ are absolute paths, and aren't
+  // expected to be used with wildcard expressions.
   if (Arg.find_first_of("*?") == StringRef::npos || Arg == "/?" ||
-      Arg == "-?") {
+      Arg == "-?" || Arg.startswith("\\\\?\\")) {
     Args.push_back(Arg.data());
     return EC;
   }


        


More information about the llvm-commits mailing list