From d6b970285b80efab57cfd5451f6c942518580435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Mon, 15 Apr 2024 08:56:32 +0200 Subject: [PATCH 1/2] Add launcer helper --- include/boost/move/detail/launder.hpp | 53 ++++++++++++++++++++++++ include/boost/move/detail/workaround.hpp | 7 +++- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 include/boost/move/detail/launder.hpp diff --git a/include/boost/move/detail/launder.hpp b/include/boost/move/detail/launder.hpp new file mode 100644 index 0000000..a6236de --- /dev/null +++ b/include/boost/move/detail/launder.hpp @@ -0,0 +1,53 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2015. 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) +// +// See http://www.boost.org/libs/container for documentation. +// +////////////////////////////////////////////////////////////////////////////// +#ifndef BOOST_MOVE_DETAIL_LAUNDER_HPP +#define BOOST_MOVE_DETAIL_LAUNDER_HPP + +#ifndef BOOST_CONFIG_HPP +# include +#endif + +#if defined(BOOST_HAS_PRAGMA_ONCE) +# pragma once +#endif + +#include + +namespace boost { +namespace move_detail { + +#if defined(BOOST_MOVE_HAS_BUILTIN_LAUNDER) + +template +BOOST_MOVE_FORCEINLINE T* launder(T* p) +{ + return __builtin_launder( p ); +} + +#else + +template +BOOST_MOVE_FORCEINLINE T* launder(T* p) +{ + return p; +} + +#endif + +template +BOOST_MOVE_FORCEINLINE T launder_cast(const volatile void* p) +{ + return (launder)((T)p); +} + +} //namespace move_detail { +} //namespace boost { + +#endif //#ifndef BOOST_MOVE_DETAIL_LAUNDER_HPP diff --git a/include/boost/move/detail/workaround.hpp b/include/boost/move/detail/workaround.hpp index 5edfcee..f12e933 100644 --- a/include/boost/move/detail/workaround.hpp +++ b/include/boost/move/detail/workaround.hpp @@ -147,5 +147,10 @@ template struct static_assert_test {}; #define BOOST_MOVE_INTRINSIC_CAST BOOST_MOVE_FORCEINLINE #endif -#endif //#ifndef BOOST_MOVE_DETAIL_WORKAROUND_HPP +#if defined(__has_builtin) +#if __has_builtin(__builtin_launder) + #define BOOST_MOVE_HAS_BUILTIN_LAUNDER +#endif +#endif +#endif //#ifndef BOOST_MOVE_DETAIL_WORKAROUND_HPP From d0631eec745828207cf251232cef0d681cb758d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Tue, 16 Apr 2024 14:42:42 +0200 Subject: [PATCH 2/2] Implement aligned_struct with __declspec(align(x)) for x = 8 as MSVC will not align the stack if a built-in type is used (like double). --- include/boost/move/detail/type_traits.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/boost/move/detail/type_traits.hpp b/include/boost/move/detail/type_traits.hpp index 84dcbce..de8b2eb 100644 --- a/include/boost/move/detail/type_traits.hpp +++ b/include/boost/move/detail/type_traits.hpp @@ -1197,12 +1197,20 @@ struct aligned_struct; template <> struct aligned_struct<1> { char data; }; template <> struct aligned_struct<2> { short data; }; template <> struct aligned_struct<4> { int data; }; -template <> struct aligned_struct<8> { double data; }; +//8 byte alignment does not propely work in x86 if attribute is not used. +//If a user declares a variable with 8 byte alignment, such as a double +//the compiler will not realign the stack. +// +//If _declspec(align) is used MSVC will realign the stack. +// +//Disabled specialization +//template <> struct aligned_struct<8> { double data; }; #define BOOST_MOVE_ALIGNED_STRUCT(x) \ template <> struct aligned_struct { \ __declspec(align(x)) char data; \ } +BOOST_MOVE_ALIGNED_STRUCT(8); BOOST_MOVE_ALIGNED_STRUCT(16); BOOST_MOVE_ALIGNED_STRUCT(32); BOOST_MOVE_ALIGNED_STRUCT(64);