This is an archive of the discontinued LLVM Phabricator instance.

Basic: Support named pipes natively in SourceManager
ClosedPublic

Authored by dexonsmith on Dec 2 2020, 6:14 PM.

Details

Summary

Handle named pipes natively in SourceManager, removing a call to
SourceManager::overrideFileContents in
CompilerInstance::InitializeSourceManager. This is a blocker for
sinking the content cache down to FileManager (which will incidently
sink this new named pipe logic with it).

SourceManager usually checks if the file entry's size matches the
eventually loaded buffer, but that's now skipped for named pipes since
the stat won't reflect the full size. Since we can't trust
ContentsEntry->getSize(), we also need shift the check for files that
are too large until after the buffer is loaded... and load the buffer
immediately in createFileID so that no client gets a bad value from
ContentCache::getSize. FileManager::getBufferForFile also needs to
treat these files as volatile when loading the buffer.

Native support in SourceManager means that named pipes can also be
#included, and clang/test/Misc/dev-fd-fs.c was expanded to check for
that.

This is a new version of 3b18a594c7717a328c33b9c1eba675e9f4bd367c, which
was reverted in b34632201987eed369bb7ef4646f341b901c95b8 since it was
missing the SourceManager changes.

Diff Detail

Event Timeline

dexonsmith created this revision.Dec 2 2020, 6:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 2 2020, 6:14 PM
dexonsmith requested review of this revision.Dec 2 2020, 6:14 PM

Note that the original commit was reviewed here: https://reviews.llvm.org/D90733.

Left one question.

clang/lib/Basic/SourceManager.cpp
553

What's the reason behind duplicating the logic here instead of calling createFileID with const FileEntry *SourceFile?

dexonsmith retitled this revision from Reapply "Frontend: Sink named pipe logic from CompilerInstance down to FileManager" to Basic: Support named pipes natively in SourceManager.
dexonsmith edited the summary of this revision. (Show Details)

Updates:

  • Rebased on top of https://reviews.llvm.org/D92984, which drops the const FileEntry* version of createFileID.
  • Add a test for #include-ing from a named pipe, which now works because the named pipe support is native to SourceManager instead of special logic in CompilerInstance.
  • Updated the commit message / summary / title to better reflect the commit content. The new changes are bigger than the original, and I realized that describing it as a revert-of-a-revert+changes was inaccurate.
dexonsmith marked an inline comment as done.Dec 10 2020, 1:29 PM
dexonsmith added inline comments.
clang/lib/Basic/SourceManager.cpp
553

Yeah, I noticed the duplication too; and then I removed the other one with https://reviews.llvm.org/D92984, but forgot to rebase this on top of it. Done now!

Left one minor suggestion , but LGTM otherwise

clang/lib/Basic/SourceManager.cpp
165

Would it make sense to do the diagnoseFileTooLarge check for both files and named pipes here unconditionally instead of having two separate checks? It appears that it shouldn't really matter if we check the ContentsEntry or the Buffer size for regular files, as their sizes are expected to match anyway.

arphaman accepted this revision.Dec 18 2020, 4:01 PM
This revision is now accepted and ready to land.Dec 18 2020, 4:01 PM
dexonsmith marked an inline comment as done.Dec 18 2020, 4:47 PM

Thanks for the review!

clang/lib/Basic/SourceManager.cpp
165

To explain, the reason I split it was to be able to return faster (don't bother loading the buffer) if it's going to be the wrong size... but an mmap is cheap and the error path isn't worth micro-optimizing.

I agree it's cleaner to just move it. I'll update to do that.