summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/HTMLPrint.cpp
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-05-19 05:28:52 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-05-19 05:28:52 +0000
commit69329a52cf9187878209ea380fdcb255c0966097 (patch)
tree5284b5e36646c3649da3b0f62dbc126dac6a46ce /clang/lib/Frontend/HTMLPrint.cpp
parentc82b86dfaa96cadc561b5ccd2b5b37dfae4530cf (diff)
downloadbcm5719-llvm-69329a52cf9187878209ea380fdcb255c0966097.tar.gz
bcm5719-llvm-69329a52cf9187878209ea380fdcb255c0966097.zip
Fix a crash with -emit-html from stdin.
llvm-svn: 72104
Diffstat (limited to 'clang/lib/Frontend/HTMLPrint.cpp')
-rw-r--r--clang/lib/Frontend/HTMLPrint.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/clang/lib/Frontend/HTMLPrint.cpp b/clang/lib/Frontend/HTMLPrint.cpp
index a4ce9e522df..d5eb9fb5313 100644
--- a/clang/lib/Frontend/HTMLPrint.cpp
+++ b/clang/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,
OpenPOWER on IntegriCloud