From 5674388eb637999f9de3f6398ddfc6bcfaac75b8 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Sat, 21 Mar 2009 17:56:30 +0000 Subject: [PATCH] Frontend: Handle empty input on stdin. - PR3854. I think it makes more sense to change MemoryBuffer::getSTDIN (return 0 should indicate error, not empty), but it is documented to return 0 for empty inputs, and some other code appears to rely on this. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67449 91177308-0d34-0410-b5e6-96231b3b80d8 --- Driver/clang.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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, ""); + } + + SourceMgr.createMainFileIDForMemBuffer(SB); if (SourceMgr.getMainFileID().isInvalid()) { PP.getDiagnostics().Report(FullSourceLoc(), diag::err_fe_error_reading_stdin); -- 2.40.0