diff options
-rw-r--r-- | Driver/clang.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Driver/clang.cpp b/Driver/clang.cpp index 093dc1a2cd..9c0ce10901 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -912,7 +912,15 @@ static bool InitializePreprocessor(Preprocessor &PP, } } else { llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN(); - if (SB) SourceMgr.createMainFileIDForMemBuffer(SB); + + // If stdin was empty, SB is null. Cons up an empty memory + // buffer now. + if (!SB) { + const char *EmptyStr = ""; + SB = llvm::MemoryBuffer::getMemBuffer(EmptyStr, EmptyStr, "<stdin>"); + } + + SourceMgr.createMainFileIDForMemBuffer(SB); if (SourceMgr.getMainFileID().isInvalid()) { PP.getDiagnostics().Report(FullSourceLoc(), diag::err_fe_error_reading_stdin); |