Skip to content

Commit 619226b

Browse files
Fix calling convention mismatch on Builtin.getCurrentAsyncTask (swiftlang#37008)
* Add explicit calling convention on builtin GetCurrentTask This builtin function emits a call of swift_task_getCurrent, and user code can declare the same name function with slightly different signature at LLVM level (data size should be same) using @_silgen_name. In that case, IRGen insert cast inst to cast the function to the expected signature. But this cast inst drops calling convention info, so call inst was emitted without swiftcc. This patch changed to emit a call of swift_task_getCurrent with the explicit calling convention. * Add test case to ensure builtin function cc when conflict
1 parent b5a01ba commit 619226b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ void IRGenFunction::setupAsync(unsigned asyncContextIndex) {
230230
llvm::Value *IRGenFunction::getAsyncTask() {
231231
auto call = Builder.CreateCall(IGM.getGetCurrentTaskFn(), {});
232232
call->setDoesNotThrow();
233+
call->setCallingConv(IGM.SwiftCC);
233234
return call;
234235
}
235236

test/IRGen/builtin_conflict.sil

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-swift-frontend -emit-ir -parse-sil %s -parse-stdlib | %FileCheck %s
2+
3+
import Builtin
4+
import Swift
5+
6+
sil @entry : $@async @convention(thin) () -> () {
7+
bb0:
8+
%0 = function_ref @swift_task_getCurrent : $@convention(thin) () -> @owned Optional<Builtin.NativeObject>
9+
// CHECK: call swiftcc {{.*}} @swift_task_getCurrent
10+
%1 = apply %0() : $@convention(thin) () -> @owned Optional<Builtin.NativeObject>
11+
// CHECK-NEXT: call swiftcc {{.*}} @swift_task_getCurrent
12+
%3 = builtin "getCurrentAsyncTask"() : $Builtin.NativeObject
13+
return undef : $()
14+
}
15+
16+
sil hidden_external @swift_task_getCurrent : $@convention(thin) () -> @owned Optional<Builtin.NativeObject>

0 commit comments

Comments
 (0)