Skip to content

Commit 4ab3aae

Browse files
committed
Gardening: Suppress -Winvalid-offsetof warnings in static asserts.
There cannot be undefined behavior at compile time, so these warnings can be ignored when `offsetof` is used in a static assert: ``` warning: offset of on non-standard-layout type 'AsyncTask' [-Winvalid-offsetof] ```
1 parent 2de8e5a commit 4ab3aae

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

include/swift/ABI/Task.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,9 +736,12 @@ static_assert(sizeof(AsyncTask) == NumWords_AsyncTask * sizeof(void*),
736736
"AsyncTask size is wrong");
737737
static_assert(alignof(AsyncTask) == 2 * alignof(void*),
738738
"AsyncTask alignment is wrong");
739+
#pragma clang diagnostic push
740+
#pragma clang diagnostic ignored "-Winvalid-offsetof"
739741
// Libc hardcodes this offset to extract the TaskID
740742
static_assert(offsetof(AsyncTask, Id) == 4 * sizeof(void *) + 4,
741743
"AsyncTask::Id offset is wrong");
744+
#pragma clang diagnostic pop
742745

743746
SWIFT_CC(swiftasync)
744747
inline void Job::runInFullyEstablishedContext() {

stdlib/public/Concurrency/TaskPrivate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,8 +865,11 @@ struct AsyncTask::PrivateStorage {
865865

866866
// It will be aligned to 2 words on all platforms. On arm64_32, we have an
867867
// additional requirement where it is aligned to 4 words.
868+
#pragma clang diagnostic push
869+
#pragma clang diagnostic ignored "-Winvalid-offsetof"
868870
static_assert(((offsetof(AsyncTask, Private) + offsetof(AsyncTask::PrivateStorage, StatusStorage)) % ACTIVE_TASK_STATUS_SIZE == 0),
869871
"StatusStorage is not aligned in the AsyncTask");
872+
#pragma clang diagnostic pop
870873
static_assert(sizeof(AsyncTask::PrivateStorage) <= sizeof(AsyncTask::OpaquePrivateStorage),
871874
"Task-private storage doesn't fit in reserved space");
872875

stdlib/toolchain/Compatibility56/include/Concurrency/Task.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,12 @@ static_assert(sizeof(AsyncTask) == NumWords_AsyncTask * sizeof(void*),
605605
"AsyncTask size is wrong");
606606
static_assert(alignof(AsyncTask) == 2 * alignof(void*),
607607
"AsyncTask alignment is wrong");
608+
#pragma clang diagnostic push
609+
#pragma clang diagnostic ignored "-Winvalid-offsetof"
608610
// Libc hardcodes this offset to extract the TaskID
609611
static_assert(offsetof(AsyncTask, Id) == 4 * sizeof(void *) + 4,
610612
"AsyncTask::Id offset is wrong");
613+
#pragma clang diagnostic pop
611614

612615
SWIFT_CC(swiftasync)
613616
inline void Job::runInFullyEstablishedContext() {

0 commit comments

Comments
 (0)