This is an archive of the discontinued LLVM Phabricator instance.

Rewrite MSVC toolchain discovery with VFS
ClosedPublic

Authored by aeubanks on Feb 24 2021, 8:33 PM.

Details

Summary

This fixes an issue where the toolchain discovery doesn't respect the
VFS's current working directory, specifically clangd not respecting a
relative /winsysroot.

Diff Detail

Event Timeline

aeubanks created this revision.Feb 24 2021, 8:33 PM
aeubanks requested review of this revision.Feb 24 2021, 8:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 24 2021, 8:33 PM

not exactly sure how to test this...

Re test: Maybe some combination of -ivfsoverlay (as a /clang: flag I suppose) and /winsysroot can be used to test this?

(aside: Do you know if the sysroot vs clangd stuff works on non-win? I happened to see https://bugs.llvm.org/show_bug.cgi?id=27909)

In Linux.cpp I only see uses of VFS, no uses of llvm::sys::fs so I think it should work there. And using clangd on vscode on Linux, it works with --sysroot.

Looks like -ivfsoverlay doesn't take effect in the driver. And -working-directory also changes the program's working directory since there's no vfs in the driver so it uses the actual fs.

rnk accepted this revision.Feb 25 2021, 11:25 AM

lgtm

I think we also do some registry searching, which is not virtualized. I guess those are all absolute references and paths, so if you use clangd on the same machine, it should just work.

It occurs to me that this code is suddenly much more unit testable now that it uses a VFS, but it doesn't seem reasonable to request unit tests.

clang/lib/Driver/ToolChains/MSVC.cpp
361

This function already takes TC, which has TC.getVFS, so I think you can skip the extra parameter.

This revision is now accepted and ready to land.Feb 25 2021, 11:25 AM
aeubanks updated this revision to Diff 326455.Feb 25 2021, 11:36 AM

remove extra parameter

We don't use a VFS for registry searching because we just take the value given by the registry and pass it on, rather than checking for the existence of specific files/directories. But yeah they're probably all absolute paths so it shouldn't matter in those cases.

This revision was landed with ongoing or failed builds.Feb 25 2021, 12:51 PM
This revision was automatically updated to reflect the committed changes.

Thanks for fixing this :)