Skip to content

Commit b5e039d

Browse files
Fixed 32-bit build with SWIFT_CONCURRENCY_ENABLE_PRIORITY_ESCALATION
1 parent 6298d41 commit b5e039d

File tree

2 files changed

+42
-15
lines changed

2 files changed

+42
-15
lines changed

include/swift/Basic/HeaderFooterLayout.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,32 @@
1515

1616
namespace swift {
1717

18+
namespace detail {
19+
20+
template <ptrdiff_t size>
21+
struct LayoutPadding {
22+
char padding[size];
23+
};
24+
template <>
25+
struct LayoutPadding<0> {};
26+
1827
template <class Header, class Footer, size_t TotalSize>
19-
struct HeaderFooterLayoutPadding {
20-
private:
28+
struct HeaderFooterLayoutPaddingSize {
2129
enum : ptrdiff_t {
2230
maxFooterOffset = TotalSize - (ptrdiff_t)sizeof(Footer),
2331
footerAlignment = (ptrdiff_t)alignof(Footer),
2432
footerOffset = maxFooterOffset - (maxFooterOffset % footerAlignment),
25-
size = footerOffset - (ptrdiff_t)sizeof(Header)
33+
value = footerOffset - (ptrdiff_t)sizeof(Header)
2634
};
27-
char padding[size];
2835
};
2936

37+
} // namespace detail
38+
3039
template <class Header, class Footer, size_t TotalSize>
3140
struct HeaderFooterLayout
3241
: Header,
33-
HeaderFooterLayoutPadding<Header, Footer, TotalSize>,
42+
detail::LayoutPadding<detail::HeaderFooterLayoutPaddingSize<
43+
Header, Footer, TotalSize>::value>,
3444
Footer {};
3545

3646
} // namespace swift

stdlib/public/Concurrency/Actor.cpp

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,13 +1006,13 @@ class DefaultActorImplHeader : public HeapObject {
10061006
// escalation logic
10071007
Mutex drainLock;
10081008
#else
1009+
// TODO (rokhinip): Make this a flagset
1010+
bool isDistributedRemoteActor;
10091011
// Note: There is some padding that is added here by the compiler in order to
10101012
// enforce alignment. This is space that is available for us to use in
10111013
// the future
10121014
alignas(sizeof(ActiveActorStatus)) char StatusStorage[sizeof(ActiveActorStatus)];
10131015
#endif
1014-
// TODO (rokhinip): Make this a flagset
1015-
bool isDistributedRemoteActor;
10161016
};
10171017

10181018
// All the fields accessed under the actor's lock should be moved
@@ -1036,6 +1036,14 @@ class DefaultActorImplFooter {
10361036
#endif
10371037
};
10381038

1039+
// We can't use sizeof(DefaultActor) since the alignment requirement on the
1040+
// default actor means that we have some padding added when calculating
1041+
// sizeof(DefaultActor). However that padding isn't available for us to use
1042+
// in DefaultActorImpl.
1043+
enum {
1044+
DefaultActorSize = sizeof(void *) * NumWords_DefaultActor + sizeof(HeapObject)
1045+
};
1046+
10391047
/// The default actor implementation.
10401048
///
10411049
/// Ownership of the actor is subtle. Jobs are assumed to keep the actor
@@ -1088,8 +1096,13 @@ class DefaultActorImplFooter {
10881096
/// are (1), (3), (5), (6).
10891097
class DefaultActorImpl
10901098
: public HeaderFooterLayout<DefaultActorImplHeader, DefaultActorImplFooter,
1091-
sizeof(HeapObject) +
1092-
sizeof(void *) * NumWords_DefaultActor> {
1099+
DefaultActorSize> {
1100+
#pragma clang diagnostic push
1101+
#pragma clang diagnostic ignored "-Wunused-private-field"
1102+
/// Dummy variable, used to compute sizeWithoutTrailingPadding()
1103+
/// Must not be accessed
1104+
char const bytesPastTheEnd[1];
1105+
#pragma clang diagnostic pop
10931106
public:
10941107
/// Properly construct an actor, except for the heap header.
10951108
void initialize(bool isDistributedRemote = false) {
@@ -1159,6 +1172,13 @@ class DefaultActorImpl
11591172
}
11601173
#endif /* !SWIFT_CONCURRENCY_ACTORS_AS_LOCKS */
11611174

1175+
static constexpr size_t sizeWithoutTrailingPadding() {
1176+
#pragma clang diagnostic push
1177+
#pragma clang diagnostic ignored "-Winvalid-offsetof"
1178+
return offsetof(DefaultActorImpl, bytesPastTheEnd);
1179+
#pragma clang diagnostic pop
1180+
}
1181+
11621182
private:
11631183
#if !SWIFT_CONCURRENCY_ACTORS_AS_LOCKS
11641184
#if SWIFT_CONCURRENCY_ENABLE_PRIORITY_ESCALATION
@@ -1213,12 +1233,9 @@ class NonDefaultDistributedActorImpl : public HeapObject {
12131233

12141234
} /// end anonymous namespace
12151235

1216-
// We can't use sizeof(DefaultActor) since the alignment requirement on the
1217-
// default actor means that we have some padding added when calculating
1218-
// sizeof(DefaultActor). However that padding isn't available for us to use
1219-
// in DefaultActorImpl.
1220-
static_assert(sizeof(DefaultActorImpl) <= ((sizeof(void *) * NumWords_DefaultActor) + sizeof(HeapObject)) &&
1221-
alignof(DefaultActorImpl) <= alignof(DefaultActor),
1236+
static_assert(DefaultActorImpl::sizeWithoutTrailingPadding() ==
1237+
DefaultActorSize &&
1238+
alignof(DefaultActorImpl) <= alignof(DefaultActor),
12221239
"DefaultActorImpl doesn't fit in DefaultActor");
12231240
#if !SWIFT_CONCURRENCY_ACTORS_AS_LOCKS
12241241
static_assert(DefaultActorImpl::offsetOfActiveActorStatus() % ACTIVE_ACTOR_STATUS_SIZE == 0,

0 commit comments

Comments
 (0)