Skip to content

Commit 780d88c

Browse files
gottesmmkavon
authored andcommitted
[move-only] Fix emission of addressonly noncopyable setter new values.
NOTE: This does not affect normal parameters since normal parameters that are noncopyable never have default access semantics since the user is forced to specify either borrow or consume. This is incontrast to implicit parameters like the newValue of a setter. rdar://109726282 (cherry picked from commit 82c645d)
1 parent 5372ce8 commit 780d88c

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

lib/SILGen/SILGenProlog.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,12 @@ class ArgumentInitHelper {
552552
substFormalParams.push_back(
553553
pd->toFunctionParam(pd->getType()).getCanonical(nullptr));
554554
};
555-
for (auto paramDecl : *paramList) { addParamDecl(paramDecl); }
556-
if (selfParam) { addParamDecl(selfParam); }
555+
for (auto paramDecl : *paramList) {
556+
addParamDecl(paramDecl);
557+
}
558+
if (selfParam) {
559+
addParamDecl(selfParam);
560+
}
557561

558562
// Initialize the formal parameter generator. Note that this can
559563
// immediately claim lowered parameters.
@@ -795,8 +799,32 @@ class ArgumentInitHelper {
795799
loc, value, MarkMustCheckInst::CheckKind::NoConsumeOrAssign);
796800
}
797801
} else {
798-
assert(isa<MarkMustCheckInst>(value) &&
799-
"Should have inserted mark must check inst in EmitBBArgs");
802+
if (auto *fArg = dyn_cast<SILFunctionArgument>(value)) {
803+
switch (fArg->getArgumentConvention()) {
804+
case SILArgumentConvention::Direct_Guaranteed:
805+
case SILArgumentConvention::Direct_Owned:
806+
case SILArgumentConvention::Direct_Unowned:
807+
case SILArgumentConvention::Indirect_Inout:
808+
case SILArgumentConvention::Indirect_Out:
809+
case SILArgumentConvention::Indirect_InoutAliasable:
810+
case SILArgumentConvention::Pack_Inout:
811+
case SILArgumentConvention::Pack_Guaranteed:
812+
case SILArgumentConvention::Pack_Owned:
813+
case SILArgumentConvention::Pack_Out:
814+
llvm_unreachable("Should have been handled elsewhere");
815+
case SILArgumentConvention::Indirect_In:
816+
value = SGF.B.createMarkMustCheckInst(
817+
loc, value,
818+
MarkMustCheckInst::CheckKind::ConsumableAndAssignable);
819+
break;
820+
case SILArgumentConvention::Indirect_In_Guaranteed:
821+
value = SGF.B.createMarkMustCheckInst(
822+
loc, value, MarkMustCheckInst::CheckKind::NoConsumeOrAssign);
823+
}
824+
} else {
825+
assert(isa<MarkMustCheckInst>(value) &&
826+
"Should have inserted mark must check inst in EmitBBArgs");
827+
}
800828
}
801829
break;
802830
case ValueOwnership::InOut:

test/SILGen/moveonly.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,3 +983,20 @@ func testConditionallyInitializedLet() {
983983
borrowVal(x)
984984
consumeVal(x)
985985
}
986+
987+
/////////////////////////////
988+
// MARK: AddressOnlySetter //
989+
/////////////////////////////
990+
991+
struct AddressOnlySetterTester : ~Copyable {
992+
var a: AddressOnlyProtocol {
993+
get { fatalError() }
994+
995+
// CHECK-LABEL: sil hidden [ossa] @$s8moveonly23AddressOnlySetterTesterV1aAA0bC8ProtocolVvs : $@convention(method) (@in AddressOnlyProtocol, @inout AddressOnlySetterTester) -> () {
996+
// CHECK: bb0([[IN_ARG:%.*]] : $*AddressOnlyProtocol, [[SELF_INOUT_ARG:%.*]] : $*AddressOnlySetterTester):
997+
// CHECK: mark_must_check [consumable_and_assignable] [[IN_ARG]]
998+
// CHECK: mark_must_check [consumable_and_assignable] [[SELF_INOUT_ARG]]
999+
// CHECK: } // end sil function '$s8moveonly23AddressOnlySetterTesterV1aAA0bC8ProtocolVvs'
1000+
set { fatalError() }
1001+
}
1002+
}

0 commit comments

Comments
 (0)