This is an archive of the discontinued LLVM Phabricator instance.

Do not honor explicit alignment attribute on fields for PS4.
ClosedPublic

Authored by Sunil_Srivastava on Feb 1 2016, 4:11 PM.

Details

Summary

This is the round 2 of the PS4 ABI. In this round:

  1. A new value PS4 has been added to TargetCXXABI::Kind. It is being used for x86_64-scei-ps4 triple only.
  2. RecordLayoutBuilder.cpp has been logically reverted back to pre r257462 behavior for PS4 abi.
  3. The test Sema/bitfield-layout.c has been enhanced by adding the PS4 triple, and few test entries that differ between PS4 and other triples, have been put under '#ifdef PS4'. Logically, the test has not changed for triples other than x86_64-scei-ps4. For x86_64-scei-ps4 triple, the test matches pre r257462 behavior.

The test passes on all listed triples on x86 Linux and windows hosts.

Diff Detail

Repository
rL LLVM

Event Timeline

Sunil_Srivastava retitled this revision from to Ps4 ABI Round 2. Actual PS4 code..
Sunil_Srivastava updated this object.
Sunil_Srivastava retitled this revision from Ps4 ABI Round 2. Actual PS4 code. to PS4 ABI Round 2. Actual PS4 code..
Sunil_Srivastava added a subscriber: cfe-commits.
rsmith added inline comments.Feb 1 2016, 5:05 PM
lib/AST/RecordLayoutBuilder.cpp
1598–1599 ↗(On Diff #46584)

Please say what that behavior was here. "The PS4 ABI ignores explicit alignment attributes on bitfields." or similar.

rjmccall added inline comments.Feb 1 2016, 10:40 PM
include/clang/Basic/TargetCXXABI.h
118 ↗(On Diff #46584)

I'm not sure why you added a new C++ ABI kind here. The bug fix you're opting out of is not at all specific to C++, and there are more straightforward ways to check the target than checking the C++ ABI kind.

I mean, I have no doubt that eventually there will be some significant C++ ABI bug fix that you don't want to pick up, so I'm not opposed to adding a new C++ ABI kind. It just seems inappropriate to do that in this patch.

lib/AST/RecordLayoutBuilder.cpp
1598–1599 ↗(On Diff #46584)

Also, this should be added as a bit on TargetInfo instead of making it a target-specific check in random code. This also makes it easier to make the code self-documenting, because instead of:

} else if (ExplicitFieldAlign && !isPS4ABI) {

you'd have

} else if (ExplicitFieldAlign && Context.getTargetInfo().useExplicitBitFieldAlignment()) {

You can then document the fact that your ABI is explicitly opting out of this bug fix in a comment on the line in Targets.cpp where you set this field to false.

probinson added inline comments.Feb 2 2016, 8:07 AM
include/clang/Basic/TargetCXXABI.h
118 ↗(On Diff #46584)

The alignment attribute is affecting layout, and layout would seem to be an ABI thing.

rjmccall added inline comments.Feb 2 2016, 9:33 AM
include/clang/Basic/TargetCXXABI.h
118 ↗(On Diff #46584)

The CXXABI types dictate C++-specific ABI details, e.g. the layout of v-tables. Generic C-level ABI details like type sizes and alignments and struct layout quirks are provided by TargetInfo. In particular, TargetInfo already have 3 or 4 target-specific methods controlling various details of bit-field alignment; adding another for this will be very natural.

Changed the patch based of feedback from John McCall.

There is new bit UseExplicitBitFieldAlignment, which is set for everything except for PS4. The r257462 change has been made conditional on this bit.

majnemer added inline comments.
include/clang/Basic/TargetInfo.h
206 ↗(On Diff #47026)

I'd use unsigned to match the style of the surrounding code.

rjmccall edited edge metadata.Feb 5 2016, 10:46 AM

Yes, thank you, this looks great. I agree with David's review, but otherwise this LGTM.

Sunil_Srivastava retitled this revision from PS4 ABI Round 2. Actual PS4 code. to Do not honor explicit alignment attribute on fields for PS4..Feb 5 2016, 12:53 PM
Sunil_Srivastava edited edge metadata.
This revision was automatically updated to reflect the committed changes.