This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG1d4d21e2e095: [Clang][AST] Fix __has_unique_object_representations computation for unnamed… (authored by royjacobson).
Changed prior to commit: https://reviews.llvm.org/D145852?vs=509298&id=510273#toc 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 @@ -2828,6 +2828,17 @@ static_assert(!has_unique_object_representations<WeirdAlignmentUnion>::value, "Alignment causes padding"); static_assert(!has_unique_object_representations<WeirdAlignment[42]>::value, "Also no arrays that have padding"); +struct __attribute__((packed)) PackedNoPadding1 { + short i; + int j; +}; +struct __attribute__((packed)) PackedNoPadding2 { + int j; + short i; +}; +static_assert(has_unique_object_representations<PackedNoPadding1>::value, "Packed structs have no padding"); +static_assert(has_unique_object_representations<PackedNoPadding2>::value, "Packed structs have no padding"); + static_assert(!has_unique_object_representations<int(int)>::value, "Functions are not unique"); static_assert(!has_unique_object_representations<int(int) const>::value, "Functions are not unique"); static_assert(!has_unique_object_representations<int(int) volatile>::value, "Functions are not unique"); @@ -2878,9 +2889,35 @@ char d : 2; }; +struct UnnamedBitfield { + int named : 8; + int : 24; +}; + +struct __attribute__((packed)) UnnamedBitfieldPacked { + int named : 8; + int : 24; +}; + +struct UnnamedEmptyBitfield { + int named; + int : 0; +}; + +struct UnnamedEmptyBitfieldSplit { + short named; + int : 0; + short also_named; +}; + 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<UnnamedBitfieldPacked>::value, "Bitfield padding"); +static_assert(has_unique_object_representations<UnnamedEmptyBitfield>::value, "Bitfield padding"); +static_assert(sizeof(UnnamedEmptyBitfieldSplit) != (sizeof(short) * 2), "Wrong size"); +static_assert(!has_unique_object_representations<UnnamedEmptyBitfieldSplit>::value, "Bitfield padding"); struct BoolBitfield { bool b : 8; Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -2716,6 +2716,11 @@ int64_t FieldSizeInBits = Context.toBits(Context.getTypeSizeInChars(Field->getType())); if (Field->isBitField()) { + // If we have explicit padding bits, they don't contribute bits + // to the actual object representation, so return 0. + if (Field->isUnnamedBitfield()) + return 0; + int64_t BitfieldSize = Field->getBitWidthValue(Context); if (IsBitIntType) { if ((unsigned)BitfieldSize > Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -291,6 +291,9 @@ template parameters with different nested constraints. - Fix type equivalence comparison between auto types to take constraints into account. +- 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 ^^^^^^^^^^^^^^^^^^^^^^^^^
Index: clang/test/SemaCXX/type-traits.cpp =================================================================== --- clang/test/SemaCXX/type-traits.cpp +++ clang/test/SemaCXX/type-traits.cpp @@ -2828,6 +2828,17 @@ static_assert(!has_unique_object_representations<WeirdAlignmentUnion>::value, "Alignment causes padding"); static_assert(!has_unique_object_representations<WeirdAlignment[42]>::value, "Also no arrays that have padding"); +struct __attribute__((packed)) PackedNoPadding1 { + short i; + int j; +}; +struct __attribute__((packed)) PackedNoPadding2 { + int j; + short i; +}; +static_assert(has_unique_object_representations<PackedNoPadding1>::value, "Packed structs have no padding"); +static_assert(has_unique_object_representations<PackedNoPadding2>::value, "Packed structs have no padding"); + static_assert(!has_unique_object_representations<int(int)>::value, "Functions are not unique"); static_assert(!has_unique_object_representations<int(int) const>::value, "Functions are not unique"); static_assert(!has_unique_object_representations<int(int) volatile>::value, "Functions are not unique"); @@ -2878,9 +2889,35 @@ char d : 2; }; +struct UnnamedBitfield { + int named : 8; + int : 24; +}; + +struct __attribute__((packed)) UnnamedBitfieldPacked { + int named : 8; + int : 24; +}; + +struct UnnamedEmptyBitfield { + int named; + int : 0; +}; + +struct UnnamedEmptyBitfieldSplit { + short named; + int : 0; + short also_named; +}; + 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<UnnamedBitfieldPacked>::value, "Bitfield padding"); +static_assert(has_unique_object_representations<UnnamedEmptyBitfield>::value, "Bitfield padding"); +static_assert(sizeof(UnnamedEmptyBitfieldSplit) != (sizeof(short) * 2), "Wrong size"); +static_assert(!has_unique_object_representations<UnnamedEmptyBitfieldSplit>::value, "Bitfield padding"); struct BoolBitfield { bool b : 8; Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -2716,6 +2716,11 @@ int64_t FieldSizeInBits = Context.toBits(Context.getTypeSizeInChars(Field->getType())); if (Field->isBitField()) { + // If we have explicit padding bits, they don't contribute bits + // to the actual object representation, so return 0. + if (Field->isUnnamedBitfield()) + return 0; + int64_t BitfieldSize = Field->getBitWidthValue(Context); if (IsBitIntType) { if ((unsigned)BitfieldSize > Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -291,6 +291,9 @@ template parameters with different nested constraints. - Fix type equivalence comparison between auto types to take constraints into account. +- 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 ^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits