Skip to content

Commit 704cd98

Browse files
[CIR] Fix outdated bitfield iteration logic in accumulateFields
1 parent e1d45b1 commit 704cd98

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,7 @@ void CIRRecordLowering::accumulateFields() {
499499
fieldEnd = recordDecl->field_end();
500500
field != fieldEnd;) {
501501
if (field->isBitField()) {
502-
RecordDecl::field_iterator start = field;
503-
// Iterate to gather the list of bitfields.
504-
for (++field; field != fieldEnd && field->isBitField(); ++field)
505-
;
506-
field = accumulateBitFields(start, field);
502+
field = accumulateBitFields(field, fieldEnd);
507503
assert((field == fieldEnd || !field->isBitField()) &&
508504
"Failed to accumulate all the bitfields");
509505
} else if (!field->isZeroSize(astContext)) {

clang/test/CIR/CodeGen/bitfields.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,23 @@ typedef struct {
7171
// LLVM-DAG: %struct.U = type <{ i8, i8, i8, i8, i64 }>
7272
// OGCG-DAG: %struct.U = type <{ i8, i8, i8, i8, i64 }>
7373

74+
typedef struct{
75+
int a : 24;
76+
char b;
77+
int c: 30;
78+
} Clip;
79+
80+
// CIR-DAG: !rec_Clip = !cir.record<struct "Clip" {!cir.array<!u8i x 3>, !s8i, !u32i}>
81+
// LLVM-DAG: %struct.Clip = type { [3 x i8], i8, i32 }
82+
// OGCG-DAG: %struct.Clip = type { [3 x i8], i8, i32 }
83+
7484
void def() {
7585
A a;
7686
D d;
7787
S s;
7888
T t;
7989
U u;
90+
Clip c;
8091
}
8192

8293
int load_field(S* s) {

0 commit comments

Comments
 (0)