[clang] 8d908b8 - [clang][Interp] Ignore unnamed bitfields when zeroing records (#102749)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 10 06:56:22 PDT 2024
Author: Timm Baeder
Date: 2024-08-10T15:56:19+02:00
New Revision: 8d908b8cc5f4b3aeb2303437a9c2d35654279fd9
URL: https://github.com/llvm/llvm-project/commit/8d908b8cc5f4b3aeb2303437a9c2d35654279fd9
DIFF: https://github.com/llvm/llvm-project/commit/8d908b8cc5f4b3aeb2303437a9c2d35654279fd9.diff
LOG: [clang][Interp] Ignore unnamed bitfields when zeroing records (#102749)
Including unions, where this is more important.
Added:
Modified:
clang/lib/AST/Interp/Compiler.cpp
clang/test/AST/Interp/unions.cpp
Removed:
################################################################################
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
More information about the cfe-commits
mailing list