]> granicus.if.org Git - clang/commitdiff
Fix a crash with -emit-html from stdin.
authorEli Friedman <eli.friedman@gmail.com>
Tue, 19 May 2009 05:28:52 +0000 (05:28 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Tue, 19 May 2009 05:28:52 +0000 (05:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72104 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/HTMLPrint.cpp

index a4ce9e522dfb4edf1b00660a5fde1510e7002f8a..d5eb9fb5313d44875fc102ad4af0bcd85885b4aa 100644 (file)
@@ -20,6 +20,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/AST/ASTContext.h"
+#include "llvm/Support/MemoryBuffer.h"
 
 using namespace clang;
 
@@ -62,9 +63,17 @@ HTMLPrinter::~HTMLPrinter() {
   // Format the file.
   FileID FID = R.getSourceMgr().getMainFileID();
   const FileEntry* Entry = R.getSourceMgr().getFileEntryForID(FID);
-  
+  const char* Name;
+  // In some cases, in particular the case where the input is from stdin,
+  // there is no entry.  Fall back to the memory buffer for a name in those
+  // cases.
+  if (Entry)
+    Name = Entry->getName();
+  else
+    Name = R.getSourceMgr().getBuffer(FID)->getBufferIdentifier();
+
   html::AddLineNumbers(R, FID);
-  html::AddHeaderFooterInternalBuiltinCSS(R, FID, Entry->getName());
+  html::AddHeaderFooterInternalBuiltinCSS(R, FID, Name);
 
   // If we have a preprocessor, relex the file and syntax highlight.
   // We might not have a preprocessor if we come from a deserialized AST file,