Skip to content

Commit

Permalink
Remove the SNMALLOC_USE_CXX17 C preprocessor symbol (#667)
Browse files Browse the repository at this point in the history
* Revise search for no-unique-addres

* Remove SNMALLOC_USE_CXX17 as preprocessor symbol

Just test __cplusplus in the last place we were using it.
  • Loading branch information
nwf-msr authored Jun 28, 2024
1 parent 4620220 commit 6bd6db5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ endfunction()
add_library(snmalloc INTERFACE)

if(SNMALLOC_USE_CXX17)
target_compile_definitions(snmalloc INTERFACE -DSNMALLOC_USE_CXX17)
target_compile_features(snmalloc INTERFACE cxx_std_17)
else()
target_compile_features(snmalloc INTERFACE cxx_std_20)
Expand Down
33 changes: 22 additions & 11 deletions src/snmalloc/ds_core/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* `inline` and complains if you specify `SNMALLOC_FAST_PATH` and `inline`.
*/
# define SNMALLOC_FAST_PATH_INLINE ALWAYSINLINE
# if _MSC_VER >= 1927 && !defined(SNMALLOC_USE_CXX17)
# if _MSC_VER >= 1927 && _MSVC_LANG > 201703L
# define SNMALLOC_FAST_PATH_LAMBDA [[msvc::forceinline]]
# else
# define SNMALLOC_FAST_PATH_LAMBDA
Expand All @@ -27,11 +27,6 @@
# define SNMALLOC_REQUIRE_CONSTINIT
# define SNMALLOC_UNUSED_FUNCTION
# define SNMALLOC_USED_FUNCTION
# ifdef SNMALLOC_USE_CXX17
# define SNMALLOC_NO_UNIQUE_ADDRESS
# else
# define SNMALLOC_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
# endif
#else
# define SNMALLOC_FAST_FAIL() __builtin_trap()
# define SNMALLOC_LIKELY(x) __builtin_expect(!!(x), 1)
Expand All @@ -55,11 +50,6 @@
# define SNMALLOC_COLD __attribute__((cold))
# define SNMALLOC_UNUSED_FUNCTION __attribute((unused))
# define SNMALLOC_USED_FUNCTION __attribute((used))
# ifdef SNMALLOC_USE_CXX17
# define SNMALLOC_NO_UNIQUE_ADDRESS
# else
# define SNMALLOC_NO_UNIQUE_ADDRESS [[no_unique_address]]
# endif
# ifdef __clang__
# define SNMALLOC_REQUIRE_CONSTINIT \
[[clang::require_constant_initialization]]
Expand All @@ -68,6 +58,27 @@
# endif
#endif

/*
* Try to find the right "no_unique_address" attribute for our use, assuming one
* exists.
*
* Different compiler versions and ABIs make this a right pain; see, for
* example, https://github.com/llvm/llvm-project/issues/49358 and
* https://devblogs.microsoft.com/cppblog/msvc-cpp20-and-the-std-cpp20-switch/ .
*/
#if defined(__has_cpp_attribute)
# if __has_cpp_attribute(msvc::no_unique_address) && \
(__cplusplus >= 201803L || _MSVC_LANG >= 201803L)
# define SNMALLOC_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
# elif __has_cpp_attribute(no_unique_address)
# define SNMALLOC_NO_UNIQUE_ADDRESS [[no_unique_address]]
# else
# define SNMALLOC_NO_UNIQUE_ADDRESS
# endif
#else
# define SNMALLOC_NO_UNIQUE_ADDRESS
#endif

#if defined(__cpp_constinit) && __cpp_constinit >= 201907
# define SNMALLOC_CONSTINIT_FN constinit
# define SNMALLOC_CONSTINIT_STATIC constinit const
Expand Down

0 comments on commit 6bd6db5

Please sign in to comment.