Page MenuHomePhabricator

[PR32482] Fix bitfield layout for -mms-bitfield and pragma pack
ClosedPublic

Authored by arphaman on Jan 29 2018, 2:19 PM.

Details

Summary

Clang currently generates wrong record layout for -mms-bitfield and #pragma pack. https://godbolt.org/g/nQ4rVW shows how MSVC and GCC generate different layout to Clang.

This patch fixes the issue by ensuring that bitfields are not packed, but the record's alignment is still updated. This seems to be in line with logic used by GCC and MSVC.

rdar://36343145

Diff Detail

Repository
rC Clang

Event Timeline

arphaman created this revision.Jan 29 2018, 2:19 PM
rjmccall added inline comments.Jan 29 2018, 2:34 PM
lib/AST/RecordLayoutBuilder.cpp
1565

I think naming this 'FieldAlignForRecord' would be clearer.

Other this LGTM.

arphaman updated this revision to Diff 132034.Jan 30 2018, 1:15 PM

Fix packing logic.

Oops, that logic turned out to be incorrect. We simply have to start a new storage unit when the new bitfield's size is wider than the available bits.

rjmccall accepted this revision.Jan 30 2018, 10:50 PM

Oh, that makes much more sense, thanks.

This revision is now accepted and ready to land.Jan 30 2018, 10:50 PM
This revision was automatically updated to reflect the committed changes.