[clang] 9099f6f - [clang][Interp] Skip unnamed bit fields in initializers
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 17 23:19:47 PDT 2024
Author: Timm Bäder
Date: 2024-04-18T08:19:36+02:00
New Revision: 9099f6f8dcffffd7cf7d5cbe9ca4b7582851fde1
URL: https://github.com/llvm/llvm-project/commit/9099f6f8dcffffd7cf7d5cbe9ca4b7582851fde1
DIFF: https://github.com/llvm/llvm-project/commit/9099f6f8dcffffd7cf7d5cbe9ca4b7582851fde1.diff
LOG: [clang][Interp] Skip unnamed bit fields in initializers
Fixes the Codegen/CSKY/csky-hard-abi.c test
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Program.cpp
clang/test/AST/Interp/records.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 6b4b51aac41e84..52e3efff2359d2 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -971,6 +971,11 @@ bool ByteCodeExprGen<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
unsigned InitIndex = 0;
for (const Expr *Init : Inits) {
+ // Skip unnamed bitfields.
+ while (InitIndex < R->getNumFields() &&
+ R->getField(InitIndex)->Decl->isUnnamedBitField())
+ ++InitIndex;
+
if (!this->emitDupPtr(E))
return false;
diff --git a/clang/lib/AST/Interp/Program.cpp b/clang/lib/AST/Interp/Program.cpp
index e6f22e79451e97..2c8c6781b34833 100644
--- a/clang/lib/AST/Interp/Program.cpp
+++ b/clang/lib/AST/Interp/Program.cpp
@@ -312,6 +312,11 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
// Reserve space for fields.
Record::FieldList Fields;
for (const FieldDecl *FD : RD->fields()) {
+ // Note that we DO create fields and descriptors
+ // for unnamed bitfields here, even though we later ignore
+ // them everywhere. That's because so the FieldDecl's
+ // getFieldIndex() matches.
+
// Reserve space for the field's descriptor and the offset.
BaseSize += align(sizeof(InlineDescriptor));
diff --git a/clang/test/AST/Interp/records.cpp b/clang/test/AST/Interp/records.cpp
index 2c33fa1bf88432..3e52354a4a1067 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -1317,3 +1317,16 @@ namespace {
F f;
static_assert(f.Z == 12, "");
}
+
+namespace UnnamedBitFields {
+ struct A {
+ int : 1;
+ double f;
+ int : 1;
+ char c;
+ };
+
+ constexpr A a = (A){1.0, 'a'};
+ static_assert(a.f == 1.0, "");
+ static_assert(a.c == 'a', "");
+}
More information about the cfe-commits
mailing list