Skip to content

Commit

Permalink
Properly support [[noreturn]] attribute if available
Browse files Browse the repository at this point in the history
- flyby: remove #include <boost/exception/detail/attribute_noreturn.hpp>
  • Loading branch information
hkaiser committed Aug 11, 2017
1 parent 0b269d1 commit 2bf98d6
Show file tree
Hide file tree
Showing 19 changed files with 113 additions and 82 deletions.
7 changes: 7 additions & 0 deletions cmake/HPX_AddConfigTest.cmake
Expand Up @@ -510,6 +510,13 @@ macro(hpx_check_for_cxx11_std_unordered_set)
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_noreturn_attribute)
add_hpx_config_test(HPX_WITH_CXX11_NORETURN_ATTRIBUTE
SOURCE cmake/tests/cxx11_noreturn_attribute.cpp
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx14_constexpr)
add_hpx_config_test(HPX_WITH_CXX14_CONSTEXPR
Expand Down
3 changes: 3 additions & 0 deletions cmake/HPX_PerformCxxFeatureTests.cmake
Expand Up @@ -136,6 +136,9 @@ macro(hpx_perform_cxx_feature_tests)
hpx_check_for_cxx11_std_unordered_set(
REQUIRED "HPX needs support for C++11 std::unordered_set")

hpx_check_for_cxx11_noreturn_attribute(
DEFINITIONS HPX_HAVE_CXX11_NORETURN_ATTRIBUTE)

if(HPX_WITH_CXX1Y OR HPX_WITH_CXX14 OR HPX_WITH_CXX1Z OR HPX_WITH_CXX17)
# Check the availability of certain C++14 language features
hpx_check_for_cxx14_constexpr(
Expand Down
19 changes: 19 additions & 0 deletions cmake/tests/cxx11_noreturn_attribute.cpp
@@ -0,0 +1,19 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2017 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
////////////////////////////////////////////////////////////////////////////////

#if !defined(__has_cpp_attribute)
# error "__has_cpp_attribute not supported, assume [[noreturn]] is not supported"
#else
# if !__has_cpp_attribute(noreturn)
# error "__has_cpp_attribute(noreturn) not supported"
# endif
#endif

int main()
{
return 0;
}
29 changes: 0 additions & 29 deletions hpx/config.hpp
Expand Up @@ -32,10 +32,6 @@
#error HPX cannot be compiled with a Boost version earlier than 1.55.0
#endif

#if BOOST_VERSION < 105600
#include <boost/exception/detail/attribute_noreturn.hpp>
#endif

#include <hpx/util/detail/pp/cat.hpp>
#include <hpx/util/detail/pp/stringize.hpp>

Expand Down Expand Up @@ -482,31 +478,6 @@
#endif
#endif

///////////////////////////////////////////////////////////////////////////////
#if defined(HPX_MSVC)
# define HPX_NOINLINE __declspec(noinline)
#elif defined(__GNUC__)
# if defined(__NVCC__) || defined(__CUDACC__)
// nvcc doesn't always parse __noinline
# define HPX_NOINLINE __attribute__ ((noinline))
# else
# define HPX_NOINLINE __attribute__ ((__noinline__))
# endif
#else
# define HPX_NOINLINE
#endif

///////////////////////////////////////////////////////////////////////////////
#if !defined(HPX_ATTRIBUTE_NORETURN)
# if defined(_MSC_VER)
# define HPX_ATTRIBUTE_NORETURN __declspec(noreturn)
# elif defined(__GNUC__)
# define HPX_ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
# else
# define HPX_ATTRIBUTE_NORETURN
# endif
#endif

///////////////////////////////////////////////////////////////////////////////
// Make sure we have support for more than 64 threads for Xeon Phi
#if defined(__MIC__) && !defined(HPX_HAVE_MORE_THAN_64_THREADS)
Expand Down
41 changes: 36 additions & 5 deletions hpx/config/attributes.hpp
Expand Up @@ -7,14 +7,37 @@
#define HPX_CONFIG_ATTRIBUTES_HPP

#include <hpx/config/defines.hpp>
#include <hpx/config/compiler_specific.hpp>

// handle [[fallthrough]]
#if defined(HPX_HAVE_CXX17_FALLTHROUGH_ATTRIBUTE)
# define HPX_FALLTHROUGH [[fallthrough]]
///////////////////////////////////////////////////////////////////////////////
#if defined(HPX_MSVC)
# define HPX_NOINLINE __declspec(noinline)
#elif defined(__GNUC__)
# if defined(__NVCC__) || defined(__CUDACC__)
// nvcc doesn't always parse __noinline
# define HPX_NOINLINE __attribute__ ((noinline))
# else
# define HPX_NOINLINE __attribute__ ((__noinline__))
# endif
#else
# define HPX_FALLTHROUGH
# define HPX_NOINLINE
#endif

///////////////////////////////////////////////////////////////////////////////
// handle [[noreturn]]
#if defined(HPX_HAVE_CXX11_NORETURN_ATTRIBUTE)
# define HPX_NORETURN [[noreturn]]
#else
# if defined(_MSC_VER)
# define HPX_NORETURN __declspec(noreturn)
# elif defined(__GNUC__)
# define HPX_NORETURN __attribute__ ((__noreturn__))
# else
# define HPX_NORETURN
# endif
#endif

///////////////////////////////////////////////////////////////////////////////
// handle [[deprecated]]
#if defined(HPX_HAVE_DEPRECATION_WARNINGS)
# define HPX_DEPRECATED_MSG \
Expand All @@ -29,7 +52,15 @@
#endif

#if !defined(HPX_DEPRECATED)
# define HPX_DEPRECATED(x) /**/
# define HPX_DEPRECATED(x)
#endif

///////////////////////////////////////////////////////////////////////////////
// handle [[fallthrough]]
#if defined(HPX_HAVE_CXX17_FALLTHROUGH_ATTRIBUTE)
# define HPX_FALLTHROUGH [[fallthrough]]
#else
# define HPX_FALLTHROUGH
#endif

#endif
8 changes: 4 additions & 4 deletions hpx/exception.hpp
Expand Up @@ -348,12 +348,12 @@ namespace hpx
construct_lightweight_exception(Exception const& e);

// HPX_ASSERT handler
HPX_ATTRIBUTE_NORETURN HPX_EXPORT
HPX_NORETURN HPX_EXPORT
void assertion_failed(char const* expr, char const* function,
char const* file, long line);

// HPX_ASSERT_MSG handler
HPX_ATTRIBUTE_NORETURN HPX_EXPORT
HPX_NORETURN HPX_EXPORT
void assertion_failed_msg(char const* msg, char const* expr,
char const* function, char const* file, long line);

Expand Down Expand Up @@ -1058,12 +1058,12 @@ namespace hpx
///////////////////////////////////////////////////////////////////////////
// \cond NOINTERNAL
// forwarder for HPX_ASSERT handler
HPX_ATTRIBUTE_NORETURN HPX_EXPORT
HPX_NORETURN HPX_EXPORT
void assertion_failed(char const* expr, char const* function,
char const* file, long line);

// forwarder for HPX_ASSERT_MSG handler
HPX_ATTRIBUTE_NORETURN HPX_EXPORT
HPX_NORETURN HPX_EXPORT
void assertion_failed_msg(char const* msg, char const* expr,
char const* function, char const* file, long line);

Expand Down
4 changes: 2 additions & 2 deletions hpx/exception_info.hpp
Expand Up @@ -185,7 +185,7 @@ namespace hpx
};
}

template <typename E> HPX_ATTRIBUTE_NORETURN
template <typename E> HPX_NORETURN
void throw_with_info(E&& e, exception_info&& xi = exception_info())
{
using ED = typename std::decay<E>::type;
Expand All @@ -203,7 +203,7 @@ namespace hpx
throw detail::exception_with_info<ED>(std::forward<E>(e), std::move(xi));
}

template <typename E> HPX_ATTRIBUTE_NORETURN
template <typename E> HPX_NORETURN
void throw_with_info(E&& e, exception_info const& xi)
{
throw_with_info(std::forward<E>(e), exception_info(xi));
Expand Down
2 changes: 1 addition & 1 deletion hpx/hpx_finalize.hpp
Expand Up @@ -112,7 +112,7 @@ namespace hpx
/// all localities associated with this application. If the function
/// is called not from an HPX thread it will fail and return an error
/// using the argument \a ec.
HPX_EXPORT HPX_ATTRIBUTE_NORETURN void terminate();
HPX_EXPORT HPX_NORETURN void terminate();

/// \brief Disconnect this locality from the application.
///
Expand Down
8 changes: 4 additions & 4 deletions hpx/parallel/exception_list.hpp
Expand Up @@ -28,7 +28,7 @@ namespace hpx { namespace parallel { inline namespace v1
{
typedef Result type;

HPX_ATTRIBUTE_NORETURN static Result call()
HPX_NORETURN static Result call()
{
try {
throw; //-V667
Expand Down Expand Up @@ -174,20 +174,20 @@ namespace hpx { namespace parallel { inline namespace v1
{
typedef Result type;

HPX_ATTRIBUTE_NORETURN static Result call()
HPX_NORETURN static Result call()
{
// any exceptions thrown by algorithms executed with the
// parallel_unsequenced_policy are to call terminate.
hpx::terminate();
}

HPX_ATTRIBUTE_NORETURN
HPX_NORETURN
static hpx::future<Result> call(hpx::future<Result> &&)
{
hpx::terminate();
}

HPX_ATTRIBUTE_NORETURN
HPX_NORETURN
static hpx::future<Result> call(std::exception_ptr const&)
{
hpx::terminate();
Expand Down
6 changes: 3 additions & 3 deletions hpx/parallel/util/detail/handle_local_exceptions.hpp
Expand Up @@ -26,7 +26,7 @@ namespace hpx { namespace parallel { namespace util { namespace detail
{
///////////////////////////////////////////////////////////////////////
// std::bad_alloc has to be handled separately
HPX_ATTRIBUTE_NORETURN static void call(std::exception_ptr const& e)
HPX_NORETURN static void call(std::exception_ptr const& e)
{
try {
std::rethrow_exception(e);
Expand Down Expand Up @@ -130,12 +130,12 @@ namespace hpx { namespace parallel { namespace util { namespace detail
struct handle_local_exceptions<execution::parallel_unsequenced_policy>
{
///////////////////////////////////////////////////////////////////////
HPX_ATTRIBUTE_NORETURN static void call(std::exception_ptr const&)
HPX_NORETURN static void call(std::exception_ptr const&)
{
hpx::terminate();
}

HPX_ATTRIBUTE_NORETURN static void call(
HPX_NORETURN static void call(
std::exception_ptr const&, std::list<std::exception_ptr>&)
{
hpx::terminate();
Expand Down
2 changes: 1 addition & 1 deletion hpx/parallel/util/detail/handle_remote_exceptions.hpp
Expand Up @@ -75,7 +75,7 @@ namespace hpx { namespace parallel { namespace util { namespace detail
template <>
struct handle_remote_exceptions<execution::parallel_unsequenced_policy>
{
HPX_ATTRIBUTE_NORETURN static void call(
HPX_NORETURN static void call(
std::exception_ptr const&, std::list<std::exception_ptr>&)
{
hpx::terminate();
Expand Down
4 changes: 2 additions & 2 deletions hpx/runtime/components/server/runtime_support.hpp
Expand Up @@ -194,13 +194,13 @@ namespace hpx { namespace components { namespace server
void shutdown_all(double timeout);

/// \brief Shutdown this runtime system instance
HPX_ATTRIBUTE_NORETURN void terminate(
HPX_NORETURN void terminate(
naming::id_type const& respond_to);

void terminate_act(naming::id_type const& id) { terminate(id); }

/// \brief Shutdown runtime system instances on all localities
HPX_ATTRIBUTE_NORETURN void terminate_all();
HPX_NORETURN void terminate_all();

void terminate_all_act() { terminate_all(); }

Expand Down
2 changes: 1 addition & 1 deletion hpx/runtime/threads/coroutines/detail/context_base.hpp
Expand Up @@ -430,7 +430,7 @@ namespace hpx { namespace threads { namespace coroutines { namespace detail

// Always throw exit_exception.
// Never returns from standard control flow.
HPX_ATTRIBUTE_NORETURN void exit_self()
HPX_NORETURN void exit_self()
{
HPX_ASSERT(!pending());
HPX_ASSERT(running());
Expand Down
2 changes: 1 addition & 1 deletion hpx/runtime/threads/coroutines/detail/coroutine_self.hpp
Expand Up @@ -128,7 +128,7 @@ namespace hpx { namespace threads { namespace coroutines { namespace detail
return tmp;
}

HPX_ATTRIBUTE_NORETURN void exit()
HPX_NORETURN void exit()
{
m_pimpl->exit_self();
std::terminate(); // FIXME: replace with hpx::terminate();
Expand Down
10 changes: 5 additions & 5 deletions hpx/throw_exception.hpp
Expand Up @@ -25,15 +25,15 @@
namespace hpx { namespace detail
{
template <typename Exception>
HPX_ATTRIBUTE_NORETURN HPX_EXPORT
HPX_NORETURN HPX_EXPORT
void throw_exception(Exception const& e,
std::string const& func, std::string const& file, long line);

HPX_ATTRIBUTE_NORETURN HPX_EXPORT void throw_exception(
HPX_NORETURN HPX_EXPORT void throw_exception(
error errcode, std::string const& msg,
std::string const& func, std::string const& file, long line);

HPX_ATTRIBUTE_NORETURN HPX_EXPORT void rethrow_exception(
HPX_NORETURN HPX_EXPORT void rethrow_exception(
exception const& e, std::string const& func);

template <typename Exception>
Expand Down Expand Up @@ -64,7 +64,7 @@ namespace hpx { namespace detail
HPX_EXPORT void rethrows_if(
hpx::error_code& ec, exception const& e, std::string const& func);

HPX_ATTRIBUTE_NORETURN HPX_EXPORT
HPX_NORETURN HPX_EXPORT
void throw_thread_interrupted_exception();
}}
/// \endcond
Expand All @@ -74,7 +74,7 @@ namespace hpx
/// \cond NOINTERNAL

/// \brief throw an hpx::exception initialized from the given arguments
HPX_ATTRIBUTE_NORETURN inline
HPX_NORETURN inline
void throw_exception(error e, std::string const& msg,
std::string const& func, std::string const& file = "", long line = -1)
{
Expand Down
6 changes: 3 additions & 3 deletions hpx/util/assert.hpp
Expand Up @@ -44,7 +44,7 @@

namespace hpx
{
HPX_ATTRIBUTE_NORETURN HPX_EXPORT void assertion_failed(char const * expr,
HPX_NORETURN HPX_EXPORT void assertion_failed(char const * expr,
char const * function, char const * file, long line); // user defined
} // namespace hpx

Expand Down Expand Up @@ -85,7 +85,7 @@ namespace hpx

namespace hpx
{
HPX_ATTRIBUTE_NORETURN HPX_EXPORT void assertion_failed_msg(
HPX_NORETURN HPX_EXPORT void assertion_failed_msg(
char const * expr, char const * msg,
char const * function, char const * file, long line); // user defined
} // namespace hpx
Expand Down Expand Up @@ -116,7 +116,7 @@ namespace hpx { namespace assertion { namespace detail
// Note: The template is needed to make the function non-inline and
// avoid linking errors
template <typename CharT>
HPX_ATTRIBUTE_NORETURN HPX_NOINLINE void assertion_failed_msg(
HPX_NORETURN HPX_NOINLINE void assertion_failed_msg(
CharT const * expr, char const * msg, char const * function,
char const * file, long line)
{
Expand Down

0 comments on commit 2bf98d6

Please sign in to comment.