Skip to content

Commit 51ff578

Browse files
committed
[OpaqueValues] Don't emit temporary in one case.
When creating a foreign-to-native thunk, create a temporary when the foreign convention is indirect-non-inout only when using lowered addresses.
1 parent cc3038d commit 51ff578

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/SILGen/SILGenBridging.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,13 +2242,15 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) {
22422242
auto bridged = emitNativeToBridgedValue(fd, param, nativeFormalType,
22432243
foreignFormalType,
22442244
foreignLoweredTy);
2245-
if (foreignParam.getConvention() == ParameterConvention::Indirect_In ||
2246-
foreignParam.getConvention() == ParameterConvention::Indirect_In_Guaranteed) {
2245+
if (useLoweredAddresses() &&
2246+
(foreignParam.getConvention() == ParameterConvention::Indirect_In ||
2247+
foreignParam.getConvention() ==
2248+
ParameterConvention::Indirect_In_Guaranteed)) {
22472249
auto temp = emitTemporaryAllocation(fd, bridged.getType());
22482250
bridged.forwardInto(*this, fd, temp);
22492251
bridged = emitManagedBufferWithCleanup(temp);
22502252
}
2251-
2253+
22522254
if (memberStatus.isInstance() && isSelf) {
22532255
// Fill in the `self` space.
22542256
args[memberStatus.getSelfIndex()] = bridged;

test/SILGen/opaque_values_cxx.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
// RUN: %target-swift-emit-silgen -enable-sil-opaque-values -Xllvm -sil-full-demangle -cxx-interoperability-mode=swift-5.9 -import-objc-header %S/Inputs/opaque_values_cxx.h -primary-file %s | %FileCheck %s --check-prefix=CHECK
22

3+
// TODO: Find the relevant mangled name instead of
4+
// $sSo3stdO3__1O0020___wrap_iter__udAAdDaVSQSCSQ2eeoiySbx_xtFZTW for other
5+
// platforms.
6+
// REQUIRES: VENDOR=apple
7+
38
import Cxx
49

510
// CHECK-LABEL: sil {{.*}}[ossa] @$sSo3stdO{{(3__1O)?}}0042vectorUInt32allocatorUInt32_mzFHjGjjqraEeaV3Cxx0B8SequenceSCA{{.*}}P13__beginUnsafe11RawIteratorQzyFTW : {{.*}} {
@@ -10,6 +15,12 @@ import Cxx
1015
// CHECK: end_borrow [[VECTOR]]
1116
// CHECK: return [[BEGIN]]
1217
// CHECK-LABEL: } // end sil function '$sSo3stdO{{(3__1O)?}}0042vectorUInt32allocatorUInt32_mzFHjGjjqraEeaV3Cxx0B8SequenceSCA{{.*}}P13__beginUnsafe11RawIteratorQzyFTW'
18+
// CHECK-LABEL: sil {{.*}}[ossa] @$sSo3stdO{{(3__1O)?}}0020___wrap_iter__udAAdDaVSQSCSQ2eeoiySbx_xtFZTW : {{.*}} {
19+
// CHECK: bb0([[LHS:%[^,]+]] : $std.__1.__wrap_iter<_>, [[RHS:%[^,]+]] :
20+
// CHECK: [[CALLEE:%[^,]+]] = function_ref @$sSo2eeoiySbSo3stdO{{(3__1O)?}}0020___wrap_iter__udAAdDaV_AGtFTO
21+
// CHECK: [[EQUAL:%[^,]+]] = apply [[CALLEE]]([[LHS]], [[RHS]])
22+
// CHECK: return [[EQUAL]]
23+
// CHECK-LABEL: } // end sil function '$sSo3stdO{{(3__1O)?}}0020___wrap_iter__udAAdDaVSQSCSQ2eeoiySbx_xtFZTW'
1324
func test_cxx_vector_uint32t_iterate(_ n: Int, _ vectorOfU32: VectorOfU32) {
1425
for x in vectorOfU32 {}
1526
}

0 commit comments

Comments
 (0)