[cfe-commits] r72104 - /cfe/trunk/lib/Frontend/HTMLPrint.cpp

Eli Friedman eli.friedman at gmail.com
Mon May 18 22:28:52 PDT 2009


Author: efriedma
Date: Tue May 19 00:28:52 2009
New Revision: 72104

URL: http://llvm.org/viewvc/llvm-project?rev=72104&view=rev
Log:
Fix a crash with -emit-html from stdin.


Modified:
    cfe/trunk/lib/Frontend/HTMLPrint.cpp

Modified: cfe/trunk/lib/Frontend/HTMLPrint.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/HTMLPrint.cpp?rev=72104&r1=72103&r2=72104&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/HTMLPrint.cpp (original)
+++ cfe/trunk/lib/Frontend/HTMLPrint.cpp Tue May 19 00:28:52 2009
@@ -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 @@
   // 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,





More information about the cfe-commits mailing list