Skip to content

Commit bb4d0c8

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

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
@@ -400,6 +400,18 @@ struct ObservingTest {
400400
}
401401
}
402402

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

0 commit comments

Comments
 (0)