]> granicus.if.org Git - clang/commitdiff
Frontend: Handle empty input on stdin.
authorDaniel Dunbar <daniel@zuster.org>
Sat, 21 Mar 2009 17:56:30 +0000 (17:56 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sat, 21 Mar 2009 17:56:30 +0000 (17:56 +0000)
 - 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

index 093dc1a2cd2da3579388be8b49660c50c7587d67..9c0ce109017d01b03480732cca884ad44774faef 100644 (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);