Skip to content

[move-only] Fix emission of addressonly noncopyable setter new values. #66084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions lib/SILGen/SILGenProlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,12 @@ class ArgumentInitHelper {
substFormalParams.push_back(
pd->toFunctionParam(pd->getType()).getCanonical(nullptr));
};
for (auto paramDecl : *paramList) { addParamDecl(paramDecl); }
if (selfParam) { addParamDecl(selfParam); }
for (auto paramDecl : *paramList) {
addParamDecl(paramDecl);
}
if (selfParam) {
addParamDecl(selfParam);
}

// Initialize the formal parameter generator. Note that this can
// immediately claim lowered parameters.
Expand Down Expand Up @@ -795,8 +799,32 @@ class ArgumentInitHelper {
loc, value, MarkMustCheckInst::CheckKind::NoConsumeOrAssign);
}
} else {
assert(isa<MarkMustCheckInst>(value) &&
"Should have inserted mark must check inst in EmitBBArgs");
if (auto *fArg = dyn_cast<SILFunctionArgument>(value)) {
switch (fArg->getArgumentConvention()) {
case SILArgumentConvention::Direct_Guaranteed:
case SILArgumentConvention::Direct_Owned:
case SILArgumentConvention::Direct_Unowned:
case SILArgumentConvention::Indirect_Inout:
case SILArgumentConvention::Indirect_Out:
case SILArgumentConvention::Indirect_InoutAliasable:
case SILArgumentConvention::Pack_Inout:
case SILArgumentConvention::Pack_Guaranteed:
case SILArgumentConvention::Pack_Owned:
case SILArgumentConvention::Pack_Out:
llvm_unreachable("Should have been handled elsewhere");
case SILArgumentConvention::Indirect_In:
value = SGF.B.createMarkMustCheckInst(
loc, value,
MarkMustCheckInst::CheckKind::ConsumableAndAssignable);
break;
case SILArgumentConvention::Indirect_In_Guaranteed:
value = SGF.B.createMarkMustCheckInst(
loc, value, MarkMustCheckInst::CheckKind::NoConsumeOrAssign);
}
} else {
assert(isa<MarkMustCheckInst>(value) &&
"Should have inserted mark must check inst in EmitBBArgs");
}
}
break;
case ValueOwnership::InOut:
Expand Down
17 changes: 17 additions & 0 deletions test/SILGen/moveonly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -983,3 +983,20 @@ func testConditionallyInitializedLet() {
borrowVal(x)
consumeVal(x)
}

/////////////////////////////
// MARK: AddressOnlySetter //
/////////////////////////////

struct AddressOnlySetterTester : ~Copyable {
var a: AddressOnlyProtocol {
get { fatalError() }

// CHECK-LABEL: sil hidden [ossa] @$s8moveonly23AddressOnlySetterTesterV1aAA0bC8ProtocolVvs : $@convention(method) (@in AddressOnlyProtocol, @inout AddressOnlySetterTester) -> () {
// CHECK: bb0([[IN_ARG:%.*]] : $*AddressOnlyProtocol, [[SELF_INOUT_ARG:%.*]] : $*AddressOnlySetterTester):
// CHECK: mark_must_check [consumable_and_assignable] [[IN_ARG]]
// CHECK: mark_must_check [consumable_and_assignable] [[SELF_INOUT_ARG]]
// CHECK: } // end sil function '$s8moveonly23AddressOnlySetterTesterV1aAA0bC8ProtocolVvs'
set { fatalError() }
}
}