Skip to content

Commit 481d8ba

Browse files
Merge pull request #38089 from aschwaighofer/workaround_armv7k_async_lowering_bug
Runtime: Workaround armv7k code lowering bug
2 parents 61805a5 + 9263f61 commit 481d8ba

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

stdlib/public/Concurrency/Task.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,22 @@ AsyncTaskAndContext swift::swift_task_create(
682682
initialContextSize);
683683
}
684684

685+
#ifdef __ARM_ARCH_7K__
686+
__attribute__((noinline))
687+
SWIFT_CC(swiftasync) static void workaround_function_swift_task_future_waitImpl(
688+
OpaqueValue *result, SWIFT_ASYNC_CONTEXT AsyncContext *callerContext,
689+
AsyncTask *task, TaskContinuationFunction resumeFunction,
690+
AsyncContext *callContext) {
691+
// Make sure we don't eliminate calls to this function.
692+
asm volatile("" // Do nothing.
693+
: // Output list, empty.
694+
: "r"(result), "r"(callerContext), "r"(task) // Input list.
695+
: // Clobber list, empty.
696+
);
697+
return;
698+
}
699+
#endif
700+
685701
SWIFT_CC(swiftasync)
686702
static void swift_task_future_waitImpl(
687703
OpaqueValue *result,
@@ -701,7 +717,12 @@ static void swift_task_future_waitImpl(
701717
result)) {
702718
case FutureFragment::Status::Executing:
703719
// The waiting task has been queued on the future.
720+
#ifdef __ARM_ARCH_7K__
721+
return workaround_function_swift_task_future_waitImpl(
722+
result, callerContext, task, resumeFn, callContext);
723+
#else
704724
return;
725+
#endif
705726

706727
case FutureFragment::Status::Success: {
707728
// Run the task with a successful result.
@@ -716,6 +737,22 @@ static void swift_task_future_waitImpl(
716737
}
717738
}
718739

740+
#ifdef __ARM_ARCH_7K__
741+
__attribute__((noinline))
742+
SWIFT_CC(swiftasync) static void workaround_function_swift_task_future_wait_throwingImpl(
743+
OpaqueValue *result, SWIFT_ASYNC_CONTEXT AsyncContext *callerContext,
744+
AsyncTask *task, ThrowingTaskFutureWaitContinuationFunction resumeFunction,
745+
AsyncContext *callContext) {
746+
// Make sure we don't eliminate calls to this function.
747+
asm volatile("" // Do nothing.
748+
: // Output list, empty.
749+
: "r"(result), "r"(callerContext), "r"(task) // Input list.
750+
: // Clobber list, empty.
751+
);
752+
return;
753+
}
754+
#endif
755+
719756
SWIFT_CC(swiftasync)
720757
void swift_task_future_wait_throwingImpl(
721758
OpaqueValue *result, SWIFT_ASYNC_CONTEXT AsyncContext *callerContext,
@@ -736,7 +773,12 @@ void swift_task_future_wait_throwingImpl(
736773
result)) {
737774
case FutureFragment::Status::Executing:
738775
// The waiting task has been queued on the future.
776+
#ifdef __ARM_ARCH_7K__
777+
return workaround_function_swift_task_future_wait_throwingImpl(
778+
result, callerContext, task, resumeFunction, callContext);
779+
#else
739780
return;
781+
#endif
740782

741783
case FutureFragment::Status::Success: {
742784
auto future = task->futureFragment();

stdlib/public/Concurrency/TaskGroup.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,23 @@ task_group_wait_resume_adapter(SWIFT_ASYNC_CONTEXT AsyncContext *_context) {
648648
return resumeWithError(context->Parent, context->errorResult);
649649
}
650650

651+
#ifdef __ARM_ARCH_7K__
652+
__attribute__((noinline))
653+
SWIFT_CC(swiftasync) static void workaround_function_swift_taskGroup_wait_next_throwingImpl(
654+
OpaqueValue *result, SWIFT_ASYNC_CONTEXT AsyncContext *callerContext,
655+
TaskGroup *_group,
656+
ThrowingTaskFutureWaitContinuationFunction resumeFunction,
657+
AsyncContext *callContext) {
658+
// Make sure we don't eliminate calls to this function.
659+
asm volatile("" // Do nothing.
660+
: // Output list, empty.
661+
: "r"(result), "r"(callerContext), "r"(_group) // Input list.
662+
: // Clobber list, empty.
663+
);
664+
return;
665+
}
666+
#endif
667+
651668
// =============================================================================
652669
// ==== group.next() implementation (wait_next and groupPoll) ------------------
653670
SWIFT_CC(swiftasync)
@@ -675,7 +692,12 @@ static void swift_taskGroup_wait_next_throwingImpl(
675692
case PollStatus::MustWait:
676693
// The waiting task has been queued on the channel,
677694
// there were pending tasks so it will be woken up eventually.
695+
#ifdef __ARM_ARCH_7K__
696+
return workaround_function_swift_taskGroup_wait_next_throwingImpl(
697+
resultPointer, callerContext, _group, resumeFunction, rawContext);
698+
#else
678699
return;
700+
#endif
679701

680702
case PollStatus::Empty:
681703
case PollStatus::Error:

0 commit comments

Comments
 (0)