Skip to content

Commit f68e93b

Browse files
authored
Merge pull request #78569 from atrick/6.1-fix-silgen-noncopyable
[6.1] Fix SILGenFunction::emitValueConstructor for library evolution.
2 parents 88c0a5d + adaed21 commit f68e93b

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

lib/SILGen/SILGenConstructor.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -772,15 +772,14 @@ void SILGenFunction::emitValueConstructor(ConstructorDecl *ctor) {
772772

773773
auto cleanupLoc = CleanupLocation(ctor);
774774

775+
if (selfLV.getType().isMoveOnly()) {
776+
selfLV = B.createMarkUnresolvedNonCopyableValueInst(
777+
cleanupLoc, selfLV,
778+
MarkUnresolvedNonCopyableValueInst::CheckKind::
779+
AssignableButNotConsumable);
780+
}
775781
if (!F.getConventions().hasIndirectSILResults()) {
776782
// Otherwise, load and return the final 'self' value.
777-
if (selfLV.getType().isMoveOnly()) {
778-
selfLV = B.createMarkUnresolvedNonCopyableValueInst(
779-
cleanupLoc, selfLV,
780-
MarkUnresolvedNonCopyableValueInst::CheckKind::
781-
AssignableButNotConsumable);
782-
}
783-
784783
selfValue = lowering.emitLoad(B, cleanupLoc, selfLV.getValue(),
785784
LoadOwnershipQualifier::Copy);
786785

test/SILGen/moveonly_library_evolution.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,16 @@ func useUsableFromInlineTestKlass() {
106106
let k = UsableFromInlineTestKlass()
107107
k.e = E()
108108
}
109+
110+
// rdar://142690658 (In ~Copyable public struct, an init with COW type param causes compiler error)
111+
//
112+
// CHECK-LABEL: sil hidden [ossa] @$s26moveonly_library_evolution19NonCopyableWithInitV1sACSS_tcfC :
113+
// CHECK-SAME: $@convention(method) (@owned String, @thin NonCopyableWithInit.Type) -> @out NonCopyableWithInit {
114+
// CHECK: bb0(%0 : $*NonCopyableWithInit, %1 : @owned $String, %2 : $@thin NonCopyableWithInit.Type):
115+
// CHECK: [[BOX:%.*]] = project_box %{{.*}} : ${ var NonCopyableWithInit }, 0
116+
// CHECK: store %{{.*}} to [init] [[BOX]]
117+
// CHECK: [[MD:%.*]] = mark_unresolved_non_copyable_value [assignable_but_not_consumable] [[BOX]]
118+
// CHECK: copy_addr [[MD]] to [init] %0
119+
public struct NonCopyableWithInit: ~Copyable {
120+
init(s: String) {}
121+
}

0 commit comments

Comments
 (0)