Skip to content

Commit b346322

Browse files
committed
Revert "Frontend: Sink named pipe logic from CompilerInstance down to FileManager"
This reverts commit 3b18a59, since apparently this doesn't work everywhere. E.g., clang-x86_64-debian-fast/3889 (http://lab.llvm.org:8011/#/builders/109/builds/3889) gives me: ``` + : 'RUN: at line 8' + /b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang -x c /dev/fd/0 -E + cat /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/Misc/dev-fd-fs.c fatal error: file '/dev/fd/0' modified since it was first processed 1 error generated. ```
1 parent 715ba18 commit b346322

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
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 || Entry->isNamedPipe())
492+
if (isVolatile)
493493
FileSize = -1;
494494

495495
StringRef Filename = Entry->getName();

clang/lib/Frontend/CompilerInstance.cpp

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

861-
SourceMgr.setMainFileID(
862-
SourceMgr.createFileID(File, SourceLocation(), Kind));
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+
}
863885
} else {
864886
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> SBOrErr =
865887
llvm::MemoryBuffer::getSTDIN();

0 commit comments

Comments
 (0)