From 934a0b06a4ce6e85459c84dc2c6a0e61587fc62c Mon Sep 17 00:00:00 2001 From: Elizabeth Smith Date: Wed, 16 Apr 2014 13:49:35 -0700 Subject: [PATCH] MSVC translation of noreturn attribute Summary: Provide translations for gcc noreturn attribute __attribute__((noreturn)) is gcc specific, clang understands it on nix systems, but for msvc __declspec(noreturn) is the compiler specific version, which clang will imitate/use on windows. There was already a FOLLY_NORETURN in portability.h, however because of __declspec limitations it must prefix the declaration, not postfix. The gcc noreturn attribute does not have this limitation and will work prefixed OR postfixed, so to keep from turning code into spaghetti nonsense, the macro was moved to the front of declations where it is currently used. This will allow it to work with the proper definitions on clang, clang on windows, gcc, and msvc Test Plan: fbmake runtests Reviewed By: delong.j@fb.com FB internal diff: D1279466 --- folly/Exception.h | 6 +++--- folly/Format.h | 2 +- folly/FormatArg.h | 2 +- folly/Portability.h | 6 +++++- folly/SafeAssert.h | 6 +++--- folly/Subprocess.cpp | 2 +- folly/detail/FunctionalExcept.h | 6 +++--- .../exception_tracer/ExceptionTracerLib.cpp | 16 +++++++--------- folly/experimental/io/HugePageUtil.cpp | 2 +- 9 files changed, 25 insertions(+), 23 deletions(-) diff --git a/folly/Exception.h b/folly/Exception.h index 7c0665c7..cfa265d8 100644 --- a/folly/Exception.h +++ b/folly/Exception.h @@ -37,13 +37,13 @@ namespace folly { // The *Explicit functions take an explicit value for errno. // Helper to throw std::system_error -void throwSystemErrorExplicit(int err, const char*) FOLLY_NORETURN; +FOLLY_NORETURN void throwSystemErrorExplicit(int err, const char*); inline void throwSystemErrorExplicit(int err, const char* msg) { throw std::system_error(err, std::system_category(), msg); } template -void throwSystemErrorExplicit(int, Args&&... args) FOLLY_NORETURN; +FOLLY_NORETURN void throwSystemErrorExplicit(int, Args&&... args); template void throwSystemErrorExplicit(int err, Args&&... args) { throwSystemErrorExplicit( @@ -52,7 +52,7 @@ void throwSystemErrorExplicit(int err, Args&&... args) { // Helper to throw std::system_error from errno and components of a string template -void throwSystemError(Args&&... args) FOLLY_NORETURN; +FOLLY_NORETURN void throwSystemError(Args&&... args); template void throwSystemError(Args&&... args) { throwSystemErrorExplicit(errno, std::forward(args)...); diff --git a/folly/Format.h b/folly/Format.h index bccdf86d..970ca405 100644 --- a/folly/Format.h +++ b/folly/Format.h @@ -128,7 +128,7 @@ class Formatter { typename std::decay::type>...> ValueTuple; static constexpr size_t valueCount = std::tuple_size::value; - void handleFormatStrError() const FOLLY_NORETURN; + FOLLY_NORETURN void handleFormatStrError() const; template void appendOutput(Output& out) const; diff --git a/folly/FormatArg.h b/folly/FormatArg.h index 48bfe2af..fda872d3 100644 --- a/folly/FormatArg.h +++ b/folly/FormatArg.h @@ -80,7 +80,7 @@ struct FormatArg { template std::string errorStr(Args&&... args) const; template - void error(Args&&... args) const FOLLY_NORETURN; + FOLLY_NORETURN void error(Args&&... args) const; /** * Full argument string, as passed in to the constructor. diff --git a/folly/Portability.h b/folly/Portability.h index d7ef09bd..0a8989af 100644 --- a/folly/Portability.h +++ b/folly/Portability.h @@ -42,9 +42,13 @@ struct MaxAlign { char c; } __attribute__((aligned)); # error Cannot define MaxAlign on this platform #endif +// compiler specific attribute translation +// msvc should come first, so if clang is in msvc mode it gets the right defines // noreturn -#if defined(__clang__) || defined(__GNUC__) +#if defined(_MSC_VER) +# define FOLLY_NORETURN __declspec(noreturn) +#elif defined(__clang__) || defined(__GNUC__) # define FOLLY_NORETURN __attribute__((noreturn)) #else # define FOLLY_NORETURN diff --git a/folly/SafeAssert.h b/folly/SafeAssert.h index 2c173d6c..1bac6c77 100644 --- a/folly/SafeAssert.h +++ b/folly/SafeAssert.h @@ -43,9 +43,9 @@ namespace folly { namespace detail { -void assertionFailure(const char* expr, const char* msg, const char* file, - unsigned int line, const char* function) - FOLLY_NORETURN; +FOLLY_NORETURN void assertionFailure(const char* expr, const char* msg, + const char* file, unsigned int line, + const char* function); }} // namespace folly diff --git a/folly/Subprocess.cpp b/folly/Subprocess.cpp index c03a5b29..ac1fc8e4 100644 --- a/folly/Subprocess.cpp +++ b/folly/Subprocess.cpp @@ -197,7 +197,7 @@ struct ChildErrorInfo { int errnoValue; }; -void childError(int errFd, int errCode, int errnoValue) FOLLY_NORETURN; +FOLLY_NORETURN void childError(int errFd, int errCode, int errnoValue); void childError(int errFd, int errCode, int errnoValue) { ChildErrorInfo info = {errCode, errnoValue}; // Write the error information over the pipe to our parent process. diff --git a/folly/detail/FunctionalExcept.h b/folly/detail/FunctionalExcept.h index a1aa586c..1aaecebe 100644 --- a/folly/detail/FunctionalExcept.h +++ b/folly/detail/FunctionalExcept.h @@ -21,9 +21,9 @@ FOLLY_NAMESPACE_STD_BEGIN -void __throw_length_error(const char* msg) FOLLY_NORETURN; -void __throw_logic_error(const char* msg) FOLLY_NORETURN; -void __throw_out_of_range(const char* msg) FOLLY_NORETURN; +FOLLY_NORETURN void __throw_length_error(const char* msg); +FOLLY_NORETURN void __throw_logic_error(const char* msg); +FOLLY_NORETURN void __throw_out_of_range(const char* msg); FOLLY_NAMESPACE_STD_END diff --git a/folly/experimental/exception_tracer/ExceptionTracerLib.cpp b/folly/experimental/exception_tracer/ExceptionTracerLib.cpp index b04983bc..8105a156 100644 --- a/folly/experimental/exception_tracer/ExceptionTracerLib.cpp +++ b/folly/experimental/exception_tracer/ExceptionTracerLib.cpp @@ -29,10 +29,10 @@ namespace __cxxabiv1 { extern "C" { -void __cxa_throw(void* thrownException, std::type_info* type, - void (*destructor)(void)) FOLLY_NORETURN; +FOLLY_NORETURN void __cxa_throw(void* thrownException, + std::type_info* type, void (*destructor)(void)); void* __cxa_begin_catch(void* excObj); -void __cxa_rethrow(void) FOLLY_NORETURN; +FOLLY_NORETURN void __cxa_rethrow(void); void __cxa_end_catch(void); } @@ -48,11 +48,10 @@ __thread StackTraceStack caughtExceptions; pthread_once_t initialized = PTHREAD_ONCE_INIT; extern "C" { -typedef void (*CxaThrowType)(void*, std::type_info*, void (*)(void)) - FOLLY_NORETURN; +FOLLY_NORETURN typedef void (*CxaThrowType)(void*, std::type_info*, + void (*)(void)); typedef void* (*CxaBeginCatchType)(void*); -typedef void (*CxaRethrowType)(void) - FOLLY_NORETURN; +FOLLY_NORETURN typedef void (*CxaRethrowType)(void); typedef void (*CxaEndCatchType)(void); CxaThrowType orig_cxa_throw; @@ -61,8 +60,7 @@ CxaRethrowType orig_cxa_rethrow; CxaEndCatchType orig_cxa_end_catch; } // extern "C" -typedef void (*RethrowExceptionType)(std::exception_ptr) - FOLLY_NORETURN; +FOLLY_NORETURN typedef void (*RethrowExceptionType)(std::exception_ptr); RethrowExceptionType orig_rethrow_exception; void initialize() { diff --git a/folly/experimental/io/HugePageUtil.cpp b/folly/experimental/io/HugePageUtil.cpp index 94d03f94..5e687d59 100644 --- a/folly/experimental/io/HugePageUtil.cpp +++ b/folly/experimental/io/HugePageUtil.cpp @@ -39,7 +39,7 @@ using namespace folly; namespace { -void usage(const char* name) FOLLY_NORETURN; +FOLLY_NORETURN void usage(const char* name); void usage(const char* name) { std::cerr << folly::format( -- 2.34.1