diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-11-11 08:05:23 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-11-11 08:05:23 +0000 |
commit | c7a5bae597b5756696cd552d98fc7f30e8dae528 (patch) | |
tree | fe787b86a71167452a529dd30dc900a68d543431 /clang/tools/libclang | |
parent | 92209a45b9efe654e6bffe72271fdf38b5387a08 (diff) | |
download | bcm5719-llvm-c7a5bae597b5756696cd552d98fc7f30e8dae528.tar.gz bcm5719-llvm-c7a5bae597b5756696cd552d98fc7f30e8dae528.zip |
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
Diffstat (limited to 'clang/tools/libclang')
-rw-r--r-- | clang/tools/libclang/CIndex.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index de28875de8c..f3aa99ba2f1 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -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" |