This is an archive of the discontinued LLVM Phabricator instance.

Basic: Add native support for stdin to SourceManager and FileManager
ClosedPublic

Authored by dexonsmith on Dec 11 2020, 5:04 PM.

Details

Summary

Add support for stdin to SourceManager and FileManager. Adds
FileManager::getSTDIN, which adds a FileEntryRef for <stdin> and reads
the MemoryBuffer, which is stored as FileEntry::Content.

Eventually the other buffers in ContentCache will sink to here as well

  • we probably usually want to load/save a MemoryBuffer eagerly -- but

it's happening early for stdin to get rid of
CompilerInstance::InitializeSourceManager's final call to
SourceManager::overrideFileContents.

clang/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.export/p1.cpp
relies on building a module from stdin; supporting that requires setting
ContentCache::BufferOverridden.

Diff Detail

Event Timeline

dexonsmith created this revision.Dec 11 2020, 5:04 PM
dexonsmith requested review of this revision.Dec 11 2020, 5:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 11 2020, 5:04 PM
arphaman accepted this revision.Dec 18 2020, 4:31 PM

Nice, it looks cleaner than the override of file contents that was used before. Left one NIT comment

clang/lib/Basic/FileManager.cpp
352

NIT: It might be better to replace the hardcoded string literal to Content->getBufferIdentifier(), just in case it changes in the future.

This revision is now accepted and ready to land.Dec 18 2020, 4:31 PM
This revision was landed with ongoing or failed builds.Dec 23 2020, 3:33 PM
This revision was automatically updated to reflect the committed changes.