Skip to content

Commit 88daaf8

Browse files
authored
Merge pull request swiftlang#79612 from slavapestov/fix-rdar145478336
SILGen: Fix RValue::elementsToBeAdded bookkeeping
2 parents 7e58d82 + 763f9c8 commit 88daaf8

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

lib/SILGen/RValue.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ using namespace Lowering;
3535
// Helper Routines
3636
//===----------------------------------------------------------------------===//
3737

38-
static unsigned getTupleSize(CanType t) {
39-
if (auto tt = dyn_cast<TupleType>(t))
40-
return tt->getNumElements();
41-
return 1;
42-
}
43-
4438
unsigned RValue::getRValueSize(AbstractionPattern pattern, CanType formalType) {
4539
if (pattern.isTuple()) {
4640
if (pattern.doesTupleContainPackExpansionType())
@@ -483,7 +477,7 @@ RValue::RValue(SILGenFunction &SGF, Expr *expr, ManagedValue v)
483477
}
484478

485479
RValue::RValue(CanType type)
486-
: type(type), elementsToBeAdded(getTupleSize(type)) {
480+
: type(type), elementsToBeAdded(getRValueSize(type)) {
487481
}
488482

489483
RValue::RValue(AbstractionPattern pattern, CanType type)
@@ -493,12 +487,14 @@ RValue::RValue(AbstractionPattern pattern, CanType type)
493487
void RValue::addElement(RValue &&element) & {
494488
assert(!element.isUsed() && "adding consumed value to r-value");
495489
assert(!element.isInSpecialState() && "adding special value to r-value");
496-
assert(!isComplete() && "rvalue already complete");
497-
assert(!isInSpecialState() && "cannot add elements to a special r-value");
498-
--elementsToBeAdded;
499-
values.insert(values.end(),
500-
element.values.begin(), element.values.end());
501-
element.makeUsed();
490+
assert(elementsToBeAdded >= element.values.size() && "rvalue too full");
491+
if (!element.values.empty()) {
492+
assert(!isInSpecialState() && "cannot add elements to a special r-value");
493+
elementsToBeAdded -= element.values.size();
494+
values.insert(values.end(),
495+
element.values.begin(), element.values.end());
496+
element.makeUsed();
497+
}
502498

503499
assert(!isComplete() || values.size() == getRValueSize(type));
504500
// Call into the verifier helper directly without an SGF since we know that

test/SILGen/variadic-generic-tuples.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,3 +423,13 @@ func testTupleExpansionInEnumConstructor<each T>(
423423
// CHECK-NEXT: [[PAYLOAD_ADDR:%.*]] = init_enum_data_addr [[RESULT_TEMP]] : $*Result<(repeat each T), any Error>, #Result.success
424424
// CHECK-NEXT: copy_addr [[VAR]] to [init] [[PAYLOAD_ADDR]] : $*(repeat each T)
425425
// CHECK-NEXT: inject_enum_addr [[RESULT_TEMP]] : $*Result<(repeat each T), any Error>, #Result.success
426+
427+
// rdar://145478336
428+
429+
func convertVoidPayloads() {
430+
convertPayloads(as: Void.self)
431+
}
432+
433+
func convertPayloads<each Value>(as valueTypes: repeat (each Value).Type) -> (repeat each Value) {
434+
fatalError()
435+
}

0 commit comments

Comments
 (0)