[libcxx-commits] [libcxx] 8a0a706 - [libcxx] Wrap [[no_unique_address]] in a macro, for clang-cl
Martin Storsjö via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Feb 11 12:04:19 PST 2022
Author: Martin Storsjö
Date: 2022-02-11T22:02:32+02:00
New Revision: 8a0a706f096bf380d81b615c67ab1e1af1c377d3
URL: https://github.com/llvm/llvm-project/commit/8a0a706f096bf380d81b615c67ab1e1af1c377d3
DIFF: https://github.com/llvm/llvm-project/commit/8a0a706f096bf380d81b615c67ab1e1af1c377d3.diff
LOG: [libcxx] Wrap [[no_unique_address]] in a macro, for clang-cl
This should silence all remaining clang-cl build warnings.
Differential Revision: https://reviews.llvm.org/D119430
Added:
Modified:
libcxx/include/__algorithm/in_in_out_result.h
libcxx/include/__algorithm/in_in_result.h
libcxx/include/__algorithm/in_out_out_result.h
libcxx/include/__algorithm/in_out_result.h
libcxx/include/__config
libcxx/include/__iterator/counted_iterator.h
libcxx/include/__ranges/copyable_box.h
libcxx/include/__ranges/drop_view.h
libcxx/include/__ranges/join_view.h
libcxx/include/__ranges/reverse_view.h
libcxx/include/__ranges/subrange.h
libcxx/include/__ranges/take_view.h
libcxx/include/__ranges/transform_view.h
Removed:
################################################################################
diff --git a/libcxx/include/__algorithm/in_in_out_result.h b/libcxx/include/__algorithm/in_in_out_result.h
index d020b918ac73f..3a163d1a75b68 100644
--- a/libcxx/include/__algorithm/in_in_out_result.h
+++ b/libcxx/include/__algorithm/in_in_out_result.h
@@ -26,9 +26,9 @@ namespace ranges {
template <class _I1, class _I2, class _O1>
struct in_in_out_result {
- [[no_unique_address]] _I1 in1;
- [[no_unique_address]] _I2 in2;
- [[no_unique_address]] _O1 out;
+ _LIBCPP_NO_UNIQUE_ADDRESS _I1 in1;
+ _LIBCPP_NO_UNIQUE_ADDRESS _I2 in2;
+ _LIBCPP_NO_UNIQUE_ADDRESS _O1 out;
template <class _II1, class _II2, class _OO1>
requires convertible_to<const _I1&, _II1> && convertible_to<const _I2&, _II2> && convertible_to<const _O1&, _OO1>
diff --git a/libcxx/include/__algorithm/in_in_result.h b/libcxx/include/__algorithm/in_in_result.h
index e2585a709c1ce..159092189a532 100644
--- a/libcxx/include/__algorithm/in_in_result.h
+++ b/libcxx/include/__algorithm/in_in_result.h
@@ -26,8 +26,8 @@ namespace ranges {
template <class _I1, class _I2>
struct in_in_result {
- [[no_unique_address]] _I1 in1;
- [[no_unique_address]] _I2 in2;
+ _LIBCPP_NO_UNIQUE_ADDRESS _I1 in1;
+ _LIBCPP_NO_UNIQUE_ADDRESS _I2 in2;
template <class _II1, class _II2>
requires convertible_to<const _I1&, _II1> && convertible_to<const _I2&, _II2>
diff --git a/libcxx/include/__algorithm/in_out_out_result.h b/libcxx/include/__algorithm/in_out_out_result.h
index e97a891473788..9788fbfa2e74e 100644
--- a/libcxx/include/__algorithm/in_out_out_result.h
+++ b/libcxx/include/__algorithm/in_out_out_result.h
@@ -25,9 +25,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace ranges {
template <class _I1, class _O1, class _O2>
struct in_out_out_result {
- [[no_unique_address]] _I1 in;
- [[no_unique_address]] _O1 out1;
- [[no_unique_address]] _O2 out2;
+ _LIBCPP_NO_UNIQUE_ADDRESS _I1 in;
+ _LIBCPP_NO_UNIQUE_ADDRESS _O1 out1;
+ _LIBCPP_NO_UNIQUE_ADDRESS _O2 out2;
template <class _II1, class _OO1, class _OO2>
requires convertible_to<const _I1&, _II1> && convertible_to<const _O1&, _OO1> && convertible_to<const _O2&, _OO2>
diff --git a/libcxx/include/__algorithm/in_out_result.h b/libcxx/include/__algorithm/in_out_result.h
index cdd6ab48fbd21..124b4d6ffb6c6 100644
--- a/libcxx/include/__algorithm/in_out_result.h
+++ b/libcxx/include/__algorithm/in_out_result.h
@@ -26,8 +26,8 @@ namespace ranges {
template<class _InputIterator, class _OutputIterator>
struct in_out_result {
- [[no_unique_address]] _InputIterator in;
- [[no_unique_address]] _OutputIterator out;
+ _LIBCPP_NO_UNIQUE_ADDRESS _InputIterator in;
+ _LIBCPP_NO_UNIQUE_ADDRESS _OutputIterator out;
template <class _InputIterator2, class _OutputIterator2>
requires convertible_to<const _InputIterator&, _InputIterator2> && convertible_to<const _OutputIterator&,
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 2f0e8d4cf81e5..e455eacc19485 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -1398,6 +1398,28 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
#endif
+#if __has_cpp_attribute(msvc::no_unique_address)
+ // MSVC implements [[no_unique_address]] as a silent no-op currently.
+ // (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
+ // However, MSVC implements [[msvc::no_unique_address]] which does what
+ // [[no_unique_address]] is supposed to do, in general.
+
+ // Clang-cl does not yet (14.0) implement either [[no_unique_address]] or
+ // [[msvc::no_unique_address]] though. If/when it does implement
+ // [[msvc::no_unique_address]], this should be preferred though.
+# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
+#elif __has_cpp_attribute(no_unique_address)
+# define _LIBCPP_NO_UNIQUE_ADDRESS [[no_unique_address]]
+#else
+# define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */
+ // Note that this can be replaced by #error as soon as clang-cl
+ // implements msvc::no_unique_address, since there should be no C++20
+ // compiler that doesn't support one of the two attributes at that point.
+ // We geenrally don't want to use this macro outside of C++20-only code,
+ // because using it conditionally in one language version only would make
+ // the ABI inconsistent.
+#endif
+
#endif // __cplusplus
#endif // _LIBCPP_CONFIG
diff --git a/libcxx/include/__iterator/counted_iterator.h b/libcxx/include/__iterator/counted_iterator.h
index 29de729e5ab15..c67743fbe37ff 100644
--- a/libcxx/include/__iterator/counted_iterator.h
+++ b/libcxx/include/__iterator/counted_iterator.h
@@ -65,7 +65,7 @@ class counted_iterator
, public __counted_iterator_value_type<_Iter>
{
public:
- [[no_unique_address]] _Iter __current_ = _Iter();
+ _LIBCPP_NO_UNIQUE_ADDRESS _Iter __current_ = _Iter();
iter_
diff erence_t<_Iter> __count_ = 0;
using iterator_type = _Iter;
diff --git a/libcxx/include/__ranges/copyable_box.h b/libcxx/include/__ranges/copyable_box.h
index 8d43b88845652..d092b7f9ba295 100644
--- a/libcxx/include/__ranges/copyable_box.h
+++ b/libcxx/include/__ranges/copyable_box.h
@@ -41,7 +41,7 @@ namespace ranges {
// Primary template - uses std::optional and introduces an empty state in case assignment fails.
template<__copy_constructible_object _Tp>
class __copyable_box {
- [[no_unique_address]] optional<_Tp> __val_;
+ _LIBCPP_NO_UNIQUE_ADDRESS optional<_Tp> __val_;
public:
template<class ..._Args>
@@ -116,7 +116,7 @@ namespace ranges {
template<__copy_constructible_object _Tp>
requires __doesnt_need_empty_state_for_copy<_Tp> && __doesnt_need_empty_state_for_move<_Tp>
class __copyable_box<_Tp> {
- [[no_unique_address]] _Tp __val_;
+ _LIBCPP_NO_UNIQUE_ADDRESS _Tp __val_;
public:
template<class ..._Args>
diff --git a/libcxx/include/__ranges/drop_view.h b/libcxx/include/__ranges/drop_view.h
index f3701bc711308..64c567416453c 100644
--- a/libcxx/include/__ranges/drop_view.h
+++ b/libcxx/include/__ranges/drop_view.h
@@ -45,7 +45,7 @@ namespace ranges {
// one can't call begin() on it more than once.
static constexpr bool _UseCache = forward_range<_View> && !(random_access_range<_View> && sized_range<_View>);
using _Cache = _If<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
- [[no_unique_address]] _Cache __cached_begin_ = _Cache();
+ _LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache();
range_
diff erence_t<_View> __count_ = 0;
_View __base_ = _View();
diff --git a/libcxx/include/__ranges/join_view.h b/libcxx/include/__ranges/join_view.h
index 1472924bdb80d..1af22213369a9 100644
--- a/libcxx/include/__ranges/join_view.h
+++ b/libcxx/include/__ranges/join_view.h
@@ -67,7 +67,7 @@ namespace ranges {
static constexpr bool _UseCache = !is_reference_v<_InnerRange>;
using _Cache = _If<_UseCache, __non_propagating_cache<remove_cvref_t<_InnerRange>>, __empty_cache>;
- [[no_unique_address]] _Cache __cache_;
+ _LIBCPP_NO_UNIQUE_ADDRESS _Cache __cache_;
_View __base_ = _View(); // TODO: [[no_unique_address]] makes clang crash! File a bug :)
public:
diff --git a/libcxx/include/__ranges/reverse_view.h b/libcxx/include/__ranges/reverse_view.h
index 4da16133088f5..c7f1ab8f943b6 100644
--- a/libcxx/include/__ranges/reverse_view.h
+++ b/libcxx/include/__ranges/reverse_view.h
@@ -43,8 +43,8 @@ namespace ranges {
// amortized O(1) begin() method.
static constexpr bool _UseCache = !random_access_range<_View> && !common_range<_View>;
using _Cache = _If<_UseCache, __non_propagating_cache<reverse_iterator<iterator_t<_View>>>, __empty_cache>;
- [[no_unique_address]] _Cache __cached_begin_ = _Cache();
- [[no_unique_address]] _View __base_ = _View();
+ _LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache();
+ _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
public:
_LIBCPP_HIDE_FROM_ABI
diff --git a/libcxx/include/__ranges/subrange.h b/libcxx/include/__ranges/subrange.h
index 0ea9d78875904..2450e230f281b 100644
--- a/libcxx/include/__ranges/subrange.h
+++ b/libcxx/include/__ranges/subrange.h
@@ -82,9 +82,9 @@ namespace ranges {
static constexpr bool _MustProvideSizeAtConstruction = !_StoreSize; // just to improve compiler diagnostics
struct _Empty { constexpr _Empty(auto) noexcept { } };
using _Size = conditional_t<_StoreSize, make_unsigned_t<iter_
diff erence_t<_Iter>>, _Empty>;
- [[no_unique_address]] _Iter __begin_ = _Iter();
- [[no_unique_address]] _Sent __end_ = _Sent();
- [[no_unique_address]] _Size __size_ = 0;
+ _LIBCPP_NO_UNIQUE_ADDRESS _Iter __begin_ = _Iter();
+ _LIBCPP_NO_UNIQUE_ADDRESS _Sent __end_ = _Sent();
+ _LIBCPP_NO_UNIQUE_ADDRESS _Size __size_ = 0;
public:
_LIBCPP_HIDE_FROM_ABI
diff --git a/libcxx/include/__ranges/take_view.h b/libcxx/include/__ranges/take_view.h
index 5f8fbaa0bd8b2..de44fc1fae724 100644
--- a/libcxx/include/__ranges/take_view.h
+++ b/libcxx/include/__ranges/take_view.h
@@ -39,7 +39,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace ranges {
template<view _View>
class take_view : public view_interface<take_view<_View>> {
- [[no_unique_address]] _View __base_ = _View();
+ _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
range_
diff erence_t<_View> __count_ = 0;
template<bool> class __sentinel;
@@ -136,7 +136,7 @@ namespace ranges {
using _Base = __maybe_const<_Const, _View>;
template<bool _OtherConst>
using _Iter = counted_iterator<iterator_t<__maybe_const<_OtherConst, _View>>>;
- [[no_unique_address]] sentinel_t<_Base> __end_ = sentinel_t<_Base>();
+ _LIBCPP_NO_UNIQUE_ADDRESS sentinel_t<_Base> __end_ = sentinel_t<_Base>();
template<bool>
friend class take_view<_View>::__sentinel;
diff --git a/libcxx/include/__ranges/transform_view.h b/libcxx/include/__ranges/transform_view.h
index a8d2ea3f0ed2d..dad46536c75fb 100644
--- a/libcxx/include/__ranges/transform_view.h
+++ b/libcxx/include/__ranges/transform_view.h
@@ -61,8 +61,8 @@ class transform_view : public view_interface<transform_view<_View, _Fn>> {
template<bool> class __iterator;
template<bool> class __sentinel;
- [[no_unique_address]] __copyable_box<_Fn> __func_;
- [[no_unique_address]] _View __base_ = _View();
+ _LIBCPP_NO_UNIQUE_ADDRESS __copyable_box<_Fn> __func_;
+ _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
public:
_LIBCPP_HIDE_FROM_ABI
More information about the libcxx-commits
mailing list