Skip to content

Commit a158234

Browse files
committed
SILGen: Fix emission of class allocating init with pack expansion parameters
Fixes rdar://110099644.
1 parent 630a7fc commit a158234

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

lib/SILGen/SILGenProlog.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -910,19 +910,25 @@ static void makeArgument(Type ty, ParamDecl *decl,
910910
SmallVectorImpl<SILValue> &args, SILGenFunction &SGF) {
911911
assert(ty && "no type?!");
912912

913+
if (ty->is<PackExpansionType>()) {
914+
ty = PackType::get(SGF.getASTContext(), {ty});
915+
}
916+
913917
// Destructure tuple value arguments.
914-
if (TupleType *tupleTy = decl->isInOut() ? nullptr : ty->getAs<TupleType>()) {
915-
for (auto fieldType : tupleTy->getElementTypes())
916-
makeArgument(fieldType, decl, args, SGF);
917-
} else {
918-
auto loweredTy = SGF.getLoweredTypeForFunctionArgument(ty);
919-
if (decl->isInOut())
920-
loweredTy = SILType::getPrimitiveAddressType(loweredTy.getASTType());
921-
auto arg = SGF.F.begin()->createFunctionArgument(loweredTy, decl);
922-
args.push_back(arg);
918+
if (!decl->isInOut()) {
919+
if (TupleType *tupleTy = ty->getAs<TupleType>()) {
920+
for (auto fieldType : tupleTy->getElementTypes())
921+
makeArgument(fieldType, decl, args, SGF);
922+
return;
923+
}
923924
}
924-
}
925925

926+
auto loweredTy = SGF.getLoweredTypeForFunctionArgument(ty);
927+
if (decl->isInOut())
928+
loweredTy = SILType::getPrimitiveAddressType(loweredTy.getASTType());
929+
auto arg = SGF.F.begin()->createFunctionArgument(loweredTy, decl);
930+
args.push_back(arg);
931+
}
926932

927933
void SILGenFunction::bindParameterForForwarding(ParamDecl *param,
928934
SmallVectorImpl<SILValue> &parameters) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-emit-silgen %s -disable-availability-checking | %FileCheck %s
2+
3+
class C<each T> {
4+
var values: (repeat each T)
5+
6+
// CHECK-LABEL: sil hidden [exact_self_class] [ossa] @$s32variadic_generic_allocating_init1CC9fromTupleACyxxQp_QPGxxQp_t_tcfC : $@convention(method) <each T> (@pack_owned Pack{repeat each T}, @thick C<repeat each T>.Type) -> @owned C<repeat each T> {
7+
// CHECK: bb0(%0 : $*Pack{repeat each T}, %1 : $@thick C<repeat each T>.Type):
8+
init(fromTuple: (repeat each T)) {
9+
self.values = fromTuple
10+
}
11+
12+
// CHECK-LABEL: sil hidden [exact_self_class] [ossa] @$s32variadic_generic_allocating_init1CC8fromPackACyxxQp_QPGxxQp_tcfC : $@convention(method) <each T> (@pack_owned Pack{repeat each T}, @thick C<repeat each T>.Type) -> @owned C<repeat each T> {
13+
// CHECK: bb0(%0 : $*Pack{repeat each T}, %1 : $@thick C<repeat each T>.Type):
14+
init(fromPack: repeat each T) {
15+
self.values = (repeat each fromPack)
16+
}
17+
}

0 commit comments

Comments
 (0)