From 99ed43a7a2c44f761f73228a2be34ec8c4494aef Mon Sep 17 00:00:00 2001 From: Tudor Bosman Date: Sat, 20 Apr 2013 13:17:18 -0700 Subject: [PATCH] FOLLY_NORETURN Summary: Seems like a good idea. Test Plan: compiled all of folly Reviewed By: delong.j@fb.com FB internal diff: D783104 --- folly/Exception.h | 7 ++++--- folly/FormatArg.h | 7 ++++--- folly/Portability.h | 6 ++++++ .../exception_tracer/ExceptionTracerLib.cpp | 11 ++++++----- folly/experimental/io/HugePageUtil.cpp | 5 +++-- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/folly/Exception.h b/folly/Exception.h index c2e6eea7..a9300ce4 100644 --- a/folly/Exception.h +++ b/folly/Exception.h @@ -24,24 +24,25 @@ #include "folly/Conv.h" #include "folly/Likely.h" +#include "folly/Portability.h" namespace folly { // Helper to throw std::system_error -void throwSystemError(int err, const char* msg) __attribute__((noreturn)); +void throwSystemError(int err, const char* msg) FOLLY_NORETURN; inline void throwSystemError(int err, const char* msg) { throw std::system_error(err, std::system_category(), msg); } // Helper to throw std::system_error from errno -void throwSystemError(const char* msg) __attribute__((noreturn)); +void throwSystemError(const char* msg) FOLLY_NORETURN; inline void throwSystemError(const char* msg) { throwSystemError(errno, msg); } // Helper to throw std::system_error from errno and components of a string template -void throwSystemError(Args... args) __attribute__((noreturn)); +void throwSystemError(Args... args) FOLLY_NORETURN; template inline void throwSystemError(Args... args) { throwSystemError(errno, folly::to(args...)); diff --git a/folly/FormatArg.h b/folly/FormatArg.h index c72c0300..124d621d 100644 --- a/folly/FormatArg.h +++ b/folly/FormatArg.h @@ -18,9 +18,10 @@ #define FOLLY_FORMATARG_H_ #include -#include "folly/Range.h" -#include "folly/Likely.h" #include "folly/Conv.h" +#include "folly/Likely.h" +#include "folly/Portability.h" +#include "folly/Range.h" namespace folly { @@ -71,7 +72,7 @@ struct FormatArg { } template - void error(Args&&... args) const __attribute__((noreturn)); + void error(Args&&... args) const FOLLY_NORETURN; /** * Full argument string, as passed in to the constructor. */ diff --git a/folly/Portability.h b/folly/Portability.h index 14b7c5b0..a317350c 100644 --- a/folly/Portability.h +++ b/folly/Portability.h @@ -60,4 +60,10 @@ struct MaxAlign { char c; } __attribute__((aligned)); # error Cannot define MaxAlign on this platform #endif +#if defined(__clang__) || defined(__GNUC__) +# define FOLLY_NORETURN __attribute__((noreturn)) +#else +# define FOLLY_NORETURN +#endif + #endif // FOLLY_PORTABILITY_H_ diff --git a/folly/experimental/exception_tracer/ExceptionTracerLib.cpp b/folly/experimental/exception_tracer/ExceptionTracerLib.cpp index 2a7c954b..eab33fd3 100644 --- a/folly/experimental/exception_tracer/ExceptionTracerLib.cpp +++ b/folly/experimental/exception_tracer/ExceptionTracerLib.cpp @@ -20,6 +20,7 @@ #include +#include "folly/Portability.h" #include "folly/experimental/exception_tracer/StackTrace.h" #include "folly/experimental/exception_tracer/ExceptionAbi.h" #include "folly/experimental/exception_tracer/ExceptionTracer.h" @@ -28,9 +29,9 @@ namespace __cxxabiv1 { extern "C" { void __cxa_throw(void* thrownException, std::type_info* type, - void (*destructor)(void)) __attribute__((noreturn)); + void (*destructor)(void)) FOLLY_NORETURN; void* __cxa_begin_catch(void* excObj); -void __cxa_rethrow(void) __attribute__((noreturn)); +void __cxa_rethrow(void) FOLLY_NORETURN; void __cxa_end_catch(void); } @@ -45,10 +46,10 @@ pthread_once_t initialized = PTHREAD_ONCE_INIT; extern "C" { typedef void (*CxaThrowType)(void*, std::type_info*, void (*)(void)) - __attribute__((noreturn)); + FOLLY_NORETURN; typedef void* (*CxaBeginCatchType)(void*); typedef void (*CxaRethrowType)(void) - __attribute__((noreturn)); + FOLLY_NORETURN; typedef void (*CxaEndCatchType)(void); CxaThrowType orig_cxa_throw; @@ -58,7 +59,7 @@ CxaEndCatchType orig_cxa_end_catch; } // extern "C" typedef void (*RethrowExceptionType)(std::exception_ptr) - __attribute__((noreturn)); + FOLLY_NORETURN; RethrowExceptionType orig_rethrow_exception; void initialize() { diff --git a/folly/experimental/io/HugePageUtil.cpp b/folly/experimental/io/HugePageUtil.cpp index 1715da99..3b2053ec 100644 --- a/folly/experimental/io/HugePageUtil.cpp +++ b/folly/experimental/io/HugePageUtil.cpp @@ -27,10 +27,11 @@ #include -#include "folly/experimental/io/HugePages.h" #include "folly/Format.h" +#include "folly/Portability.h" #include "folly/Range.h" #include "folly/ScopeGuard.h" +#include "folly/experimental/io/HugePages.h" DEFINE_bool(cp, false, "Copy file"); @@ -38,7 +39,7 @@ using namespace folly; namespace { -void usage(const char* name) __attribute__((noreturn)); +void usage(const char* name) FOLLY_NORETURN; void usage(const char* name) { std::cerr << folly::format( -- 2.34.1