Skip to content

Commit 5536114

Browse files
committed
[IRGen] Return unsigned context from resume_project_context.
In __swift_async_resume_project_context, the context is stored into the extended frame. On arm64e, it is signed first. Previously, that signed context was returned fro the function. That resulted in code like pacda x16, x10 str x16, [x9] ldr x9, [x16, #0x48] where the context is signed (pacda), stored into the extended frame (str) and then an attempt is made to load from the signed context (ldr). Here, the unsigned context is returned from the function.
1 parent 7226070 commit 5536114

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/IRGen/GenFunc.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2401,6 +2401,7 @@ llvm::Function *IRGenFunction::getOrCreateResumePrjFn() {
24012401
// TODO: remove this once all platforms support lowering the intrinsic.
24022402
// At the time of this writing only arm64 supports it.
24032403
if (IGM.TargetInfo.canUseSwiftAsyncContextAddrIntrinsic()) {
2404+
llvm::Value *storedCallerContext = callerContext;
24042405
auto contextLocationInExtendedFrame =
24052406
Address(Builder.CreateIntrinsicCall(
24062407
llvm::Intrinsic::swift_async_context_addr, {}),
@@ -2412,9 +2413,9 @@ llvm::Function *IRGenFunction::getOrCreateResumePrjFn() {
24122413
auto authInfo = PointerAuthInfo::emit(
24132414
IGF, schema, contextLocationInExtendedFrame.getAddress(),
24142415
PointerAuthEntity());
2415-
callerContext = emitPointerAuthSign(IGF, callerContext, authInfo);
2416+
storedCallerContext = emitPointerAuthSign(IGF, storedCallerContext, authInfo);
24162417
}
2417-
Builder.CreateStore(callerContext, contextLocationInExtendedFrame);
2418+
Builder.CreateStore(storedCallerContext, contextLocationInExtendedFrame);
24182419
}
24192420
Builder.CreateRet(callerContext);
24202421
},

test/IRGen/async/hop_to_executor.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final actor class MyActor {
2929
// CHECK-arm64e: [[SIGNED_RESUME:%[0-9]+]] = inttoptr i64 [[SIGNED_INT]] to i8*
3030
// CHECK: [[CAST_ACTOR:%[0-9]+]] = bitcast %T4test7MyActorC* [[ACTOR]] to %swift.executor*
3131
// CHECK-x86_64: call {{.*}} @llvm.coro.suspend.async(i8* [[RESUME]], i8* bitcast (i8* (i8*)* @__swift_async_resume_get_context to i8*), i8* bitcast (void (i8*, %swift.executor*, %swift.task*, %swift.executor*, %swift.context*)* @__swift_suspend_point to i8*), i8* [[RESUME]], %swift.executor* [[CAST_ACTOR]], %swift.task* [[TASK]], %swift.executor* {{%[0-9]+}}, %swift.context* {{%[0-9]+}})
32-
// CHECK-arm64e: call {{.*}} @llvm.coro.suspend.async(i8* [[SIGNED_RESUME]], i8* bitcast (i8* (i8*)* @__swift_async_resume_get_context to i8*), i8* bitcast (void (i8*, %swift.executor*, %swift.task*, %swift.executor*, %swift.context*)* @__swift_suspend_point to i8*), i8* [[SIGNED_RESUME]], %swift.executor* [[CAST_ACTOR]], %swift.task* [[TASK]], %swift.executor* {{%[0-9]+}}, %swift.context* {{%[0-9]+}})
32+
// CHECK-arm64e: call {{.*}} @llvm.coro.suspend.async(i8* [[RESUME]], i8* bitcast (i8* (i8*)* @__swift_async_resume_get_context to i8*), i8* bitcast (void (i8*, %swift.executor*, %swift.task*, %swift.executor*, %swift.context*)* @__swift_suspend_point to i8*), i8* [[SIGNED_RESUME]], %swift.executor* [[CAST_ACTOR]], %swift.task* [[TASK]], %swift.executor* {{%[0-9]+}}, %swift.context* {{%[0-9]+}})
3333
sil @test_simple : $@convention(method) @async (@guaranteed MyActor) -> () {
3434
bb0(%0 : $MyActor):
3535
hop_to_executor %0 : $MyActor

0 commit comments

Comments
 (0)