Skip to content

Commit a8ff646

Browse files
committed
NFC: Fix unintialized variable warnings and C++20 extension warnings in concurrency related code.
1 parent 1be8913 commit a8ff646

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -652,15 +652,15 @@ class alignas(sizeof(void *) * 2) ActiveActorStatus {
652652
#if SWIFT_CONCURRENCY_ENABLE_PRIORITY_ESCALATION && SWIFT_POINTER_IS_4_BYTES
653653
uint32_t Flags;
654654
dispatch_lock_t DrainLock;
655-
uint32_t Unused;
655+
LLVM_ATTRIBUTE_UNUSED uint32_t Unused = {};
656656
#elif SWIFT_CONCURRENCY_ENABLE_PRIORITY_ESCALATION && SWIFT_POINTER_IS_8_BYTES
657657
uint32_t Flags;
658658
dispatch_lock_t DrainLock;
659659
#elif !SWIFT_CONCURRENCY_ENABLE_PRIORITY_ESCALATION && SWIFT_POINTER_IS_4_BYTES
660660
uint32_t Flags;
661661
#else /* !SWIFT_CONCURRENCY_ENABLE_PRIORITY_ESCALATION && SWIFT_POINTER_IS_8_BYTES */
662662
uint32_t Flags;
663-
uint32_t Unused;
663+
LLVM_ATTRIBUTE_UNUSED uint32_t Unused = {};
664664
#endif
665665
JobRef FirstJob;
666666

@@ -701,7 +701,7 @@ class alignas(sizeof(void *) * 2) ActiveActorStatus {
701701
bool isIdle() const {
702702
bool isIdle = (getActorState() == Idle);
703703
if (isIdle) {
704-
assert(FirstJob == NULL);
704+
assert(!FirstJob);
705705
}
706706
return isIdle;
707707
}
@@ -1063,7 +1063,7 @@ preprocessQueue(JobRef unprocessedStart, JobRef unprocessedEnd, Job *existingPro
10631063
// Preprocess the queue starting from the top
10641064
static Job *
10651065
preprocessQueue(JobRef start) {
1066-
if (start == NULL) {
1066+
if (!start) {
10671067
return NULL;
10681068
}
10691069

@@ -1081,7 +1081,7 @@ preprocessQueue(JobRef start) {
10811081
Job *wellFormedListStart = NULL;
10821082

10831083
auto current = start;
1084-
while (current != NULL) {
1084+
while (current) {
10851085
if (!current.needsPreprocessing()) {
10861086
// We can assume that everything from here onwards as being well formed
10871087
// and sorted
@@ -1241,7 +1241,7 @@ retry:;
12411241
}
12421242

12431243
assert(oldState.getMaxPriority() == JobPriority::Unspecified);
1244-
assert(oldState.getFirstJob() == NULL);
1244+
assert(!oldState.getFirstJob());
12451245
}
12461246

12471247
auto newState = oldState.withRunning();
@@ -1352,7 +1352,7 @@ bool DefaultActorImpl::unlock(bool forceUnlock)
13521352
}
13531353

13541354
auto newState = oldState;
1355-
if (oldState.getFirstJob() != NULL) {
1355+
if (oldState.getFirstJob()) {
13561356
// There is work left to do, don't unlock the actor
13571357
if (!forceUnlock) {
13581358
SWIFT_TASK_DEBUG_LOG("Unlock-ing actor %p failed", this);
@@ -1375,7 +1375,7 @@ bool DefaultActorImpl::unlock(bool forceUnlock)
13751375

13761376
if (newState.isScheduled()) {
13771377
// See ownership rule (6) in DefaultActorImpl
1378-
assert(newState.getFirstJob() != NULL);
1378+
assert(newState.getFirstJob());
13791379
scheduleActorProcessJob(newState.getMaxPriority(), true);
13801380
} else {
13811381
// See ownership rule (5) in DefaultActorImpl

stdlib/public/Concurrency/TaskPrivate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,15 @@ class alignas(2 * sizeof(void*)) ActiveTaskStatus {
298298
#if SWIFT_CONCURRENCY_ENABLE_PRIORITY_ESCALATION && SWIFT_POINTER_IS_4_BYTES
299299
uint32_t Flags;
300300
dispatch_lock_t ExecutionLock;
301-
uint32_t Unused;
301+
LLVM_ATTRIBUTE_UNUSED uint32_t Unused = {};
302302
#elif SWIFT_CONCURRENCY_ENABLE_PRIORITY_ESCALATION && SWIFT_POINTER_IS_8_BYTES
303303
uint32_t Flags;
304304
dispatch_lock_t ExecutionLock;
305305
#elif !SWIFT_CONCURRENCY_ENABLE_PRIORITY_ESCALATION && SWIFT_POINTER_IS_4_BYTES
306306
uint32_t Flags;
307307
#else /* !SWIFT_CONCURRENCY_ENABLE_PRIORITY_ESCALATION && SWIFT_POINTER_IS_8_BYTES */
308308
uint32_t Flags;
309-
uint32_t Unused;
309+
LLVM_ATTRIBUTE_UNUSED uint32_t Unused = {};
310310
#endif
311311
TaskStatusRecord *Record;
312312

stdlib/public/runtime/StackAllocator.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ class StackAllocator {
7171
/// The first slab.
7272
Slab *firstSlab;
7373

74+
/// True if the first slab is pre-allocated.
7475
uint32_t firstSlabIsPreallocated:1;
7576
/// Used for unit testing.
76-
uint32_t numAllocatedSlabs:31 = 0;
77+
uint32_t numAllocatedSlabs:31;
7778

78-
/// True if the first slab is pre-allocated.
7979

8080
/// The minimal alignment of allocated memory.
8181
static constexpr size_t alignment = MaximumAlignment;
@@ -278,7 +278,9 @@ class StackAllocator {
278278

279279
public:
280280
/// Construct a StackAllocator without a pre-allocated first slab.
281-
StackAllocator() : firstSlab(nullptr), firstSlabIsPreallocated(false) { }
281+
StackAllocator()
282+
: firstSlab(nullptr), firstSlabIsPreallocated(false),
283+
numAllocatedSlabs(0) {}
282284

283285
/// Construct a StackAllocator with a pre-allocated first slab.
284286
StackAllocator(void *firstSlabBuffer, size_t bufferCapacity) {
@@ -289,6 +291,7 @@ class StackAllocator {
289291
"buffer for first slab too small");
290292
firstSlab = new (start) Slab(end - start - Slab::headerSize());
291293
firstSlabIsPreallocated = true;
294+
numAllocatedSlabs = 0;
292295
}
293296

294297
~StackAllocator() {

0 commit comments

Comments
 (0)