[libcxx-commits] [libcxx] r355755 - Unbork `std::memory_order` ABI.
Eric Fiselier via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Mar 8 15:15:54 PST 2019
Author: ericwf
Date: Fri Mar 8 15:15:54 2019
New Revision: 355755
URL: http://llvm.org/viewvc/llvm-project?rev=355755&view=rev
Log:
Unbork `std::memory_order` ABI.
Summary:
We need to pin the underlying type of C++20' `std::memory_order` to match the C++17 version. Anything less is an ABI break.
At the moment it's `unsigned` before C++20 and `int` after. Or if you're using `-fshort-enums` it's `unsigned char` before C++20 and `int` after.
This patch explicitly specifies the underlying type of the C++20 `memory_order` to be w/e type the compiler would have chosen for the C++17 version.
Reviewers: mclow.lists, ldionne
Reviewed By: ldionne
Subscribers: jfb, jdoerfert, #libc, zoecarver
Differential Revision: https://reviews.llvm.org/D59063
Modified:
libcxx/trunk/include/atomic
Modified: libcxx/trunk/include/atomic
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/atomic?rev=355755&r1=355754&r2=355755&view=diff
==============================================================================
--- libcxx/trunk/include/atomic (original)
+++ libcxx/trunk/include/atomic Fri Mar 8 15:15:54 2019
@@ -584,10 +584,29 @@ void atomic_signal_fence(memory_order m)
_LIBCPP_BEGIN_NAMESPACE_STD
+// Figure out what the underlying type for `memory_order` would be if it were
+// declared as an unscoped enum (accounting for -fshort-enums). Use this result
+// to pin the underlying type in C++20.
+enum __legacy_memory_order {
+ __mo_relaxed,
+ __mo_consume,
+ __mo_acquire,
+ __mo_release,
+ __mo_acq_rel,
+ __mo_seq_cst
+};
+
+typedef underlying_type<__legacy_memory_order>::type __memory_order_underlying_t;
+
#if _LIBCPP_STD_VER > 17
-enum class memory_order {
- relaxed, consume, acquire, release, acq_rel, seq_cst
+enum class memory_order : __memory_order_underlying_t {
+ relaxed = __mo_relaxed,
+ consume = __mo_consume,
+ acquire = __mo_acquire,
+ release = __mo_release,
+ acq_rel = __mo_acq_rel,
+ seq_cst = __mo_seq_cst
};
inline constexpr auto memory_order_relaxed = memory_order::relaxed;
@@ -600,14 +619,18 @@ inline constexpr auto memory_order_seq_c
#else
typedef enum memory_order {
- memory_order_relaxed, memory_order_consume, memory_order_acquire,
- memory_order_release, memory_order_acq_rel, memory_order_seq_cst
+ memory_order_relaxed = __mo_relaxed,
+ memory_order_consume = __mo_consume,
+ memory_order_acquire = __mo_acquire,
+ memory_order_release = __mo_release,
+ memory_order_acq_rel = __mo_acq_rel,
+ memory_order_seq_cst = __mo_seq_cst,
} memory_order;
#endif // _LIBCPP_STD_VER > 17
-typedef underlying_type<memory_order>::type __memory_order_underlying_t;
-
+static_assert(is_same<underlying_type<memory_order>::type, __memory_order_underlying_t>::value,
+ "unexpected underlying type for std::memory_order");
#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) || \
defined(_LIBCPP_ATOMIC_ONLY_USE_BUILTINS)
More information about the libcxx-commits
mailing list