Skip to content

Commit f621890

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

File tree

2 files changed

+45
-21
lines changed

2 files changed

+45
-21
lines changed

include/swift/Basic/HeaderFooterLayout.h

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

1616
namespace swift {
1717

18-
template <class Header, class Footer, size_t TotalSize>
19-
struct HeaderFooterLayoutPadding {
20-
private:
21-
enum : ptrdiff_t {
22-
maxFooterOffset = TotalSize - (ptrdiff_t)sizeof(Footer),
23-
footerAlignment = (ptrdiff_t)alignof(Footer),
24-
footerOffset = maxFooterOffset - (maxFooterOffset % footerAlignment),
25-
size = footerOffset - (ptrdiff_t)sizeof(Header)
26-
};
27-
char padding[size];
18+
namespace detail {
19+
20+
template<ptrdiff_t size>
21+
struct LayoutPadding {
22+
char padding[size];
2823
};
24+
template<>
25+
struct LayoutPadding<0> {};
26+
27+
template<class Header, class Footer, size_t TotalSize>
28+
struct HeaderFooterLayoutPaddingSize {
29+
enum : ptrdiff_t {
30+
maxFooterOffset = TotalSize - (ptrdiff_t)sizeof(Footer),
31+
footerAlignment = (ptrdiff_t)alignof(Footer),
32+
footerOffset = maxFooterOffset - (maxFooterOffset % footerAlignment),
33+
value = footerOffset - (ptrdiff_t)sizeof(Header)
34+
};
35+
};
36+
37+
} //namespace detail
2938

3039
template <class Header, class Footer, size_t TotalSize>
3140
struct HeaderFooterLayout
3241
: Header,
33-
HeaderFooterLayoutPadding<Header, Footer, TotalSize>,
42+
detail::LayoutPadding<
43+
detail::HeaderFooterLayoutPaddingSize<Header, Footer, TotalSize>::value
44+
>,
3445
Footer {};
3546

3647
} // namespace swift

stdlib/public/Concurrency/Actor.cpp

Lines changed: 23 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,12 @@ 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 { DefaultActorSize = sizeof(void *) * NumWords_DefaultActor + sizeof(HeapObject) };
1044+
10391045
/// The default actor implementation.
10401046
///
10411047
/// Ownership of the actor is subtle. Jobs are assumed to keep the actor
@@ -1087,9 +1093,13 @@ class DefaultActorImplFooter {
10871093
/// exist yet. As a result, the subset of rules that currently apply
10881094
/// are (1), (3), (5), (6).
10891095
class DefaultActorImpl
1090-
: public HeaderFooterLayout<DefaultActorImplHeader, DefaultActorImplFooter,
1091-
sizeof(HeapObject) +
1092-
sizeof(void *) * NumWords_DefaultActor> {
1096+
: public HeaderFooterLayout<DefaultActorImplHeader, DefaultActorImplFooter, DefaultActorSize> {
1097+
#pragma clang diagnostic push
1098+
#pragma clang diagnostic ignored "-Wunused-private-field"
1099+
/// Dummy variable, used to compute sizeWithoutTrailingPadding()
1100+
/// Must not be accessed
1101+
char const bytesPastTheEnd[1];
1102+
#pragma clang diagnostic pop
10931103
public:
10941104
/// Properly construct an actor, except for the heap header.
10951105
void initialize(bool isDistributedRemote = false) {
@@ -1159,6 +1169,13 @@ class DefaultActorImpl
11591169
}
11601170
#endif /* !SWIFT_CONCURRENCY_ACTORS_AS_LOCKS */
11611171

1172+
static constexpr size_t sizeWithoutTrailingPadding() {
1173+
#pragma clang diagnostic push
1174+
#pragma clang diagnostic ignored "-Winvalid-offsetof"
1175+
return offsetof(DefaultActorImpl, bytesPastTheEnd);
1176+
#pragma clang diagnostic pop
1177+
}
1178+
11621179
private:
11631180
#if !SWIFT_CONCURRENCY_ACTORS_AS_LOCKS
11641181
#if SWIFT_CONCURRENCY_ENABLE_PRIORITY_ESCALATION
@@ -1213,11 +1230,7 @@ class NonDefaultDistributedActorImpl : public HeapObject {
12131230

12141231
} /// end anonymous namespace
12151232

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)) &&
1233+
static_assert(DefaultActorImpl::sizeWithoutTrailingPadding() == DefaultActorSize &&
12211234
alignof(DefaultActorImpl) <= alignof(DefaultActor),
12221235
"DefaultActorImpl doesn't fit in DefaultActor");
12231236
#if !SWIFT_CONCURRENCY_ACTORS_AS_LOCKS

0 commit comments

Comments
 (0)