diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2009-05-19 05:28:52 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2009-05-19 05:28:52 +0000 |
commit | 24200917df7f66afed031e6f4f1672158d28d377 (patch) | |
tree | 7cffa3c9fd336f75f34cefd424f787bec1c788fb /lib/Frontend/HTMLPrint.cpp | |
parent | 7f6ad153565245026c7569314f65a4d4ff4ac41f (diff) |
Fix a crash with -emit-html from stdin.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72104 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/HTMLPrint.cpp')
-rw-r--r-- | lib/Frontend/HTMLPrint.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/Frontend/HTMLPrint.cpp b/lib/Frontend/HTMLPrint.cpp index a4ce9e522d..d5eb9fb531 100644 --- a/lib/Frontend/HTMLPrint.cpp +++ b/lib/Frontend/HTMLPrint.cpp @@ -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, |