aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInstance.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2020-12-02 18:01:28 -0800
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2020-12-23 14:57:41 -0800
commit245218bb355599771ba43a0fe1449d1670f2666c (patch)
tree6d058a341ea1362d3fdd5634284d48690d30b922 /clang/lib/Frontend/CompilerInstance.cpp
parent747f67e034a924cf308f4c0f1bb6b1fa46bd9fbe (diff)
downloadllvm-245218bb355599771ba43a0fe1449d1670f2666c.zip
llvm-245218bb355599771ba43a0fe1449d1670f2666c.tar.gz
llvm-245218bb355599771ba43a0fe1449d1670f2666c.tar.bz2
Basic: Support named pipes natively in SourceManager and FileManager
Handle named pipes natively in SourceManager and FileManager, removing a call to `SourceManager::overrideFileContents` in `CompilerInstance::InitializeSourceManager` (removing a blocker for sinking the content cache 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 / FileManager means that named pipes can also be `#include`d, 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. Differential Revision: https://reviews.llvm.org/D92531
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp29
1 files changed, 3 insertions, 26 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 69e2e55..d96afae 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -856,32 +856,9 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input,
Diags.Report(diag::err_fe_error_reading) << InputFile;
return false;
}
- FileEntryRef File = *FileOrErr;
-
- // The natural SourceManager infrastructure can't currently handle named
- // pipes, but we would at least like to accept them for the main
- // file. Detect them here, read them with the volatile flag so FileMgr will
- // pick up the correct size, and simply override their contents as we do for
- // STDIN.
- if (File.getFileEntry().isNamedPipe()) {
- auto MB =
- FileMgr.getBufferForFile(&File.getFileEntry(), /*isVolatile=*/true);
- if (MB) {
- // Create a new virtual file that will have the correct size.
- FileEntryRef FE =
- FileMgr.getVirtualFileRef(InputFile, (*MB)->getBufferSize(), 0);
- SourceMgr.overrideFileContents(FE, std::move(*MB));
- SourceMgr.setMainFileID(
- SourceMgr.createFileID(FE, SourceLocation(), Kind));
- } else {
- Diags.Report(diag::err_cannot_open_file) << InputFile
- << MB.getError().message();
- return false;
- }
- } else {
- SourceMgr.setMainFileID(
- SourceMgr.createFileID(File, SourceLocation(), Kind));
- }
+
+ SourceMgr.setMainFileID(
+ SourceMgr.createFileID(*FileOrErr, SourceLocation(), Kind));
} else {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> SBOrErr =
llvm::MemoryBuffer::getSTDIN();