This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Fix how size-0 bitfields affect homogeneous aggregates.
ClosedPublic

Authored by simon_tatham on Jun 7 2022, 3:57 AM.

Details

Summary

By both AAPCS32 and AAPCS64, the test for whether an aggregate
qualifies as homogeneous (either HFA or HVA) is based on the data
layout alone. So any logical member of the structure that does not
affect the data layout also should not affect homogeneity. In
particular, an empty bitfield ('int : 0') should make no difference.

In fact, clang considered it to make a difference in C but not in C++,
and justified that policy as compatible with gcc. But that's
considered a bug in gcc as well (at least for Arm targets), and it's
fixed in gcc 12.1.

This fix mimics gcc's: zero-sized bitfields are now ignored in all
languages for the Arm (32- and 64-bit) ABIs. But I've left the
previous behaviour unchanged in other ABIs, by means of adding an
ABIInfo::isZeroLengthBitfieldPermittedInHomogeneousAggregate query
method which the Arm subclasses override.

Diff Detail

Event Timeline

simon_tatham created this revision.Jun 7 2022, 3:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2022, 3:57 AM
simon_tatham requested review of this revision.Jun 7 2022, 3:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2022, 3:57 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Added tests with extern "C", at @lenary's (offline) suggestion.

lenary accepted this revision.Jun 10 2022, 3:22 AM

LGTM.

I tested this patch in an end-to-end fashion to look at the assembly in affected cases, and it is doing the right thing.

This revision is now accepted and ready to land.Jun 10 2022, 3:22 AM
This revision was landed with ongoing or failed builds.Jun 10 2022, 3:27 AM
This revision was automatically updated to reflect the committed changes.