Skip to content

Commit

Permalink
[clang][Interp] Ignore unnamed bitfields when zeroing records (#102749)
Browse files Browse the repository at this point in the history
Including unions, where this is more important.
  • Loading branch information
tbaederr authored Aug 10, 2024
1 parent 1c26992 commit 8d908b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/lib/AST/Interp/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3356,6 +3356,9 @@ bool Compiler<Emitter>::visitZeroRecordInitializer(const Record *R,
assert(R);
// Fields
for (const Record::Field &Field : R->fields()) {
if (Field.Decl->isUnnamedBitField())
continue;

const Descriptor *D = Field.Desc;
if (D->isPrimitive()) {
QualType QT = D->getType();
Expand Down
8 changes: 8 additions & 0 deletions clang/test/AST/Interp/unions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,5 +297,13 @@ namespace Zeroing {
static_assert(u6.a[4] == 0, "");
static_assert(u6.b == 0, ""); // both-error {{not an integral constant expression}} \
// both-note {{read of member 'b' of union with active member 'a'}}

union UnionWithUnnamedBitfield {
int : 3;
int n;
};
static_assert(UnionWithUnnamedBitfield().n == 0, "");
static_assert(UnionWithUnnamedBitfield{}.n == 0, "");
static_assert(UnionWithUnnamedBitfield{1}.n == 1, "");
}
#endif

0 comments on commit 8d908b8

Please sign in to comment.