[llvm-branch-commits] [cfe-branch] r118558 - in /cfe/branches/Apple/whitney/tools/libclang: CIndex.cpp CIndexCodeCompletion.cpp CIndexer.h

Daniel Dunbar daniel at zuster.org
Tue Nov 9 09:31:46 PST 2010


Author: ddunbar
Date: Tue Nov  9 11:31:46 2010
New Revision: 118558

URL: http://llvm.org/viewvc/llvm-project?rev=118558&view=rev
Log:
Merge r118274:
--
Author: Daniel Dunbar <daniel at zuster.org>
Date:   Fri Nov 5 07:19:31 2010 +0000

    libclang: Add some support for running certain entry points in a "safety"
    thread, primarily to get a larger stack.
     - Yes, I feel dirty.

Modified:
    cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp
    cfe/branches/Apple/whitney/tools/libclang/CIndexCodeCompletion.cpp
    cfe/branches/Apple/whitney/tools/libclang/CIndexer.h

Modified: cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp?rev=118558&r1=118557&r2=118558&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp (original)
+++ cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp Tue Nov  9 11:31:46 2010
@@ -2139,7 +2139,7 @@
                                     num_unsaved_files, options, 0 };
   llvm::CrashRecoveryContext CRC;
 
-  if (!CRC.RunSafely(clang_parseTranslationUnit_Impl, &PTUI)) {
+  if (!RunSafely(CRC, clang_parseTranslationUnit_Impl, &PTUI)) {
     fprintf(stderr, "libclang: crash detected during parsing: {\n");
     fprintf(stderr, "  'source_filename' : '%s'\n", source_filename);
     fprintf(stderr, "  'command_line_args' : [");
@@ -2238,7 +2238,7 @@
                                       options, 0 };
   llvm::CrashRecoveryContext CRC;
 
-  if (!CRC.RunSafely(clang_reparseTranslationUnit_Impl, &RTUI)) {
+  if (!RunSafely(CRC, clang_reparseTranslationUnit_Impl, &RTUI)) {
     fprintf(stderr, "libclang: crash detected during reparsing\n");
     static_cast<ASTUnit *>(TU)->setUnsafeToFree(true);
     return 1;
@@ -4431,6 +4431,27 @@
 // Misc. utility functions.
 //===----------------------------------------------------------------------===//
 
+static unsigned SafetyStackThreadSize = 0;
+
+namespace clang {
+
+bool RunSafely(llvm::CrashRecoveryContext &CRC,
+               void (*Fn)(void*), void *UserData) {
+  if (unsigned Size = GetSafetyThreadStackSize())
+    return CRC.RunSafelyOnThread(Fn, UserData, Size);
+  return CRC.RunSafely(Fn, UserData);
+}
+
+unsigned GetSafetyThreadStackSize() {
+  return SafetyStackThreadSize;
+}
+
+void SetSafetyThreadStackSize(unsigned Value) {
+  SafetyStackThreadSize = Value;
+}
+
+}
+
 extern "C" {
 
 CXString clang_getClangVersion() {

Modified: cfe/branches/Apple/whitney/tools/libclang/CIndexCodeCompletion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/CIndexCodeCompletion.cpp?rev=118558&r1=118557&r2=118558&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/CIndexCodeCompletion.cpp (original)
+++ cfe/branches/Apple/whitney/tools/libclang/CIndexCodeCompletion.cpp Tue Nov  9 11:31:46 2010
@@ -480,7 +480,7 @@
                               options, 0 };
   llvm::CrashRecoveryContext CRC;
 
-  if (!CRC.RunSafely(clang_codeCompleteAt_Impl, &CCAI)) {
+  if (!RunSafely(CRC, clang_codeCompleteAt_Impl, &CCAI)) {
     fprintf(stderr, "libclang: crash detected in code completion\n");
     static_cast<ASTUnit *>(TU)->setUnsafeToFree(true);
     return 0;

Modified: cfe/branches/Apple/whitney/tools/libclang/CIndexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/CIndexer.h?rev=118558&r1=118557&r2=118558&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/CIndexer.h (original)
+++ cfe/branches/Apple/whitney/tools/libclang/CIndexer.h Tue Nov  9 11:31:46 2010
@@ -1,4 +1,4 @@
-//===- CIndexer.h - Clang-C Source Indexing Library -----------------------===//
+//===- CIndexer.h - Clang-C Source Indexing Library -------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -20,6 +20,10 @@
 #include "llvm/System/Path.h"
 #include <vector>
 
+namespace llvm {
+  class CrashRecoveryContext;
+}
+
 namespace clang {
 namespace cxstring {
   CXString createCXString(const char *String, bool DupString = false);
@@ -66,6 +70,20 @@
                   struct CXUnsavedFile *unsaved_files,
                   std::vector<std::string> &RemapArgs,
                   std::vector<llvm::sys::Path> &TemporaryFiles);
+
+  /// \brief Return the current size to request for "safety".
+  unsigned GetSafetyThreadStackSize();
+
+  /// \brief Set the current size to request for "safety" (or 0, if safety
+  /// threads should not be used).
+  void SetSafetyThreadStackSize(unsigned Value);
+
+  /// \brief Execution the given code "safely", using crash recovery or safety
+  /// threads when possible.
+  ///
+  /// \return False if a crash was detected.
+  bool RunSafely(llvm::CrashRecoveryContext &CRC,
+                 void (*Fn)(void*), void *UserData);
 }
 
 #endif





More information about the llvm-branch-commits mailing list