]> granicus.if.org Git - clang/commitdiff
"Fix" some unintentional fallout from converting
authorTed Kremenek <kremenek@apple.com>
Sun, 14 Nov 2010 17:47:35 +0000 (17:47 +0000)
committerTed Kremenek <kremenek@apple.com>
Sun, 14 Nov 2010 17:47:35 +0000 (17:47 +0000)
the Stmt* visitation in CursorVisitor to be
data-recursive.

Since AnnotationTokensWorker explicitly calls
CursorVisitor::VisitChildren(), it essentially
transforms the data-recursive algorithm in
CursorVisitor back into a non-data recursive one.
This is particularly bad because the data-recursive
algorithm uses more stack space per stack frame,
which can cause us to blow the stack in some cases.

"Fix" this by making the stack that AnnotationTokensWorker
runs in really huge.  The real fix is to modify
AnnotationTokensWorker not to do the explicit
recursive call.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119047 91177308-0d34-0410-b5e6-96231b3b80d8

tools/libclang/CIndex.cpp
tools/libclang/CIndexer.h

index 98c74c79bd6b8c05c133806472b0cf197fc0249e..6b8bec767ebafcf687df3a47eed756e27a9ebd35 100644 (file)
@@ -4251,8 +4251,14 @@ void clang_annotateTokens(CXTranslationUnit TU,
                          CXXUnit, RegionOfInterest);
 
   // Run the worker within a CrashRecoveryContext.
+  // FIXME: We use a ridiculous stack size here because the data-recursion
+  // algorithm uses a large stack frame than the non-data recursive version,
+  // and AnnotationTokensWorker currently transforms the data-recursion
+  // algorithm back into a traditional recursion by explicitly calling
+  // VisitChildren().  We will need to remove this explicit recursive call.
   llvm::CrashRecoveryContext CRC;
-  if (!RunSafely(CRC, runAnnotateTokensWorker, &W)) {
+  if (!RunSafely(CRC, runAnnotateTokensWorker, &W,
+                 GetSafetyThreadStackSize() * 2)) {
     fprintf(stderr, "libclang: crash detected while annotating tokens\n");
   }
 }
@@ -4597,8 +4603,11 @@ static unsigned SafetyStackThreadSize = 8 << 20;
 namespace clang {
 
 bool RunSafely(llvm::CrashRecoveryContext &CRC,
-               void (*Fn)(void*), void *UserData) {
-  if (unsigned Size = GetSafetyThreadStackSize())
+               void (*Fn)(void*), void *UserData,
+               unsigned Size) {
+  if (!Size)
+    Size = GetSafetyThreadStackSize();
+  if (Size)
     return CRC.RunSafelyOnThread(Fn, UserData, Size);
   return CRC.RunSafely(Fn, UserData);
 }
index b6a82818a80e6af21b051d602047eed926934683..32cfa971f34a5d3f8d0a2ae0a89661b50dbc3c8c 100644 (file)
@@ -83,7 +83,7 @@ namespace clang {
   ///
   /// \return False if a crash was detected.
   bool RunSafely(llvm::CrashRecoveryContext &CRC,
-                 void (*Fn)(void*), void *UserData);
+                 void (*Fn)(void*), void *UserData, unsigned Size = 0);
 }
 
 #endif