This is an archive of the discontinued LLVM Phabricator instance.

[clang][deps] Avoid leaking modulemap paths across unrelated imports
ClosedPublic

Authored by benlangmuir on Nov 14 2022, 2:56 PM.

Details

Summary

Use a FileEntryRef when retrieving modulemap paths in the scanner so that we use a path compatible with the original module import, rather than a FileEntry which can allow unrelated modules to leak paths into how we build a module due to FileManager mutating the path.

Note: the current change prevents an "unrelated" path, but does not change how VFS mapped paths are handled (which would be calling getNameAsRequested) nor canonicalize the path. In that sense, this is a narrower version of https://reviews.llvm.org/D135636 that should not be blocked by the VFS concerns.

Diff Detail

Event Timeline

benlangmuir created this revision.Nov 14 2022, 2:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 14 2022, 2:56 PM
benlangmuir requested review of this revision.Nov 14 2022, 2:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 14 2022, 2:56 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
jansvoboda11 accepted this revision.Nov 14 2022, 3:22 PM

LGTM, thanks!

clang/lib/Serialization/ASTWriter.cpp
1560–1561

Do you think resolving this fixme warrants separate patch?

This revision is now accepted and ready to land.Nov 14 2022, 3:22 PM
benlangmuir added inline comments.Nov 14 2022, 3:30 PM
clang/lib/Serialization/ASTWriter.cpp
1560–1561

Good catch, I'll remove this FIXME. Usually diagnostics use the on-disk path, so I think FileEntryRef::getName is correct here and we don't need to change it to getNameAsRequested.

  • Removed outdated FIXME
  • Ran clang-format
  • Attempt to fix Windows test failure: the StringSet of paths was failing to match, so switch to DenseSet<FileEntry *>. Note: the path that ends up in the command-line is from a FileEntryRef, but the equality of FileEntry * is how we check whether to include it at all. For now we just re-lookup the paths which should always hit the path cache in FIleManager. A future improvement could be to track FileEntryRef for the module map paths directly instead of strings.