[cfe-commits] r119047 - in /cfe/trunk/tools/libclang: CIndex.cpp CIndexer.h

Ted Kremenek kremenek at apple.com
Sun Nov 14 09:47:35 PST 2010


Author: kremenek
Date: Sun Nov 14 11:47:35 2010
New Revision: 119047

URL: http://llvm.org/viewvc/llvm-project?rev=119047&view=rev
Log:
"Fix" some unintentional fallout from converting
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.

Modified:
    cfe/trunk/tools/libclang/CIndex.cpp
    cfe/trunk/tools/libclang/CIndexer.h

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=119047&r1=119046&r2=119047&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Sun Nov 14 11:47:35 2010
@@ -4251,8 +4251,14 @@
                          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 @@
 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);
 }

Modified: cfe/trunk/tools/libclang/CIndexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexer.h?rev=119047&r1=119046&r2=119047&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexer.h (original)
+++ cfe/trunk/tools/libclang/CIndexer.h Sun Nov 14 11:47:35 2010
@@ -83,7 +83,7 @@
   ///
   /// \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





More information about the cfe-commits mailing list