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.

llvm-svn: 67449
This commit is contained in:
Daniel Dunbar 2009-03-21 17:56:30 +00:00
parent 8e93780c86
commit 891d57155e
1 changed files with 9 additions and 1 deletions

View File

@ -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);