diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/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 `_) +- Fix bug in the computation of the ``__has_unique_object_representations`` + builtin for types with unnamed bitfields. + (`#61336 `_) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -2810,6 +2810,9 @@ int64_t FieldSizeInBits = Context.toBits(Context.getTypeSizeInChars(Field->getType())); if (Field->isBitField()) { + if (Field->isUnnamedBitfield()) + return std::nullopt; + int64_t BitfieldSize = Field->getBitWidthValue(Context); if (IsBitIntType) { if ((unsigned)BitfieldSize > diff --git a/clang/test/SemaCXX/type-traits.cpp b/clang/test/SemaCXX/type-traits.cpp --- a/clang/test/SemaCXX/type-traits.cpp +++ b/clang/test/SemaCXX/type-traits.cpp @@ -2878,9 +2878,15 @@ char d : 2; }; +struct UnnamedBitfield { + int named : 8; + int : 24; +}; + static_assert(!has_unique_object_representations::value, "Bitfield padding"); static_assert(has_unique_object_representations::value, "Bitfield padding"); static_assert(!has_unique_object_representations::value, "Bitfield padding"); +static_assert(!has_unique_object_representations::value, "Bitfield padding"); struct BoolBitfield { bool b : 8;