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
diff --git a/Driver/clang.cpp b/Driver/clang.cpp
index 093dc1a..9c0ce10 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -912,7 +912,15 @@
       }
     } 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);