Skip to content

Commit 3699f72

Browse files
Merge pull request #61854 from aschwaighofer/irgen_fix_async_function_pointer_lowering
IRGen: Fix the type of function pointers for signatures with opaque result types
2 parents a56934a + 8e6e158 commit 3699f72

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,7 +2530,9 @@ class AsyncCallEmission final : public CallEmission {
25302530
getCallee().getFunctionPointer().getKind());
25312531

25322532
return FunctionPointer::createForAsyncCall(
2533-
calleeFunction, codeAuthInfo, awaitSig, awaitEntrySig.getType());
2533+
IGF.Builder.CreateBitCast(calleeFunction,
2534+
awaitEntrySig.getType()->getPointerTo()),
2535+
codeAuthInfo, awaitSig, awaitEntrySig.getType());
25342536
}
25352537

25362538
SILType getParameterType(unsigned index) override {
@@ -5355,6 +5357,12 @@ llvm::FunctionType *FunctionPointer::getFunctionType() const {
53555357
return cast<llvm::Function>(SecondaryValue)->getFunctionType();
53565358
}
53575359

5360+
if (awaitSignature) {
5361+
assert(llvm::cast<llvm::PointerType>(Value->getType())
5362+
->isOpaqueOrPointeeTypeMatches(awaitSignature));
5363+
return cast<llvm::FunctionType>(awaitSignature);
5364+
}
5365+
53585366
// Read the function type off the global or else from the Signature.
53595367
if (auto *constant = dyn_cast<llvm::Constant>(Value)) {
53605368
auto *gv = dyn_cast<llvm::GlobalValue>(Value);
@@ -5377,12 +5385,6 @@ llvm::FunctionType *FunctionPointer::getFunctionType() const {
53775385
return cast<llvm::FunctionType>(gv->getValueType());
53785386
}
53795387

5380-
if (awaitSignature) {
5381-
assert(llvm::cast<llvm::PointerType>(Value->getType())
5382-
->isOpaqueOrPointeeTypeMatches(awaitSignature));
5383-
return cast<llvm::FunctionType>(awaitSignature);
5384-
}
5385-
53865388
assert(llvm::cast<llvm::PointerType>(Value->getType())
53875389
->isOpaqueOrPointeeTypeMatches(Sig.getType()));
53885390
return Sig.getType();

test/IRGen/async.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend -primary-file %s -emit-ir -disable-availability-checking | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
2+
// RUN: %target-swift-frontend -primary-file %s -emit-ir -disable-availability-checking -enable-library-evolution
23

34
// REQUIRES: concurrency
45

@@ -29,3 +30,21 @@ public func testThis(_ task: __owned SomeClass) async {
2930
print("error")
3031
}
3132
}
33+
34+
35+
public protocol P {}
36+
37+
struct I : P{
38+
var x = 0
39+
}
40+
41+
public struct S {
42+
public func callee() async -> some P {
43+
return I()
44+
}
45+
// We used to assert on this in resilient mode due to mismatch function
46+
// pointers.
47+
public func caller() async -> some P {
48+
return await callee()
49+
}
50+
}

0 commit comments

Comments
 (0)