From 4ab72db4abf8510332f13dac8b1336fb00e59ed9 Mon Sep 17 00:00:00 2001 From: isidorostsa Date: Tue, 17 Dec 2024 13:25:44 +0200 Subject: [PATCH] Feature test for __builtin_frame_address --- cmake/HPX_AddConfigTest.cmake | 9 +++++++++ cmake/HPX_PerformCxxFeatureTests.cmake | 4 ++++ cmake/tests/builtin_frame_address.cpp | 14 ++++++++++++++ .../hpx/coroutines/detail/get_stack_pointer.hpp | 3 ++- 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 cmake/tests/builtin_frame_address.cpp diff --git a/cmake/HPX_AddConfigTest.cmake b/cmake/HPX_AddConfigTest.cmake index b0e1ea437452..9d988a3afd96 100644 --- a/cmake/HPX_AddConfigTest.cmake +++ b/cmake/HPX_AddConfigTest.cmake @@ -250,6 +250,15 @@ function(hpx_check_for_builtin_forward_move) ) endfunction() +# ############################################################################## +function(hpx_check_for_builtin_frame_address) + add_hpx_config_test( + HPX_WITH_BUILTIN_FRAME_ADDRESS + SOURCE cmake/tests/builtin_frame_address.cpp + FILE ${ARGN} + ) +endfunction() + # ############################################################################## function(hpx_check_for_libfun_std_experimental_optional) add_hpx_config_test( diff --git a/cmake/HPX_PerformCxxFeatureTests.cmake b/cmake/HPX_PerformCxxFeatureTests.cmake index 9e2389ef376f..aef17bd812d8 100644 --- a/cmake/HPX_PerformCxxFeatureTests.cmake +++ b/cmake/HPX_PerformCxxFeatureTests.cmake @@ -173,4 +173,8 @@ function(hpx_perform_cxx_feature_tests) hpx_check_for_builtin_forward_move(DEFINITIONS HPX_HAVE_BUILTIN_FORWARD_MOVE) + hpx_check_for_builtin_frame_address( + DEFINITIONS HPX_HAVE_BUILTIN_FRAME_ADDRESS + ) + endfunction() diff --git a/cmake/tests/builtin_frame_address.cpp b/cmake/tests/builtin_frame_address.cpp new file mode 100644 index 000000000000..f1df1a9e1999 --- /dev/null +++ b/cmake/tests/builtin_frame_address.cpp @@ -0,0 +1,14 @@ +// Copyright (c) 2024 Isidoros Tsaousis-Seiras +// +// SPDX-License-Identifier: BSL-1.0 +// 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) + +// test for availability of __builtin_frame_address(0) +// This is needed because circle (build_226) defines __GNUC__ +// but does not provide the builtin + +int main() +{ + (void)__builtin_frame_address(0); +} diff --git a/libs/core/coroutines/include/hpx/coroutines/detail/get_stack_pointer.hpp b/libs/core/coroutines/include/hpx/coroutines/detail/get_stack_pointer.hpp index d0bc472be6f8..2cdf3ffd5f49 100644 --- a/libs/core/coroutines/include/hpx/coroutines/detail/get_stack_pointer.hpp +++ b/libs/core/coroutines/include/hpx/coroutines/detail/get_stack_pointer.hpp @@ -9,6 +9,7 @@ #pragma once #include +#include #if defined(HPX_WINDOWS) #define HPX_HAVE_THREADS_GET_STACK_POINTER @@ -30,7 +31,7 @@ namespace hpx::threads::coroutines::detail { inline std::size_t get_stack_ptr() noexcept { -#if defined(HPX_GCC_VERSION) +#if defined(HPX_HAVE_BUILTIN_FRAME_ADDRESS) return std::size_t(__builtin_frame_address(0)); #else std::size_t stack_ptr = (std::numeric_limits::max)();