Skip to content

IRGen: Fix the type of function pointers for signatures with opaque result types #61854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lib/IRGen/GenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2530,7 +2530,9 @@ class AsyncCallEmission final : public CallEmission {
getCallee().getFunctionPointer().getKind());

return FunctionPointer::createForAsyncCall(
calleeFunction, codeAuthInfo, awaitSig, awaitEntrySig.getType());
IGF.Builder.CreateBitCast(calleeFunction,
awaitEntrySig.getType()->getPointerTo()),
codeAuthInfo, awaitSig, awaitEntrySig.getType());
}

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

if (awaitSignature) {
assert(llvm::cast<llvm::PointerType>(Value->getType())
->isOpaqueOrPointeeTypeMatches(awaitSignature));
return cast<llvm::FunctionType>(awaitSignature);
}

// Read the function type off the global or else from the Signature.
if (auto *constant = dyn_cast<llvm::Constant>(Value)) {
auto *gv = dyn_cast<llvm::GlobalValue>(Value);
Expand All @@ -5377,12 +5385,6 @@ llvm::FunctionType *FunctionPointer::getFunctionType() const {
return cast<llvm::FunctionType>(gv->getValueType());
}

if (awaitSignature) {
assert(llvm::cast<llvm::PointerType>(Value->getType())
->isOpaqueOrPointeeTypeMatches(awaitSignature));
return cast<llvm::FunctionType>(awaitSignature);
}

assert(llvm::cast<llvm::PointerType>(Value->getType())
->isOpaqueOrPointeeTypeMatches(Sig.getType()));
return Sig.getType();
Expand Down
19 changes: 19 additions & 0 deletions test/IRGen/async.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %target-swift-frontend -primary-file %s -emit-ir -disable-availability-checking | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
// RUN: %target-swift-frontend -primary-file %s -emit-ir -disable-availability-checking -enable-library-evolution

// REQUIRES: concurrency

Expand Down Expand Up @@ -29,3 +30,21 @@ public func testThis(_ task: __owned SomeClass) async {
print("error")
}
}


public protocol P {}

struct I : P{
var x = 0
}

public struct S {
public func callee() async -> some P {
return I()
}
// We used to assert on this in resilient mode due to mismatch function
// pointers.
public func caller() async -> some P {
return await callee()
}
}