Skip to content

Commit 8f31017

Browse files
committed
XXX: I am not understanding how things going. don't merge this commit
1 parent 3785a8e commit 8f31017

File tree

3 files changed

+23
-26
lines changed

3 files changed

+23
-26
lines changed

src/codegen/struct_layout.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub struct StructLayoutTracker<'a> {
2424
padding_count: usize,
2525
latest_field_layout: Option<Layout>,
2626
max_field_align: usize,
27+
has_bitfield: bool,
2728
last_field_was_bitfield: bool,
2829
}
2930

@@ -103,6 +104,7 @@ impl<'a> StructLayoutTracker<'a> {
103104
padding_count: 0,
104105
latest_field_layout: None,
105106
max_field_align: 0,
107+
has_bitfield: false,
106108
last_field_was_bitfield: false,
107109
}
108110
}
@@ -145,6 +147,7 @@ impl<'a> StructLayoutTracker<'a> {
145147
);
146148

147149
self.latest_field_layout = Some(layout);
150+
self.has_bitfield = true;
148151
self.last_field_was_bitfield = true;
149152
// NB: We intentionally don't update the max_field_align here, since our
150153
// bitfields code doesn't necessarily guarantee it, so we need to
@@ -365,8 +368,14 @@ impl<'a> StructLayoutTracker<'a> {
365368
return true;
366369
}
367370

368-
if !self.is_packed && self.max_field_align >= layout.align {
369-
return false;
371+
if self.is_packed && !self.has_bitfield {
372+
if self.max_field_align > layout.align {
373+
return false;
374+
}
375+
} else {
376+
if self.max_field_align >= layout.align {
377+
return false;
378+
}
370379
}
371380

372381
// We can only generate up-to a 8-bytes of alignment unless we support

tests/expectations/tests/issue-537-repr-packed-n.rs

+6-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/expectations/tests/issue-537.rs

+6-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)