aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-03-21 17:56:30 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-03-21 17:56:30 +0000
commit5674388eb637999f9de3f6398ddfc6bcfaac75b8 (patch)
tree1501ebb9b44fda47df989f0e584d3191820ee344
parent54dfd5cad10c92bbae2d9f3d8933e728ed820db7 (diff)
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
-rw-r--r--Driver/clang.cpp10
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);