[clang] [libcxx] [libc++] Remove potential 0-sized array in __compressed_pair_padding (PR #109028)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 18 02:32:24 PDT 2024
https://github.com/serge-sans-paille updated https://github.com/llvm/llvm-project/pull/109028
>From fc06c00eb299b070106dcffd7d13f3a11eb4c1f0 Mon Sep 17 00:00:00 2001
From: serge-sans-paille <sguelton at mozilla.com>
Date: Wed, 18 Sep 2024 08:31:04 +0200
Subject: [PATCH 1/2] Consistent strict flex array
---
clang/lib/Sema/SemaDecl.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 31bf50a32a83c3..b92973299f9c13 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -18931,7 +18931,11 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
FD->setInvalidDecl();
EnclosingDecl->setInvalidDecl();
continue;
- } else if (FDTy->isIncompleteArrayType() &&
+ } else if (Decl::isFlexibleArrayMemberLike(
+ Context, FD, FD->getType(),
+ LangOptions::StrictFlexArraysLevelKind::ZeroOrIncomplete
+ /*getLangOpts().getStrictFlexArraysLevel()*/,
+ true) &&
(Record || isa<ObjCContainerDecl>(EnclosingDecl))) {
if (Record) {
// Flexible array member.
>From 0c70565390aa326fb9aac4fda77280f45c1837df 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 2/2] [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__, _); \
More information about the cfe-commits
mailing list