Annotate tokens in a separate thread to avoid blowing out stack space. While the CursorVisitor

is gradually becoming more data recursive, AnnotateTokensVisitor does its own recursive call
within the visitor that can still blow out the stack.  This can potentially be reworked to avoid this,
but for now just do token annotation on a separate thread.

llvm-svn: 118783
This commit is contained in:
Ted Kremenek 2010-11-11 08:05:23 +00:00
parent 92209a45b9
commit c7a5bae597
2 changed files with 2272 additions and 1 deletions

File diff suppressed because it is too large Load Diff

View File

@ -235,6 +235,8 @@ public:
StmtParent = 0;
}
ASTUnit *getASTUnit() const { return TU; }
bool Visit(CXCursor Cursor, bool CheckedRegionOfInterest = false);
std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator>
@ -3998,6 +4000,9 @@ public:
void VisitChildren(CXCursor C) { AnnotateVis.VisitChildren(C); }
enum CXChildVisitResult Visit(CXCursor cursor, CXCursor parent);
void AnnotateTokens(CXCursor parent);
void AnnotateTokens() {
AnnotateTokens(clang_getTranslationUnitCursor(AnnotateVis.getASTUnit()));
}
};
}
@ -4202,6 +4207,11 @@ static enum CXChildVisitResult AnnotateTokensVisitor(CXCursor cursor,
return static_cast<AnnotateTokensWorker*>(client_data)->Visit(cursor, parent);
}
// This gets run a separate thread to avoid stack blowout.
static void runAnnotateTokensWorker(void *UserData) {
((AnnotateTokensWorker*)UserData)->AnnotateTokens();
}
extern "C" {
void clang_annotateTokens(CXTranslationUnit TU,
@ -4298,7 +4308,12 @@ void clang_annotateTokens(CXTranslationUnit TU,
// a specific cursor.
AnnotateTokensWorker W(Annotated, Tokens, Cursors, NumTokens,
CXXUnit, RegionOfInterest);
W.AnnotateTokens(clang_getTranslationUnitCursor(CXXUnit));
// Run the worker within a CrashRecoveryContext.
llvm::CrashRecoveryContext CRC;
if (!RunSafely(CRC, runAnnotateTokensWorker, &W)) {
fprintf(stderr, "libclang: crash detected while annotating tokens\n");
}
}
} // end: extern "C"