Skip to content

Commit 3b18a59

Browse files
committed
Frontend: Sink named pipe logic from CompilerInstance down to FileManager
Remove compilicated logic from CompilerInstance::InitializeSourceManager to deal with named pipes, updating FileManager::getBufferForFile to handle it in a more straightforward way. The existing test at clang/test/Misc/dev-fd-fs.c covers the new behaviour (just like it did the old behaviour). Differential Revision: https://reviews.llvm.org/D90733
1 parent dd2054d commit 3b18a59

File tree

2 files changed

+3
-25
lines changed

2 files changed

+3
-25
lines changed

clang/lib/Basic/FileManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile,
489489
uint64_t FileSize = Entry->getSize();
490490
// If there's a high enough chance that the file have changed since we
491491
// got its size, force a stat before opening it.
492-
if (isVolatile)
492+
if (isVolatile || Entry->isNamedPipe())
493493
FileSize = -1;
494494

495495
StringRef Filename = Entry->getName();

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -858,30 +858,8 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input,
858858
}
859859
FileEntryRef File = *FileOrErr;
860860

861-
// The natural SourceManager infrastructure can't currently handle named
862-
// pipes, but we would at least like to accept them for the main
863-
// file. Detect them here, read them with the volatile flag so FileMgr will
864-
// pick up the correct size, and simply override their contents as we do for
865-
// STDIN.
866-
if (File.getFileEntry().isNamedPipe()) {
867-
auto MB =
868-
FileMgr.getBufferForFile(&File.getFileEntry(), /*isVolatile=*/true);
869-
if (MB) {
870-
// Create a new virtual file that will have the correct size.
871-
const FileEntry *FE =
872-
FileMgr.getVirtualFile(InputFile, (*MB)->getBufferSize(), 0);
873-
SourceMgr.overrideFileContents(FE, std::move(*MB));
874-
SourceMgr.setMainFileID(
875-
SourceMgr.createFileID(FE, SourceLocation(), Kind));
876-
} else {
877-
Diags.Report(diag::err_cannot_open_file) << InputFile
878-
<< MB.getError().message();
879-
return false;
880-
}
881-
} else {
882-
SourceMgr.setMainFileID(
883-
SourceMgr.createFileID(File, SourceLocation(), Kind));
884-
}
861+
SourceMgr.setMainFileID(
862+
SourceMgr.createFileID(File, SourceLocation(), Kind));
885863
} else {
886864
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> SBOrErr =
887865
llvm::MemoryBuffer::getSTDIN();

0 commit comments

Comments
 (0)