/*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <vector>
+#include <folly/Indestructible.h>
#include <folly/Portability.h>
#include <folly/SharedMutex.h>
#include <folly/Synchronized.h>
namespace __cxxabiv1 {
extern "C" {
-FOLLY_NORETURN void __cxa_throw(void* thrownException,
- std::type_info* type,
- void (*destructor)(void*));
+void __cxa_throw(
+ void* thrownException,
+ std::type_info* type,
+ void (*destructor)(void*)) __attribute__((__noreturn__));
void* __cxa_begin_catch(void* excObj) throw();
-FOLLY_NORETURN void __cxa_rethrow(void);
-void __cxa_rethrow(void);
+void __cxa_rethrow(void) __attribute__((__noreturn__));
void __cxa_end_catch(void);
}
namespace folly {
namespace exception_tracer {
-#define DECLARE_CALLBACK(NAME) \
- CallbackHolder<NAME##Type>& get##NAME##Callbacks() { \
- static CallbackHolder<NAME##Type> Callbacks; \
- return Callbacks; \
- } \
- void register##NAME##Callback(NAME##Type callback) { \
- get##NAME##Callbacks().registerCallback(callback); \
+#define DECLARE_CALLBACK(NAME) \
+ CallbackHolder<NAME##Type>& get##NAME##Callbacks() { \
+ static Indestructible<CallbackHolder<NAME##Type>> Callbacks; \
+ return *Callbacks; \
+ } \
+ void register##NAME##Callback(NAME##Type callback) { \
+ get##NAME##Callbacks().registerCallback(callback); \
}
DECLARE_CALLBACK(CxaThrow);
DECLARE_CALLBACK(CxaEndCatch);
DECLARE_CALLBACK(RethrowException);
-} // exception_tracer
-} // folly
+} // namespace exception_tracer
+} // namespace folly
+
+// Clang is smart enough to understand that the symbols we're loading
+// are [[noreturn]], but GCC is not. In order to be able to build with
+// -Wunreachable-code enable for Clang, these __builtin_unreachable()
+// calls need to go away. Everything else is messy though, so just
+// #define it to an empty macro under Clang and be done with it.
+#ifdef __clang__
+# define __builtin_unreachable()
+#endif
namespace __cxxabiv1 {