This is an archive of the discontinued LLVM Phabricator instance.

[clang] Make `FileEntryRef::getDir()` return the as-requested `DirectoryEntryRef`
ClosedPublic

Authored by jansvoboda11 on May 24 2023, 7:42 PM.

Details

Summary

For redirected file entries, FileEntryRef::getDir() returns the parent directory entry of the target file entry. This differs from FileEntry::getDir() that always returns the parent directory that was last used to look up that file.

After switching from FileEntry to FileEntryRef for umbrella headers in D142113, this discrepancy became observable and caused Clang to emit incorrect diagnostics.

This patch changes Clang so that it always associates FileEntryRef with the parent directory that was used to look it up. This brings its behavior closer to FileEntry, but without the hacky mutation.

This also ensures that llvm::sys::path::parent_path(FileRef->getNameAsRequested()) == FileRef->getDir()->getName(). Previously, FileRef->getDir() would fall underneath the redirecting VFS into the world of on-disk paths.

Diff Detail

Event Timeline

jansvoboda11 created this revision.May 24 2023, 7:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2023, 7:42 PM
Herald added a subscriber: ributzka. · View Herald Transcript
jansvoboda11 requested review of this revision.May 24 2023, 7:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2023, 7:42 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
rmaz accepted this revision.May 25 2023, 5:42 AM

LGTM

clang/include/clang/Basic/FileEntry.h
123–124

If this is always set now, should it be a non optional DirectoryEntryRef?

This revision is now accepted and ready to land.May 25 2023, 5:42 AM
benlangmuir accepted this revision.May 25 2023, 9:15 AM

Make directory non-optional

clang/include/clang/Basic/FileEntry.h
123–124

Yes, thank you.

This revision was landed with ongoing or failed builds.May 25 2023, 12:37 PM
This revision was automatically updated to reflect the committed changes.