Skip to content

Commit

Permalink
Feature test for __builtin_frame_address
Browse files Browse the repository at this point in the history
  • Loading branch information
isidorostsa committed Dec 17, 2024
1 parent 3c0ebc8 commit 4ab72db
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
9 changes: 9 additions & 0 deletions cmake/HPX_AddConfigTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions cmake/HPX_PerformCxxFeatureTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
14 changes: 14 additions & 0 deletions cmake/tests/builtin_frame_address.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

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

#if defined(HPX_WINDOWS)
#define HPX_HAVE_THREADS_GET_STACK_POINTER
Expand All @@ -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<std::size_t>::max)();
Expand Down

0 comments on commit 4ab72db

Please sign in to comment.