Fix a crash with -emit-html from stdin.

llvm-svn: 72104
This commit is contained in:
Eli Friedman 2009-05-19 05:28:52 +00:00
parent c82b86dfaa
commit 69329a52cf
1 changed files with 11 additions and 2 deletions

View 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,