Skip to content

[OpaqueValues] Build objc thunk args with fn conv. #62858

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
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
3 changes: 2 additions & 1 deletion lib/SILGen/SILGenBridging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,7 @@ static SILFunctionType *emitObjCThunkArguments(SILGenFunction &SGF,
// Emit the other arguments, taking ownership of arguments if necessary.
auto inputs = objcFnTy->getParameters();
auto nativeInputs = swiftFnTy->getParameters();
auto fnConv = SGF.silConv.getFunctionConventions(swiftFnTy);
assert(nativeInputs.size() == bridgedFormalTypes.size());
assert(nativeInputs.size() == nativeFormalTypes.size());
assert(inputs.size() ==
Expand Down Expand Up @@ -1434,7 +1435,7 @@ static SILFunctionType *emitObjCThunkArguments(SILGenFunction &SGF,

// This can happen if the value is resilient in the calling convention
// but not resilient locally.
if (nativeInputs[i].isFormalIndirect() &&
if (fnConv.isSILIndirect(nativeInputs[i]) &&
!native.getType().isAddress()) {
auto buf = SGF.emitTemporaryAllocation(loc, native.getType());
native.forwardInto(SGF, loc, buf);
Expand Down
18 changes: 18 additions & 0 deletions test/SILGen/opaque_values_objc.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: %target-swift-emit-silgen -enable-sil-opaque-values -Xllvm -sil-full-demangle %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-runtime

// REQUIRES: objc_interop

import ObjectiveC

// CHECK-LABEL: sil {{.*}} @$s18opaque_values_objc3fooyyFyypSgcfU_To : {{.*}} {
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] : @owned $Optional<Any>
// CHECK: [[GUARANTEED:%[^,]+]] = begin_borrow [[INSTANCE]]
// CHECK: [[FN:%[^,]+]] = function_ref @$s18opaque_values_objc3fooyyFyypSgcfU_
// CHECK: apply [[FN]]([[GUARANTEED]])
// CHECK: end_borrow [[GUARANTEED]]
// CHECK: destroy_value [[INSTANCE]]
// CHECK-LABEL: } // end sil function '$s18opaque_values_objc3fooyyFyypSgcfU_To'
func foo() {
objc_setUncaughtExceptionHandler { _ in
}
}