Hi rsmith, benlangmuir,
What do you think about adding a very trivial PrettyStackTrace guard around the
entry points to ASTReader, to remind compiler developers to clear their module
cache when they hit a crash here? Would this be the right way to do that?
http://reviews.llvm.org/D6138
Files:
lib/Serialization/ASTReader.cpp
Index: lib/Serialization/ASTReader.cpp
===================================================================
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -50,6 +50,7 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
@@ -62,6 +63,17 @@
using namespace clang::serialization::reader;
using llvm::BitstreamCursor;
+namespace {
+ class PrettyStackTraceASTReader : llvm::PrettyStackTraceString {
+ constexpr static const char * const Message =
+ "\n\n*** Crashed while deserializing from an AST file (e.g. PCH or PCM)."
+ "\n*** Consider clearing your module cache.\n";
+ public:
+ PrettyStackTraceASTReader() : PrettyStackTraceString(Message) {}
+ };
+
+} // end anonymous namespace
+
//===----------------------------------------------------------------------===//
// ChainedASTReaderListener implementation
@@ -1697,6 +1709,8 @@
}
void ASTReader::updateOutOfDateIdentifier(IdentifierInfo &II) {
+ PrettyStackTraceASTReader StackTraceRAII;
+
// Note that we are loading an identifier.
Deserializing AnIdentifier(this);
@@ -3585,6 +3599,7 @@
ModuleKind Type,
SourceLocation ImportLoc,
unsigned ClientLoadCapabilities) {
+ PrettyStackTraceASTReader StackTraceRAII;
llvm::SaveAndRestore<SourceLocation>
SetCurImportLocRAII(CurrentImportLoc, ImportLoc);
@@ -6054,6 +6069,7 @@
}
Decl *ASTReader::GetExternalDecl(uint32_t ID) {
+ PrettyStackTraceASTReader StackTraceRAII;
return GetDecl(ID);
}
@@ -6067,6 +6083,8 @@
return;
}
+ PrettyStackTraceASTReader StackTraceRAII;
+
const DeclContext *DC = D->getDeclContext()->getRedeclContext();
// If this is a named declaration, complete it by looking it up
@@ -6105,6 +6123,8 @@
}
CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) {
+ PrettyStackTraceASTReader StackTraceRAII;
+
RecordLocation Loc = getLocalBitOffset(Offset);
BitstreamCursor &Cursor = Loc.F->DeclsCursor;
SavedStreamPosition SavedPosition(Cursor);
@@ -6274,6 +6294,8 @@
/// source each time it is called, and is meant to be used via a
/// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) {
+ PrettyStackTraceASTReader StackTraceRAII;
+
// Switch case IDs are per Decl.
ClearSwitchCaseIDs();
@@ -6344,6 +6366,8 @@
ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC,
bool (*isKindWeWant)(Decl::Kind),
SmallVectorImpl<Decl*> &Decls) {
+ PrettyStackTraceASTReader StackTraceRAII;
+
// There might be lexical decls in multiple modules, for the TU at
// least. Walk all of the modules in the order they were loaded.
FindExternalLexicalDeclsVisitor Visitor(*this, DC, isKindWeWant, Decls);
@@ -6388,6 +6412,8 @@
void ASTReader::FindFileRegionDecls(FileID File,
unsigned Offset, unsigned Length,
SmallVectorImpl<Decl *> &Decls) {
+ PrettyStackTraceASTReader StackTraceRAII;
+
SourceManager &SM = getSourceManager();
llvm::DenseMap<FileID, FileDeclsInfo>::iterator I = FileDeclIDs.find(File);
@@ -6528,6 +6554,7 @@
if (!Name)
return false;
+ PrettyStackTraceASTReader StackTraceRAII;
Deserializing LookupResults(this);
SmallVector<NamedDecl *, 64> Decls;
@@ -6648,6 +6675,9 @@
void ASTReader::completeVisibleDeclsMap(const DeclContext *DC) {
if (!DC->hasExternalVisibleStorage())
return;
+
+ PrettyStackTraceASTReader StackTraceRAII;
+
DeclsMap Decls;
// Compute the declaration contexts we need to look into. Multiple such
@@ -7488,6 +7518,7 @@
}
Module *ASTReader::getModule(unsigned ID) {
+ PrettyStackTraceASTReader StackTraceRAII;
return getSubmodule(ID);
}
@@ -7521,10 +7552,12 @@
}
Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) {
+ PrettyStackTraceASTReader StackTraceRAII;
return DecodeSelector(ID);
}
uint32_t ASTReader::GetNumExternalSelectors() {
+ PrettyStackTraceASTReader StackTraceRAII;
// ID 0 (the null selector) is considered an external selector.
return getTotalNumSelectors() + 1;
}
@@ -8092,6 +8125,8 @@
}
void ASTReader::ReadComments() {
+ PrettyStackTraceASTReader StackTraceRAII;
+
std::vector<RawComment *> Comments;
for (SmallVectorImpl<std::pair<BitstreamCursor,
serialization::ModuleFile *> >::iterator
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits