Skip to content

Commit 927758f

Browse files
committed
[OpaqueValues] Build objc thunk args with fn conv.
Used the function convention to determine whether a SILParameterInfo is indirect when emitting objc thunk arguments.
1 parent 0d52c41 commit 927758f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/SILGen/SILGenBridging.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,7 @@ static SILFunctionType *emitObjCThunkArguments(SILGenFunction &SGF,
13641364
// Emit the other arguments, taking ownership of arguments if necessary.
13651365
auto inputs = objcFnTy->getParameters();
13661366
auto nativeInputs = swiftFnTy->getParameters();
1367+
auto fnConv = SGF.silConv.getFunctionConventions(swiftFnTy);
13671368
assert(nativeInputs.size() == bridgedFormalTypes.size());
13681369
assert(nativeInputs.size() == nativeFormalTypes.size());
13691370
assert(inputs.size() ==
@@ -1434,7 +1435,7 @@ static SILFunctionType *emitObjCThunkArguments(SILGenFunction &SGF,
14341435

14351436
// This can happen if the value is resilient in the calling convention
14361437
// but not resilient locally.
1437-
if (nativeInputs[i].isFormalIndirect() &&
1438+
if (fnConv.isSILIndirect(nativeInputs[i]) &&
14381439
!native.getType().isAddress()) {
14391440
auto buf = SGF.emitTemporaryAllocation(loc, native.getType());
14401441
native.forwardInto(SGF, loc, buf);

test/SILGen/opaque_values_objc.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-swift-emit-silgen -enable-sil-opaque-values -Xllvm -sil-full-demangle %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-runtime
2+
3+
// REQUIRES: objc_interop
4+
5+
import ObjectiveC
6+
7+
// CHECK-LABEL: sil {{.*}} @$s18opaque_values_objc3fooyyFyypSgcfU_To : {{.*}} {
8+
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] : @owned $Optional<Any>
9+
// CHECK: [[GUARANTEED:%[^,]+]] = begin_borrow [[INSTANCE]]
10+
// CHECK: [[FN:%[^,]+]] = function_ref @$s18opaque_values_objc3fooyyFyypSgcfU_
11+
// CHECK: apply [[FN]]([[GUARANTEED]])
12+
// CHECK: end_borrow [[GUARANTEED]]
13+
// CHECK: destroy_value [[INSTANCE]]
14+
// CHECK-LABEL: } // end sil function '$s18opaque_values_objc3fooyyFyypSgcfU_To'
15+
func foo() {
16+
objc_setUncaughtExceptionHandler { _ in
17+
}
18+
}

0 commit comments

Comments
 (0)