Skip to content

Commit b931348

Browse files
committed
Fix asyncMainDrainQueue noreturn warning
The async main drain queue function is noreturn, but was emitting a warning due to the override compatibility returning the result of the overridden function in the wrapper override function. To work around this, I've added the `OVERRIDE_TASK_NORETURN` macro, which provides an override point for noreturn functions in the concurrency library that doesn't return the result from the wrapped function, avoiding the warning. In the event that the function is not set, the macro is set to the normal `OVERRIDE` with the return type set to `void`.
1 parent ecc241a commit b931348

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

stdlib/public/CompatibilityOverride/CompatibilityOverrideConcurrency.def

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747
# define OVERRIDE_TASK_GROUP OVERRIDE
4848
# define OVERRIDE_TASK_LOCAL OVERRIDE
4949
# define OVERRIDE_TASK_STATUS OVERRIDE
50+
#ifndef OVERRIDE_TASK_NORETURN
51+
# define OVERRIDE_TASK_NORETURN(name, attrs, ccAttrs, namespace, typedArgs, \
52+
namedArgs) \
53+
OVERRIDE(name, void, attrs, ccAttrs, namespace, typedArgs, namedArgs)
54+
#endif
5055
#else
5156
# ifndef OVERRIDE_ACTOR
5257
# define OVERRIDE_ACTOR(...)
@@ -66,6 +71,9 @@
6671
# ifndef OVERRIDE_TASK_STATUS
6772
# define OVERRIDE_TASK_STATUS(...)
6873
# endif
74+
# ifndef OVERRIDE_TASK_NORETURN
75+
# define OVERRIDE_TASK_NORETURN(...)
76+
# endif
6977
#endif
7078

7179
OVERRIDE_ACTOR(task_enqueue, void,
@@ -151,7 +159,7 @@ OVERRIDE_TASK(task_createNullaryContinuationJob, NullaryContinuationJob *,
151159
(size_t priority,
152160
AsyncTask *continuation), (priority, continuation))
153161

154-
OVERRIDE_TASK(task_asyncMainDrainQueue, void,
162+
OVERRIDE_TASK_NORETURN(task_asyncMainDrainQueue,
155163
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift), swift::,
156164
, )
157165

@@ -339,3 +347,4 @@ OVERRIDE_TASK_STATUS(task_getNearestDeadline, NearestTaskDeadline,
339347
#undef OVERRIDE_TASK_GROUP
340348
#undef OVERRIDE_TASK_LOCAL
341349
#undef OVERRIDE_TASK_STATUS
350+
#undef OVERRIDE_TASK_NORETURN

stdlib/public/Concurrency/Task.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,4 +1561,22 @@ static void swift_task_asyncMainDrainQueueImpl() {
15611561
}
15621562

15631563
#define OVERRIDE_TASK COMPATIBILITY_OVERRIDE
1564+
1565+
/// The original COMPATIBILITY_OVERRIDE defined in CompatibilityOverride.h
1566+
/// returns the result of the impl function and override function. This results
1567+
/// in a warning emitted for noreturn functions. Overriding the override macro
1568+
/// to not return.
1569+
#define OVERRIDE_TASK_NORETURN(name, attrs, ccAttrs, namespace, typedArgs, \
1570+
namedArgs) \
1571+
attrs ccAttrs void namespace swift_##name COMPATIBILITY_PAREN(typedArgs) { \
1572+
static Override_##name Override; \
1573+
static swift_once_t Predicate; \
1574+
swift_once( \
1575+
&Predicate, [](void *) { Override = getOverride_##name(); }, nullptr); \
1576+
if (Override != nullptr) \
1577+
Override(COMPATIBILITY_UNPAREN_WITH_COMMA(namedArgs) \
1578+
swift_##name##Impl); \
1579+
swift_##name##Impl COMPATIBILITY_PAREN(namedArgs); \
1580+
}
1581+
15641582
#include COMPATIBILITY_OVERRIDE_INCLUDE_PATH

unittests/runtime/CompatibilityOverrideConcurrency.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ ExecutorRef getEmptyValue() {
4444
Ran = true; \
4545
return getEmptyValue<ret>(); \
4646
}
47+
#define OVERRIDE_TASK_NORETURN(name, attrs, ccAttrs, namespace, typedArgs, \
48+
namedArgs) \
49+
static ccAttrs void name##Override(COMPATIBILITY_UNPAREN_WITH_COMMA( \
50+
typedArgs) Original_##name originalImpl) { \
51+
if (!EnableOverride) \
52+
originalImpl COMPATIBILITY_PAREN(namedArgs); \
53+
Ran = true; \
54+
}
55+
4756
#include "../../stdlib/public/CompatibilityOverride/CompatibilityOverrideConcurrency.def"
4857

4958
struct OverrideSection {

0 commit comments

Comments
 (0)