This is an archive of the discontinued LLVM Phabricator instance.

[RecordLayout] Don't align to non-power-of-2 sizes when using -mms-bitfields
ClosedPublic

Authored by mstorsjo on Feb 24 2018, 2:29 PM.

Details

Summary

When targeting GNU/MinGW for i386, the size of the "long double" data type is 12 bytes (while it is 8 bytes in MSVC). When building
with -mms-bitfields to have struct layouts match MSVC, data types are laid out in a struct with alignment according to their size. However, this doesn't make sense for the long double type, since it doesn't match MSVC at all, and aligning to a non-power-of-2 size triggers other asserts later.

This matches what GCC does, aligning a long double to 4 bytes in structs on i386 even when -mms-bitfields is specified.

This fixes asserts when using the max_align_t data type when building for MinGW/i386 with the -mms-bitfields flag.

Diff Detail

Event Timeline

mstorsjo created this revision.Feb 24 2018, 2:29 PM
compnerd added inline comments.Feb 24 2018, 2:47 PM
lib/AST/RecordLayoutBuilder.cpp
1755–1760

Can you add an assertion that the size is a power of two unless it is the GNU environment?

mstorsjo updated this revision to Diff 135813.Feb 24 2018, 11:06 PM

Asserting that non power of 2 only occurs in gnu mode.

lib/AST/RecordLayoutBuilder.cpp
1755–1760

Sure, done.

compnerd accepted this revision.Feb 26 2018, 12:12 PM

If its easy enough to wire that through to the frontend as a proper diagnostic, that would be better with a test. Otherwise, this is good to continue to make progress.

This revision is now accepted and ready to land.Feb 26 2018, 12:12 PM
rnk accepted this revision.Feb 26 2018, 2:27 PM

Thanks!

This revision was automatically updated to reflect the committed changes.
efriedma added inline comments.
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
1758 ↗(On Diff #136037)

This assertion seems weird. sizeof(long double) is 12 for other targets, including x86-32 Linux.

mstorsjo added inline comments.Feb 28 2018, 1:31 PM
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
1758 ↗(On Diff #136037)

Perhaps it'd make more sense to flip it around, assert(isPowerOf2() || !Triple.isWindowsMSVCEnvironment())?

efriedma added inline comments.Feb 28 2018, 1:39 PM
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
1758 ↗(On Diff #136037)

Yes, that makes sense.