Skip to content

Commit 0fe88f9

Browse files
committed
[PS4/PS5] Don't inherit base class alignment
1 parent 679aa92 commit 0fe88f9

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

clang/lib/AST/RecordLayoutBuilder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,9 @@ ItaniumRecordLayoutBuilder::LayoutBase(const BaseSubobjectInfo *Base) {
12611261
(!HasExternalLayout || Offset == CharUnits::Zero()) &&
12621262
EmptySubobjects->CanPlaceBaseAtOffset(Base, CharUnits::Zero())) {
12631263
setSize(std::max(getSize(), Layout.getSize()));
1264-
UpdateAlignment(BaseAlign, UnpackedAlignTo, PreferredBaseAlign);
1264+
// On PS4/PS5, don't update the alignment, to preserve compatibility.
1265+
if (!Context.getTargetInfo().getTriple().isPS())
1266+
UpdateAlignment(BaseAlign, UnpackedAlignTo, PreferredBaseAlign);
12651267

12661268
return CharUnits::Zero();
12671269
}

clang/test/SemaCXX/alignment-of-derived-class.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// expected-no-diagnostics
33

44
// Test that the alignment of a empty direct base class is correctly
5-
// inherited by the derived class.
5+
// inherited by the derived class, and correctly not inherited on PS4/PS5.
66

77
struct A {
88
} __attribute__ ((aligned(16)));
@@ -12,22 +12,38 @@ static_assert(__alignof(A) == 16, "A should be aligned to 16 bytes");
1212
struct B1 : public A {
1313
};
1414

15+
#if defined(__SCE__)
16+
static_assert(__alignof(B1) == 1, "B1 should be aligned to 1 byte");
17+
#else
1518
static_assert(__alignof(B1) == 16, "B1 should be aligned to 16 bytes");
19+
#endif
1620

1721
struct B2 : public A {
1822
} __attribute__ ((aligned(2)));
1923

24+
#if defined(__SCE__)
25+
static_assert(__alignof(B2) == 2, "B2 should be aligned to 2 bytes");
26+
#else
2027
static_assert(__alignof(B2) == 16, "B2 should be aligned to 16 bytes");
28+
#endif
2129

2230
struct B3 : public A {
2331
} __attribute__ ((aligned(4)));
2432

33+
#if defined(__SCE__)
34+
static_assert(__alignof(B3) == 4, "B3 should be aligned to 4 bytes");
35+
#else
2536
static_assert(__alignof(B3) == 16, "B3 should be aligned to 16 bytes");
37+
#endif
2638

2739
struct B4 : public A {
2840
} __attribute__ ((aligned(8)));
2941

42+
#if defined(__SCE__)
43+
static_assert(__alignof(B4) == 8, "B4 should be aligned to 8 bytes");
44+
#else
3045
static_assert(__alignof(B4) == 16, "B4 should be aligned to 16 bytes");
46+
#endif
3147

3248
struct B5 : public A {
3349
} __attribute__ ((aligned(16)));

0 commit comments

Comments
 (0)