Skip to content

Commit 6b8ffc0

Browse files
committed
semaphore: annotate fallthrough (NFC)
Address `-Werror,-Wimplicit-fallthrough` as identified by clang. This fixes a couple of build warnings which are treated as errors. NFC.
1 parent f6e30ed commit 6b8ffc0

File tree

6 files changed

+40
-9
lines changed

6 files changed

+40
-9
lines changed

dispatch/base.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,33 @@
127127
#define DISPATCH_UNAVAILABLE_MSG(msg)
128128
#endif
129129

130+
#if defined(__cplusplus)
131+
# if __cplusplus >= 201703L
132+
# define DISPATCH_FALLTHROUGH [[fallthrough]]
133+
# elif __cplusplus >= 201103L
134+
# if defined(__clang__)
135+
# define DISPATCH_FALLTHROUGH [[clang::fallthrough]]
136+
# elif defined(__GNUC__) && __GNUC__ >= 7
137+
# define DISPATCH_FALLTHROUGH [[gnu::fallthrough]]
138+
# else
139+
# define DISPATCH_FALLTHROUGH
140+
# endif
141+
# else
142+
# define DISPATCH_FALLTHROUGH
143+
# endif
144+
#elif defined(__GNUC__) && __GNUC__ >= 7
145+
# define DISPATCH_FALLTHROUGH __attribute__((__fallthrough__))
146+
#elif defined(__clang__)
147+
# if __has_attribute(fallthrough) && __clang_major__ >= 5
148+
# define DISPATCH_FALLTHROUGH __attribute__((__fallthrough__))
149+
# else
150+
# define DISPATCH_FALLTHROUGH
151+
# endif
152+
#else
153+
# define DISPATCH_FALLTHROUGH
154+
#endif
155+
156+
130157
#ifdef __linux__
131158
#define DISPATCH_LINUX_UNAVAILABLE() \
132159
DISPATCH_UNAVAILABLE_MSG( \

src/event/event_epoll.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ _dispatch_muxnote_create(dispatch_unote_t du, uint32_t events)
174174
}
175175
case EVFILT_WRITE:
176176
filter = EVFILT_READ;
177+
DISPATCH_FALLTHROUGH;
177178
case EVFILT_READ:
178179
if (fstat(fd, &sb) < 0) {
179180
return NULL;

src/io.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,12 +2085,12 @@ _dispatch_stream_handler(void *ctx)
20852085
switch (result) {
20862086
case DISPATCH_OP_DELIVER:
20872087
flags = DOP_DEFAULT;
2088-
// Fall through
2088+
DISPATCH_FALLTHROUGH;
20892089
case DISPATCH_OP_DELIVER_AND_COMPLETE:
20902090
flags = (flags != DOP_DEFAULT) ? DOP_DELIVER | DOP_NO_EMPTY :
20912091
DOP_DEFAULT;
20922092
_dispatch_operation_deliver_data(op, flags);
2093-
// Fall through
2093+
DISPATCH_FALLTHROUGH;
20942094
case DISPATCH_OP_COMPLETE:
20952095
if (flags != DOP_DEFAULT) {
20962096
_dispatch_stream_complete_operation(stream, op);
@@ -2102,7 +2102,7 @@ _dispatch_stream_handler(void *ctx)
21022102
break;
21032103
case DISPATCH_OP_COMPLETE_RESUME:
21042104
_dispatch_stream_complete_operation(stream, op);
2105-
// Fall through
2105+
DISPATCH_FALLTHROUGH;
21062106
case DISPATCH_OP_RESUME:
21072107
if (_dispatch_stream_operation_avail(stream)) {
21082108
stream->source_running = true;

src/semaphore.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ _dispatch_semaphore_wait_slow(dispatch_semaphore_t dsema,
116116
if (!_dispatch_sema4_timedwait(&dsema->dsema_sema, timeout)) {
117117
break;
118118
}
119-
// Fall through and try to undo what the fast path did to
120-
// dsema->dsema_value
119+
// Try to undo what the fast path did to dsema->dsema_value
120+
DISPATCH_FALLTHROUGH;
121121
case DISPATCH_TIME_NOW:
122122
orig = dsema->dsema_value;
123123
while (orig < 0) {
@@ -126,8 +126,8 @@ _dispatch_semaphore_wait_slow(dispatch_semaphore_t dsema,
126126
return _DSEMA4_TIMEOUT();
127127
}
128128
}
129-
// Another thread called semaphore_signal().
130-
// Fall through and drain the wakeup.
129+
// Another thread called semaphore_signal(). Drain the wakeup.
130+
DISPATCH_FALLTHROUGH;
131131
case DISPATCH_TIME_FOREVER:
132132
_dispatch_sema4_wait(&dsema->dsema_sema);
133133
break;

src/shims/lock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ _dlock_wait(uint32_t *uaddr, uint32_t val, uint32_t timeout, uint32_t flags)
338338
if (timeout == 0) {
339339
continue;
340340
}
341-
/* FALLTHROUGH */
341+
DISPATCH_FALLTHROUGH;
342342
case ETIMEDOUT:
343343
case EFAULT:
344344
return -rc;
@@ -427,7 +427,7 @@ _futex_blocking_op(uint32_t *uaddr, int futex_op, uint32_t val,
427427
if (timeout == 0) {
428428
continue;
429429
}
430-
/* FALLTHROUGH */
430+
DISPATCH_FALLTHROUGH;
431431
case ETIMEDOUT:
432432
case EFAULT:
433433
case EWOULDBLOCK:

src/transform.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,11 +781,14 @@ _dispatch_transform_to_base32_with_table(dispatch_data_t data, const unsigned ch
781781
case 1:
782782
*ptr++ = '='; // c
783783
*ptr++ = '='; // d
784+
DISPATCH_FALLTHROUGH;
784785
case 2:
785786
*ptr++ = '='; // e
787+
DISPATCH_FALLTHROUGH;
786788
case 3:
787789
*ptr++ = '='; // f
788790
*ptr++ = '='; // g
791+
DISPATCH_FALLTHROUGH;
789792
case 4:
790793
*ptr++ = '='; // h
791794
break;

0 commit comments

Comments
 (0)