Skip to content

Commit 4fc7de3

Browse files
committed
[SILGen] Consistently call makeUsed() in RValue::getAsSingleValue().
Fixes rdar://problem/50711880.
1 parent 7809d9c commit 4fc7de3

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/SILGen/RValue.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "Initialization.h"
2222
#include "SILGenFunction.h"
2323
#include "swift/AST/CanTypeVisitor.h"
24+
#include "swift/Basic/Defer.h"
2425
#include "swift/Basic/STLExtras.h"
2526
#include "swift/SIL/AbstractionPattern.h"
2627
#include "swift/SIL/SILArgument.h"
@@ -573,19 +574,19 @@ void RValue::assignInto(SILGenFunction &SGF, SILLocation loc,
573574

574575
ManagedValue RValue::getAsSingleValue(SILGenFunction &SGF, SILLocation loc) && {
575576
assert(!isUsed() && "r-value already used");
577+
SWIFT_DEFER {
578+
makeUsed();
579+
};
576580

577581
if (isInContext()) {
578-
makeUsed();
579582
return ManagedValue::forInContext();
580583
}
581584

582585
// Avoid killing and re-emitting the cleanup if the enclosed value isn't a
583586
// tuple.
584587
if (!isa<TupleType>(type)) {
585588
assert(values.size() == 1 && "exploded non-tuple?!");
586-
ManagedValue result = values[0];
587-
makeUsed();
588-
return result;
589+
return values[0];
589590
}
590591

591592
// *NOTE* Inside implodeTupleValues, we copy our values if they are not at +1.

test/SILGen/property_wrappers.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,18 @@ struct ObservingTest {
396396
}
397397
}
398398

399+
// Tuple initial values.
400+
struct WithTuples {
401+
// CHECK-LABEL: sil hidden [ossa] @$s17property_wrappers10WithTuplesVACycfC : $@convention(method) (@thin WithTuples.Type) -> WithTuples {
402+
// CHECK: function_ref @$s17property_wrappers10WithTuplesV10$fractions33_F728088E0028E14D18C6A10CF68512E8LLAA07WrapperC12InitialValueVySd_S2dtGvpfi : $@convention(thin) () -> (Double, Double, Double)
403+
// CHECK: function_ref @$s17property_wrappers23WrapperWithInitialValueV07initialF0ACyxGx_tcfC : $@convention(method) <τ_0_0> (@in τ_0_0, @thin WrapperWithInitialValue<τ_0_0>.Type) -> @out WrapperWithInitialValue<τ_0_0>
404+
@WrapperWithInitialValue var fractions = (1.3, 0.7, 0.3)
405+
406+
static func getDefault() -> WithTuples {
407+
return .init()
408+
}
409+
}
410+
399411
// CHECK-LABEL: sil_vtable ClassUsingWrapper {
400412
// CHECK: #ClassUsingWrapper.x!getter.1: (ClassUsingWrapper) -> () -> Int : @$s17property_wrappers17ClassUsingWrapperC1xSivg // ClassUsingWrapper.x.getter
401413
// CHECK: #ClassUsingWrapper.x!setter.1: (ClassUsingWrapper) -> (Int) -> () : @$s17property_wrappers17ClassUsingWrapperC1xSivs // ClassUsingWrapper.x.setter

0 commit comments

Comments
 (0)