Skip to content

Commit

Permalink
fixed incorrect __builtin_assume_aligned check
Browse files Browse the repository at this point in the history
  • Loading branch information
marzer committed Jul 17, 2023
1 parent a7cd1e7 commit ad85977
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v0.3.0

- fixed incorrect `__builtin_assume_aligned` check

<br>

## v0.2.0

- removed `constexpr` where it would be non-portable
Expand Down
72 changes: 33 additions & 39 deletions include/mz/tagged_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#define MZ_TAGGED_PTR_HPP

#define MZ_TAGGED_PTR_VERSION_MAJOR 0
#define MZ_TAGGED_PTR_VERSION_MINOR 2
#define MZ_TAGGED_PTR_VERSION_MINOR 3
#define MZ_TAGGED_PTR_VERSION_PATCH 0

#ifndef MZ_CPP
Expand All @@ -43,10 +43,13 @@
#ifndef MZ_CPP
#define MZ_CPP __cplusplus
#endif
#if MZ_CPP >= 202600L
#if MZ_CPP >= 202900L
#undef MZ_CPP
#define MZ_CPP 29
#elif MZ_CPP >= 202600L
#undef MZ_CPP
#define MZ_CPP 26
#elif MZ_CPP >= 202300L
#elif MZ_CPP >= 202302L
#undef MZ_CPP
#define MZ_CPP 23
#elif MZ_CPP >= 202002L
Expand Down Expand Up @@ -264,49 +267,40 @@
#endif
#endif

#if MZ_MSVC_LIKE
#define MZ_ASSUME(expr) __assume(expr)
#elif MZ_ICC || MZ_CLANG || MZ_HAS_BUILTIN(__builtin_assume)
#define MZ_ASSUME(expr) __builtin_assume(expr)
#elif MZ_HAS_CPP_ATTR(assume) >= 202207
#define MZ_ASSUME(expr) [[assume(expr)]]
#elif MZ_HAS_ATTR(__assume__)
#define MZ_ASSUME(expr) __attribute__((__assume__(expr)))
#else
#define MZ_ASSUME(expr) static_cast<void>(0)
#ifndef MZ_ASSUME
#if MZ_MSVC_LIKE
#define MZ_ASSUME(expr) __assume(expr)
#elif MZ_ICC || MZ_CLANG || MZ_HAS_BUILTIN(__builtin_assume)
#define MZ_ASSUME(expr) __builtin_assume(expr)
#elif MZ_HAS_CPP_ATTR(assume) >= 202207
#define MZ_ASSUME(expr) [[assume(expr)]]
#elif MZ_HAS_ATTR(__assume__)
#define MZ_ASSUME(expr) __attribute__((__assume__(expr)))
#else
#define MZ_ASSUME(expr) static_cast<void>(0)
#endif
#endif

// clang-format off
#ifndef MZ_PURE_GETTER
#define MZ_INLINE_GETTER MZ_NODISCARD MZ_ALWAYS_INLINE
#ifdef NDEBUG
#define MZ_PURE MZ_DECLSPEC(noalias) MZ_ATTR(pure)
#define MZ_CONST MZ_DECLSPEC(noalias) MZ_ATTR(const)
#define MZ_PURE_GETTER \
MZ_NODISCARD \
MZ_PURE
#define MZ_CONST_GETTER \
MZ_NODISCARD \
MZ_CONST
#define MZ_PURE_INLINE_GETTER \
MZ_NODISCARD \
MZ_ALWAYS_INLINE \
MZ_PURE
#define MZ_CONST_INLINE_GETTER \
MZ_NODISCARD \
MZ_ALWAYS_INLINE \
MZ_CONST
#define MZ_PURE MZ_DECLSPEC(noalias) MZ_ATTR(pure)
#define MZ_CONST MZ_DECLSPEC(noalias) MZ_ATTR(const)
#define MZ_PURE_GETTER MZ_NODISCARD MZ_PURE
#define MZ_CONST_GETTER MZ_NODISCARD MZ_CONST
#define MZ_PURE_INLINE_GETTER MZ_NODISCARD MZ_ALWAYS_INLINE MZ_PURE
#define MZ_CONST_INLINE_GETTER MZ_NODISCARD MZ_ALWAYS_INLINE MZ_CONST
#else
#define MZ_PURE
#define MZ_CONST
#define MZ_PURE_GETTER MZ_NODISCARD
#define MZ_CONST_GETTER MZ_NODISCARD
#define MZ_PURE_INLINE_GETTER \
MZ_NODISCARD \
MZ_ALWAYS_INLINE
#define MZ_CONST_INLINE_GETTER \
MZ_NODISCARD \
MZ_ALWAYS_INLINE
#define MZ_PURE_GETTER MZ_NODISCARD
#define MZ_CONST_GETTER MZ_NODISCARD
#define MZ_PURE_INLINE_GETTER MZ_NODISCARD MZ_ALWAYS_INLINE
#define MZ_CONST_INLINE_GETTER MZ_NODISCARD MZ_ALWAYS_INLINE
#endif
#endif
// clang-format on

#ifndef MZ_TRIVIAL_ABI
#if MZ_CLANG || MZ_HAS_ATTR(__trivial_abi__)
Expand Down Expand Up @@ -656,7 +650,7 @@ namespace mz
}
else
{
#if MZ_CLANG || MZ_GCC || MZ_HAS_BUILTIN(assume_aligned)
#if MZ_CLANG || MZ_GCC || MZ_HAS_BUILTIN(__builtin_assume_aligned)

return static_cast<T*>(__builtin_assume_aligned(ptr, N));

Expand Down Expand Up @@ -1155,7 +1149,7 @@ namespace mz
{
template <typename T, size_t Align = detail::tptr_min_align<T>>
class MZ_TRIVIAL_ABI tagged_ptr //
MZ_HIDDEN_BASE(public detail::tptr_to_object<T, Align>)
: public detail::tptr_to_object<T, Align>
{
private:
using base = detail::tptr_to_object<T, Align>;
Expand Down
2 changes: 1 addition & 1 deletion include/mz/tagged_ptr.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define {% macros::prefix %}TAGGED_PTR_HPP

#define {% macros::prefix %}TAGGED_PTR_VERSION_MAJOR 0
#define {% macros::prefix %}TAGGED_PTR_VERSION_MINOR 2
#define {% macros::prefix %}TAGGED_PTR_VERSION_MINOR 3
#define {% macros::prefix %}TAGGED_PTR_VERSION_PATCH 0

//% preprocessor::cpp
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
project(
'tagged_ptr',
'cpp',
version : '0.2.0',
version : '0.3.0',
meson_version : '>=0.60.0',
license : 'MIT',
default_options : [ 'cpp_std=c++17' ]
Expand Down

0 comments on commit ad85977

Please sign in to comment.