r211905 - Fix a bug in my previous patch by restoring the behavior that the fatal

Chandler Carruth chandlerc at gmail.com
Fri Jun 27 09:37:27 PDT 2014


Author: chandlerc
Date: Fri Jun 27 11:37:27 2014
New Revision: 211905

URL: http://llvm.org/viewvc/llvm-project?rev=211905&view=rev
Log:
Fix a bug in my previous patch by restoring the behavior that the fatal
error handler is only registered once.

To avoid the use of std::call_once (the obvious way to do this) I've
wrapped everything up into a managed static and done the work in
a constructor. Silly, but it should be effective.

Some out-of-tree libclang users reported this to me, and I've asked them
to put together a test case which exhibits this behavior, but I wanted
to fix things ASAP since the nature of the fix is straight forward.

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

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=211905&r1=211904&r2=211905&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Fri Jun 27 11:37:27 2014
@@ -2600,6 +2600,16 @@ static void fatal_error_handler(void *us
   ::abort();
 }
 
+namespace {
+struct RegisterFatalErrorHandler {
+  RegisterFatalErrorHandler() {
+    llvm::install_fatal_error_handler(fatal_error_handler, nullptr);
+  }
+};
+}
+
+static llvm::ManagedStatic<RegisterFatalErrorHandler> RegisterFatalErrorHandlerOnce;
+
 extern "C" {
 CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
                           int displayDiagnostics) {
@@ -2608,7 +2618,10 @@ CXIndex clang_createIndex(int excludeDec
   if (!getenv("LIBCLANG_DISABLE_CRASH_RECOVERY"))
     llvm::CrashRecoveryContext::Enable();
 
-  llvm::install_fatal_error_handler(fatal_error_handler, nullptr);
+  // Look through the managed static to trigger construction of the managed
+  // static which registers our fatal error handler. This ensures it is only
+  // registered once.
+  (void)*RegisterFatalErrorHandlerOnce;
 
   CIndexer *CIdxr = new CIndexer();
   if (excludeDeclarationsFromPCH)





More information about the cfe-commits mailing list