Skip to content

Commit cc3038d

Browse files
committed
[OpaqueValues] Transforms emit addr-only loads.
In opaque values mode, when transforming, load address even when their type is address-only.
1 parent 53da675 commit cc3038d

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

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

0 commit comments

Comments
 (0)