[PATCH] D145852: [Clang][AST] Fix __has_unique_object_representations computation for unnamed bitfields.
Roy Jacobson via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 11 13:23:38 PST 2023
royjacobson updated this revision to Diff 504390.
royjacobson added a comment.
Handle 0-length unnamed bit fields as well.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D145852/new/
https://reviews.llvm.org/D145852
Files:
clang/docs/ReleaseNotes.rst
clang/lib/AST/ASTContext.cpp
clang/test/SemaCXX/type-traits.cpp
Index: clang/test/SemaCXX/type-traits.cpp
===================================================================
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2878,9 +2878,21 @@
char d : 2;
};
+struct UnnamedBitfield {
+ int named : 8;
+ int : 24;
+};
+
+struct UnnamedEmptyBitfield {
+ int named;
+ int : 0;
+};
+
static_assert(!has_unique_object_representations<PaddedBitfield>::value, "Bitfield padding");
static_assert(has_unique_object_representations<UnPaddedBitfield>::value, "Bitfield padding");
static_assert(!has_unique_object_representations<AlignedPaddedBitfield>::value, "Bitfield padding");
+static_assert(!has_unique_object_representations<UnnamedBitfield>::value, "Bitfield padding");
+static_assert(has_unique_object_representations<UnnamedEmptyBitfield>::value, "Bitfield padding");
struct BoolBitfield {
bool b : 8;
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2811,6 +2811,12 @@
Context.toBits(Context.getTypeSizeInChars(Field->getType()));
if (Field->isBitField()) {
int64_t BitfieldSize = Field->getBitWidthValue(Context);
+
+ // If we have explicit padding bits, return nullopt to indicate no
+ // unique representation.
+ if (Field->isUnnamedBitfield() && BitfieldSize > 0)
+ return std::nullopt;
+
if (IsBitIntType) {
if ((unsigned)BitfieldSize >
cast<BitIntType>(Field->getType())->getNumBits())
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,9 @@
- Fix crash when evaluating consteval constructor of derived class whose base
has more than one field.
(`#60166 <https://github.com/llvm/llvm-project/issues/60166>`_)
+- Fix bug in the computation of the ``__has_unique_object_representations``
+ builtin for types with unnamed bitfields.
+ (`#61336 <https://github.com/llvm/llvm-project/issues/61336>`_)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145852.504390.patch
Type: text/x-patch
Size: 2161 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230311/03421892/attachment.bin>
More information about the cfe-commits
mailing list