Skip to content

Commit c2fc7ee

Browse files
authored
Merge pull request #67664 from nate-chandler/opaque-values/20230801/3/cxx-interop-1
[OpaqueValues] Two tweaks to enable std::vector<uint32_t> iteration.
2 parents 7f1bf3b + 51ff578 commit c2fc7ee

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
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;

lib/SILGen/SILGenPoly.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ ManagedValue Transform::transform(ManagedValue v,
371371
// expect this.
372372
if (v.getType().isAddress()) {
373373
auto &inputTL = SGF.getTypeLowering(v.getType());
374-
if (!inputTL.isAddressOnly()) {
374+
if (!inputTL.isAddressOnly() || !SGF.silConv.useLoweredAddresses()) {
375375
v = emitManagedLoad(SGF, Loc, v, inputTL);
376376
}
377377
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include <vector>
2+
3+
using VectorOfU32 = std::vector<uint32_t>;

test/SILGen/opaque_values_cxx.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// 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
2+
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+
8+
import Cxx
9+
10+
// CHECK-LABEL: sil {{.*}}[ossa] @$sSo3stdO{{(3__1O)?}}0042vectorUInt32allocatorUInt32_mzFHjGjjqraEeaV3Cxx0B8SequenceSCA{{.*}}P13__beginUnsafe11RawIteratorQzyFTW : {{.*}} {
11+
// CHECK: bb0([[VECTOR_ADDR:%[^,]+]] :
12+
// CHECK: [[VECTOR:%[^,]+]] = load_borrow [[VECTOR_ADDR]]
13+
// CHECK: [[BEGIN_FN:%[^,]+]] = function_ref
14+
// CHECK: [[BEGIN:%[^,]+]] = apply [[BEGIN_FN]]([[VECTOR]])
15+
// CHECK: end_borrow [[VECTOR]]
16+
// CHECK: return [[BEGIN]]
17+
// 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'
24+
func test_cxx_vector_uint32t_iterate(_ n: Int, _ vectorOfU32: VectorOfU32) {
25+
for x in vectorOfU32 {}
26+
}

0 commit comments

Comments
 (0)