https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/102749
Including unions, where this is more important. >From e2a9a796b2beb2dcee0f8ec974cc548427091af4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Sat, 10 Aug 2024 15:19:55 +0200 Subject: [PATCH] [clang][Interp] Ignore unnamed bitfields when zeroing records Including unions, where this is more important. --- clang/lib/AST/Interp/Compiler.cpp | 3 +++ clang/test/AST/Interp/unions.cpp | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/clang/lib/AST/Interp/Compiler.cpp b/clang/lib/AST/Interp/Compiler.cpp index 6c4d607706c6b..1fa7a944448fb 100644 --- a/clang/lib/AST/Interp/Compiler.cpp +++ b/clang/lib/AST/Interp/Compiler.cpp @@ -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(); diff --git a/clang/test/AST/Interp/unions.cpp b/clang/test/AST/Interp/unions.cpp index 6f6bc3d6891b4..1f52950b1e09b 100644 --- a/clang/test/AST/Interp/unions.cpp +++ b/clang/test/AST/Interp/unions.cpp @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits