This is an archive of the discontinued LLVM Phabricator instance.

Improve VFS compatibility on Windows
ClosedPublic

Authored by amccarth on Nov 7 2019, 11:40 AM.

Details

Summary

Keys in a virtual file system can be in Posix or Windows form or even a combination of the two. Many VFS tests (and a few Clang tests) were XFAILed on Windows because of false negatives when comparing paths.

First, we default CaseSenstive to false on Windows. This allows drive letters like "D:" to match "d:". Windows filesystems are, by default, case insensitive, so this makes sense even beyond the drive letter.

Second, we allow slashes to match backslashes when they're used as the root component of a path.

Both of these changes are limited to RedirectingFileSystems, so there's little chance of affecting other path handling.

These changes allow eleven of the VFS tests to pass on Windows as well as three other Clang tests, so they have re-enabled (partially addressing PR43272).

Diff Detail

Event Timeline

amccarth created this revision.Nov 7 2019, 11:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 7 2019, 11:40 AM
rnk added a comment.Nov 7 2019, 1:26 PM

This looks good to me. I had one suggestion, and I would also like to hear from another reviewer who has more ownership over VFS.

llvm/include/llvm/Support/VirtualFileSystem.h
657

IIUC, this method receives path components, which must not contain path separators, or the root path component, \ or /. Is there some way to express that invariant? Maybe just comment like "A path component must not contain path separators, unless it is the root component, which is represented as a single path separator," or an assert with the same effect.

llvm/lib/Support/VirtualFileSystem.cpp
1666

Unrelated, but I wonder if this needs to be while instead of if to handle repeated foo/./././bar.

amccarth marked 3 inline comments as done.Nov 13 2019, 11:25 AM

Friendly ping for any VFS experts to comment.

llvm/include/llvm/Support/VirtualFileSystem.h
657

I felt the assumption is implicit in "path component," but I've made the comment more explicit. Note that the slash/backslash checks are checking the entire string. I hope that reinforces the idea that these would be path roots.

llvm/lib/Support/VirtualFileSystem.cpp
1666

I'm fairly certain I'll be looking into this further as I try to resolve the remaining VFS tests that don't run on Windows. I'd love to eliminate another #ifdef, but I want to keep this patch focused.

amccarth updated this revision to Diff 229144.Nov 13 2019, 11:26 AM
amccarth marked an inline comment as done.

Modified comment per feedback.

Bigcheese accepted this revision.Nov 13 2019, 1:52 PM
Bigcheese added subscribers: JDevlieghere, benlangmuir.

lgtm. Looking at the blame it would be best if @JDevlieghere @vsapsai or @benlangmuir could take a look also.

This revision is now accepted and ready to land.Nov 13 2019, 1:52 PM

There is one issue with a comment, apart of that everything looks good to me. Looked into replacing slash and backslash literals with calls to llvm::sys::path::get_separator or llvm::sys::path::is_separator but in my attempts failed to improve existing patch.

llvm/include/llvm/Support/VirtualFileSystem.h
535

I believe changing default CaseSensitive value makes this comment incorrect. Have no strong opinion on making case-insensitive default on Windows because a better requirement is for VFS generators to specify 'case-sensitive' explicitly instead of relying on default values.

amccarth marked an inline comment as done.Nov 13 2019, 4:02 PM

Thanks for the review.

There is one issue with a comment, apart of that everything looks good to me. Looked into replacing slash and backslash literals with calls to llvm::sys::path::get_separator or llvm::sys::path::is_separator but in my attempts failed to improve existing patch.

Yes, I originally started down the path of trying to "normalize" path styles (like slash direction), but that always led to collateral damage because we literally have situations where a path is a hybrid of both Windows and Posix. Rather than writing Windows and Posix versions of the tests, this patch takes the approach that choosing a path style is out-of-scope, which I'm told is Clang's general strategy.

llvm/include/llvm/Support/VirtualFileSystem.h
535

Make CaseSensitive system-dependent aligns with UseCanonicalizePaths, so this feels pretty consistent. (Perhaps in a future path, we can fix both of those.) In the mean time, I'll update the comment.

amccarth updated this revision to Diff 229197.Nov 13 2019, 4:05 PM
amccarth marked an inline comment as done.

Corrected comment about default for case sensitivity.

vsapsai accepted this revision.Nov 13 2019, 4:15 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptNov 14 2019, 8:53 AM