Skip to content

Commit 03d55cd

Browse files
author
Joe Shajrawi
committed
Support for address based array initialization under opaque values mode
1 parent ab7128e commit 03d55cd

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,16 +2965,18 @@ namespace {
29652965
// it's not already there. (Note that this potentially includes
29662966
// conventions which pass indirectly without transferring
29672967
// ownership, like Itanium C++.)
2968-
if (SGF.silConv.isSILIndirect(param)) {
2969-
if (specialDest) {
2970-
emitIndirectInto(std::move(arg), origParamType,
2971-
loweredSubstParamType, *specialDest);
2972-
Args.push_back(ManagedValue::forInContext());
2973-
} else {
2974-
auto value = emitIndirect(std::move(arg), loweredSubstArgType,
2975-
origParamType, param);
2976-
Args.push_back(value);
2977-
}
2968+
if (specialDest) {
2969+
assert(param.isFormalIndirect() &&
2970+
"SpecialDest should imply indirect parameter");
2971+
// TODO: Change the way we initialize array storage in opaque mode
2972+
emitIndirectInto(std::move(arg), origParamType, loweredSubstParamType,
2973+
*specialDest);
2974+
Args.push_back(ManagedValue::forInContext());
2975+
return;
2976+
} else if (SGF.silConv.isSILIndirect(param)) {
2977+
auto value = emitIndirect(std::move(arg), loweredSubstArgType,
2978+
origParamType, param);
2979+
Args.push_back(value);
29782980
return;
29792981
}
29802982

test/SILGen/opaque_values_silgen.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@ protocol P {
88
var x : Int { get }
99
}
1010

11+
func hasVarArg(_ args: Any...) {}
12+
13+
// Test that we still use addresses when dealing with array initialization
14+
// ---
15+
// CHECK-LABEL: sil @_TF20opaque_values_silgen10callVarArgFT_T_ : $@convention(thin) () -> () {
16+
// CHECK: %[[APY:.*]] = apply %{{.*}}<Any>(%{{.*}}) : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer)
17+
// CHECK: %[[BRW:.*]] = begin_borrow %[[APY]]
18+
// CHECK: %[[TPL:.*]] = tuple_extract %[[BRW]] : $(Array<Any>, Builtin.RawPointer), 1
19+
// CHECK: end_borrow %[[BRW]] from %[[APY]] : $(Array<Any>, Builtin.RawPointer), $(Array<Any>, Builtin.RawPointer)
20+
// CHECK: destroy_value %[[APY]]
21+
// CHECK: %[[PTR:.*]] = pointer_to_address %[[TPL]] : $Builtin.RawPointer to [strict] $*Any
22+
// CHECK: init_existential_addr %[[PTR]] : $*Any, $Int
23+
// CHECK: return %{{.*}} : $()
24+
// CHECK: } // end sil function '_TF20opaque_values_silgen10callVarArgFT_T_'
25+
public func callVarArg() {
26+
hasVarArg(3)
27+
}
28+
1129
// Test emitSemanticStore.
1230
// ---
1331
// CHECK-LABEL: sil hidden @_TF20opaque_values_silgen11assigninouturFTRxx_T_ : $@convention(thin) <T> (@inout T, @in T) -> () {
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,2 @@
11
// RUN: %target-swift-frontend -enable-sil-opaque-values -emit-sorted-sil -Xllvm -sil-full-demangle -emit-silgen %s | %FileCheck %s
22
// REQUIRES: EnableSILOpaqueValues
3-
4-
func hasVarArg(_ args: Any...) {}
5-
6-
// ArgEmitter: fix SpecialDest args.
7-
public func callVarArg() {
8-
hasVarArg(3)
9-
}

0 commit comments

Comments
 (0)