[libcxx-commits] [libcxx] [libc++] Remove potential 0-sized array in __compressed_pair_padding (PR #109028)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Sep 18 07:52:11 PDT 2024
https://github.com/serge-sans-paille updated https://github.com/llvm/llvm-project/pull/109028
>From 06e7122cca9468db17b0415aa37f9124783164e0 Mon Sep 17 00:00:00 2001
From: serge-sans-paille <sguelton at mozilla.com>
Date: Tue, 17 Sep 2024 20:39:05 +0200
Subject: [PATCH 1/3] [libc++] Remove potential 0-sized array in
__compressed_pair_padding
---
libcxx/include/__memory/compressed_pair.h | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/libcxx/include/__memory/compressed_pair.h b/libcxx/include/__memory/compressed_pair.h
index 629e3ad8848ffa..77928af434f1f4 100644
--- a/libcxx/include/__memory/compressed_pair.h
+++ b/libcxx/include/__memory/compressed_pair.h
@@ -52,13 +52,16 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#ifndef _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING
-template <class _ToPad>
+template <class _ToPad,
+ bool _Empty = ((is_empty<_ToPad>::value && !__libcpp_is_final<_ToPad>::value) ||
+ is_reference<_ToPad>::value || sizeof(_ToPad) - __datasizeof_v<_ToPad> == 0)>
class __compressed_pair_padding {
- char __padding_[((is_empty<_ToPad>::value && !__libcpp_is_final<_ToPad>::value) || is_reference<_ToPad>::value)
- ? 0
- : sizeof(_ToPad) - __datasizeof_v<_ToPad>];
+ char __padding_[sizeof(_ToPad) - __datasizeof_v<_ToPad>];
};
+template <class _ToPad>
+class __compressed_pair_padding<_ToPad, true> {};
+
# define _LIBCPP_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2) \
_LIBCPP_NO_UNIQUE_ADDRESS __attribute__((__aligned__(_LIBCPP_ALIGNOF(T2)))) T1 Initializer1; \
_LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T1> _LIBCPP_CONCAT3(__padding1_, __LINE__, _); \
>From dae40cdb2b64e7253f854314b46bb0c876129a66 Mon Sep 17 00:00:00 2001
From: serge-sans-paille <sguelton at mozilla.com>
Date: Wed, 18 Sep 2024 11:25:18 +0200
Subject: [PATCH 2/3] [libc++] Remove potential 0-sized array in
__packed_format_arg_store
---
libcxx/include/__format/format_arg_store.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/libcxx/include/__format/format_arg_store.h b/libcxx/include/__format/format_arg_store.h
index 68e936acecade7..9a4a41df6d4e68 100644
--- a/libcxx/include/__format/format_arg_store.h
+++ b/libcxx/include/__format/format_arg_store.h
@@ -234,6 +234,11 @@ struct __packed_format_arg_store {
uint64_t __types_ = 0;
};
+template <class _Context>
+struct __packed_format_arg_store<_Context, 0> {
+ uint64_t __types_ = 0;
+};
+
template <class _Context, size_t _Np>
struct __unpacked_format_arg_store {
basic_format_arg<_Context> __args_[_Np];
>From 3d28f771e26fa332a1121c67408ae621bb620f19 Mon Sep 17 00:00:00 2001
From: serge-sans-paille <sguelton at mozilla.com>
Date: Wed, 18 Sep 2024 16:51:50 +0200
Subject: [PATCH 3/3] fixup! [libc++] Remove potential 0-sized array in
__compressed_pair_padding
---
libcxx/include/__memory/compressed_pair.h | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/libcxx/include/__memory/compressed_pair.h b/libcxx/include/__memory/compressed_pair.h
index 77928af434f1f4..d955aebad63e31 100644
--- a/libcxx/include/__memory/compressed_pair.h
+++ b/libcxx/include/__memory/compressed_pair.h
@@ -52,15 +52,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#ifndef _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING
-template <class _ToPad,
- bool _Empty = ((is_empty<_ToPad>::value && !__libcpp_is_final<_ToPad>::value) ||
- is_reference<_ToPad>::value || sizeof(_ToPad) - __datasizeof_v<_ToPad> == 0)>
-class __compressed_pair_padding {
- char __padding_[sizeof(_ToPad) - __datasizeof_v<_ToPad>];
-};
-
template <class _ToPad>
-class __compressed_pair_padding<_ToPad, true> {};
+using __compressed_pair_padding =
+ __padding<((is_empty<_ToPad>::value && !__libcpp_is_final<_ToPad>::value) || is_reference<_ToPad>::value)
+ ? 0
+ : (sizeof(_ToPad) - __datasizeof_v<_ToPad>)>;
# define _LIBCPP_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2) \
_LIBCPP_NO_UNIQUE_ADDRESS __attribute__((__aligned__(_LIBCPP_ALIGNOF(T2)))) T1 Initializer1; \
More information about the libcxx-commits
mailing list