This is an archive of the discontinued LLVM Phabricator instance.

[clang][lex] NFCI: Use DirectoryEntryRef in HeaderSearch::load*()
ClosedPublic

Authored by jansvoboda11 on Apr 14 2022, 2:12 AM.

Details

Summary

This patch removes uses of the deprecated DirectoryEntry::getName() from HeaderSearch::load*() functions by using DirectoryEntryRef instead.

Note that we bail out in one case and use the also deprecated FileEntry::getLastRef(). That's to prevent this patch from growing, and is addressed in a follow-up.

Diff Detail

Event Timeline

jansvoboda11 created this revision.Apr 14 2022, 2:12 AM
Herald added a project: Restricted Project. Β· View Herald TranscriptApr 14 2022, 2:12 AM
jansvoboda11 requested review of this revision.Apr 14 2022, 2:12 AM
Herald added a project: Restricted Project. Β· View Herald TranscriptApr 14 2022, 2:12 AM
Herald added a subscriber: cfe-commits. Β· View Herald Transcript
bnbarham added inline comments.Apr 14 2022, 9:36 AM
clang/lib/Lex/HeaderSearch.cpp
339

I'd prefer the following since I had to specifically go and check getDirRef, though I suppose I probably would have done so even with a comment πŸ˜… :

// Only returns None if not a normal directory, which we just checked
DirectoryEntryRef NormalDir = *Dir.getDirRef();
...loadModuleMapFile(NormalDir, ...
1583

Can we just return false in this case, or is it definitely always a logic error?

1630

Shouldn't need the * should it? Also doesn't seem necessary to actually check here since Dir hasn't been set yet. Just Dir = FileMgr.getOptionalDirectoryRef... should be fine.

1636

I assume this is the place you mentioned in the message? (ie. to prevent patch from growing even more)

1639

Can't Dir still be None here? It *shouldn't* be since the directory for OriginalModuleMapFile should exist, but I'd feel more comfortable with either an early return or an assert here.

Same thing below at the switch as well.

jansvoboda11 marked 5 inline comments as done.Apr 15 2022, 6:30 AM
jansvoboda11 added inline comments.
clang/lib/Lex/HeaderSearch.cpp
339

Fair enough.

1583

I agree returning false here would be better, but I wanted to keep this patch as NFC as possible. How about I make that change in a follow-up patch?

1630

Nice catch!

1636

Yes, that's the one.

1639

I think Dir can't be None at this point - adding an assertion here sounds like a good idea.

jansvoboda11 marked 5 inline comments as done.

Rebase, address review feedback

bnbarham accepted this revision.Apr 15 2022, 9:07 AM
bnbarham added inline comments.
clang/lib/Lex/HeaderSearch.cpp
1583

Sure. It would have been a segfault before, so I assume it must never happen anyway.

This revision is now accepted and ready to land.Apr 15 2022, 9:07 AM
This revision was landed with ongoing or failed builds.Apr 20 2022, 9:54 AM
This revision was automatically updated to reflect the committed changes.
jansvoboda11 reopened this revision.Apr 20 2022, 11:27 AM
This revision is now accepted and ready to land.Apr 20 2022, 11:27 AM
jansvoboda11 updated this revision to Diff 436380.EditedJun 13 2022, 7:10 AM

Replace the File->getLastRef().getDir() escape hatch with FileMgr.getOptionalDirectoryRef(File->getDir()->getName()). The former was causing failures in clang/test/VFS/real-path-found-first.m on Windows.