[libcxx-commits] [libcxx] 0eb2602 - [libc++] Remove potential 0-sized array in __compressed_pair_padding (#109028)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 1 08:58:28 PDT 2024


Author: serge-sans-paille
Date: 2024-10-01T11:58:25-04:00
New Revision: 0eb26021d2a95cbe69b3b7c9f271f4a59b0f52a4

URL: https://github.com/llvm/llvm-project/commit/0eb26021d2a95cbe69b3b7c9f271f4a59b0f52a4
DIFF: https://github.com/llvm/llvm-project/commit/0eb26021d2a95cbe69b3b7c9f271f4a59b0f52a4.diff

LOG: [libc++] Remove potential 0-sized array in __compressed_pair_padding (#109028)

Added: 
    

Modified: 
    libcxx/include/__format/format_arg_store.h
    libcxx/include/__memory/compressed_pair.h

Removed: 
    


################################################################################
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];

diff  --git a/libcxx/include/__memory/compressed_pair.h b/libcxx/include/__memory/compressed_pair.h
index 629e3ad8848ffa..6454b2b7ab0700 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>)>
 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__, _);          \


        


More information about the libcxx-commits mailing list