Skip to content

Commit 9099f6f

Browse files
committed
[clang][Interp] Skip unnamed bit fields in initializers
Fixes the Codegen/CSKY/csky-hard-abi.c test
1 parent 5ff44db commit 9099f6f

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,11 @@ bool ByteCodeExprGen<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
971971

972972
unsigned InitIndex = 0;
973973
for (const Expr *Init : Inits) {
974+
// Skip unnamed bitfields.
975+
while (InitIndex < R->getNumFields() &&
976+
R->getField(InitIndex)->Decl->isUnnamedBitField())
977+
++InitIndex;
978+
974979
if (!this->emitDupPtr(E))
975980
return false;
976981

clang/lib/AST/Interp/Program.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,11 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
312312
// Reserve space for fields.
313313
Record::FieldList Fields;
314314
for (const FieldDecl *FD : RD->fields()) {
315+
// Note that we DO create fields and descriptors
316+
// for unnamed bitfields here, even though we later ignore
317+
// them everywhere. That's because so the FieldDecl's
318+
// getFieldIndex() matches.
319+
315320
// Reserve space for the field's descriptor and the offset.
316321
BaseSize += align(sizeof(InlineDescriptor));
317322

clang/test/AST/Interp/records.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,3 +1317,16 @@ namespace {
13171317
F f;
13181318
static_assert(f.Z == 12, "");
13191319
}
1320+
1321+
namespace UnnamedBitFields {
1322+
struct A {
1323+
int : 1;
1324+
double f;
1325+
int : 1;
1326+
char c;
1327+
};
1328+
1329+
constexpr A a = (A){1.0, 'a'};
1330+
static_assert(a.f == 1.0, "");
1331+
static_assert(a.c == 'a', "");
1332+
}

0 commit comments

Comments
 (0)