diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2020-12-02 17:34:38 -0800 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2020-12-02 17:36:20 -0800 |
commit | b34632201987eed369bb7ef4646f341b901c95b8 (patch) | |
tree | f67cb7d7c5212b217d13afc0347f158e1ee10025 /clang/lib | |
parent | 715ba18d3e11bc3636a9d0f701d8e5a2fdf66852 (diff) | |
download | llvm-b34632201987eed369bb7ef4646f341b901c95b8.zip llvm-b34632201987eed369bb7ef4646f341b901c95b8.tar.gz llvm-b34632201987eed369bb7ef4646f341b901c95b8.tar.bz2 |
Revert "Frontend: Sink named pipe logic from CompilerInstance down to FileManager"
This reverts commit 3b18a594c7717a328c33b9c1eba675e9f4bd367c, 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.
```
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Basic/FileManager.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 26 |
2 files changed, 25 insertions, 3 deletions
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index f3afe6d..c0d3685 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -489,7 +489,7 @@ FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile, uint64_t FileSize = Entry->getSize(); // If there's a high enough chance that the file have changed since we // got its size, force a stat before opening it. - if (isVolatile || Entry->isNamedPipe()) + if (isVolatile) FileSize = -1; StringRef Filename = Entry->getName(); diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index e3018b2..5c82878 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -858,8 +858,30 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input, } FileEntryRef File = *FileOrErr; - SourceMgr.setMainFileID( - SourceMgr.createFileID(File, SourceLocation(), Kind)); + // 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. + const FileEntry *FE = + FileMgr.getVirtualFile(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)); + } } else { llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> SBOrErr = llvm::MemoryBuffer::getSTDIN(); |