Skip to content

Commit b6b9739

Browse files
committed
[clang] Allow FileManager to read stdin
1 parent 506bc47 commit b6b9739

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

clang/lib/Basic/FileManager.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/ADT/Statistic.h"
2323
#include "llvm/Config/llvm-config.h"
2424
#include "llvm/Support/FileSystem.h"
25+
#include "llvm/Support/IOSandbox.h"
2526
#include "llvm/Support/MemoryBuffer.h"
2627
#include "llvm/Support/Path.h"
2728
#include "llvm/Support/raw_ostream.h"
@@ -347,12 +348,15 @@ llvm::Expected<FileEntryRef> FileManager::getSTDIN() {
347348
if (STDIN)
348349
return *STDIN;
349350

350-
std::unique_ptr<llvm::MemoryBuffer> Content;
351-
if (auto ContentOrError = llvm::MemoryBuffer::getSTDIN())
352-
Content = std::move(*ContentOrError);
353-
else
351+
auto ContentOrError = [] {
352+
auto BypassSandbox = llvm::sys::sandbox::scopedDisable();
353+
return llvm::MemoryBuffer::getSTDIN();
354+
}();
355+
356+
if (!ContentOrError)
354357
return llvm::errorCodeToError(ContentOrError.getError());
355358

359+
auto Content = std::move(*ContentOrError);
356360
STDIN = getVirtualFileRef(Content->getBufferIdentifier(),
357361
Content->getBufferSize(), 0);
358362
FileEntry &FE = const_cast<FileEntry &>(STDIN->getFileEntry());

0 commit comments

Comments
 (0)