Skip to content

Commit 58a4a21

Browse files
committed
ManualOwnership: copy_addr [take] doesn't copy
1 parent 16ce6b8 commit 58a4a21

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

lib/SILOptimizer/Mandatory/PerformanceDiagnostics.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,11 @@ bool PerformanceDiagnostics::visitInst(SILInstruction *inst,
388388
case SILInstructionKind::ExplicitCopyAddrInst:
389389
case SILInstructionKind::ExplicitCopyValueInst:
390390
break; // Explicitly acknowledged copies are OK.
391+
case SILInstructionKind::CopyAddrInst: {
392+
if (!cast<CopyAddrInst>(inst)->isTakeOfSrc())
393+
shouldDiagnose = true; // If it isn't a [take], it's a copy.
394+
break;
395+
}
391396
case SILInstructionKind::LoadInst: {
392397
// FIXME: we don't have an `explicit_load` and transparent functions can
393398
// end up bringing in a `load [copy]`. A better approach is needed to

test/SIL/manual_ownership.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func return_borrowed_fixed(_ t: borrowing Triangle) -> Triangle {
7272
return copy t
7373
}
7474

75-
// FIXME: copy propagation isn't able to simplify this. No copy should be required.
75+
// FIXME: copy propagation isn't able to simplify this. No copy should be required. (rdar://161359163)
7676
@_manualOwnership
7777
func return_consumingParam(_ t: consuming Triangle) -> Triangle { // expected-error {{ownership of 't' is demanded and cannot not be consumed}}
7878
return t
@@ -95,20 +95,20 @@ func reassign_with_lets() -> Triangle {
9595
func renamed_return(_ cond: Bool, _ a: Triangle) -> Triangle {
9696
let b = a
9797
let c = b
98-
// FIXME: we say 'c' instead of 'b', because of the propagation.
98+
// FIXME: we say 'c' instead of 'b', because of the propagation. (rdar://161360537)
9999
if cond { return b } // expected-error {{ownership of 'c' is demanded}}
100100
return c // expected-error {{ownership of 'c' is demanded}}
101101
}
102102

103103
@_manualOwnership
104104
func renamed_return_fix1(_ cond: Bool, _ a: Triangle) -> Triangle {
105105
let b = copy a
106-
let c = copy b // FIXME: not needed! Is explicit_copy_value is blocking propagation?
106+
let c = copy b // FIXME: not needed! Is explicit_copy_value is blocking propagation? (rdar://161359163)
107107
if cond { return b }
108108
return c
109109
}
110110

111-
// FIXME: this crashes CopyPropagation!
111+
// FIXME: this crashes CopyPropagation! (rdar://161360764)
112112
//@_manualOwnership
113113
//func renamed_return_fix2(_ cond: Bool, _ a: Triangle) -> Triangle {
114114
// let b = a
@@ -169,8 +169,8 @@ func check_vars_fixed(_ t: Triangle, _ b: Bool) -> Triangle {
169169
return copy x
170170
}
171171

172-
// FIXME: var's still have some issues.
173-
// (1) MandatoryRedundantLoadElimination introduces a 'copy_value' in place of a 'load [copy]'
172+
// FIXME: var's still have some issues
173+
// (1) MandatoryRedundantLoadElimination introduces a 'copy_value' in place of a 'load [copy]' (rdar://161359163)
174174

175175
// @_manualOwnership
176176
// func reassignments_0() -> Triangle {
@@ -234,7 +234,7 @@ public func basic_loop_nontrivial_values_fixed(_ t: Triangle, _ xs: [Triangle])
234234

235235
@_manualOwnership
236236
public func basic_loop_nontrivial_values_reduced_copies(_ t: Triangle, _ xs: [Triangle]) {
237-
// FIXME: confusing variable names are chosen
237+
// FIXME: confusing variable names are chosen (rdar://161360537)
238238
let nt = t.nontrivial // expected-error {{accessing 'nt' produces a copy of it}}
239239
var p: Pair = nt.a
240240
for x in copy xs {
@@ -379,7 +379,7 @@ func reassign_with_lets<T>(_ t: T) -> T {
379379
return copy z
380380
}
381381

382-
// FIXME: there's copy propagation has no effect on address-only types.
382+
// FIXME: copy propagation has no effect on address-only types, so this is quite verbose.
383383
@_manualOwnership
384384
func reassign_with_lets_fixed<T>(_ t: T) -> T {
385385
let x = copy t
@@ -431,8 +431,7 @@ extension FixedWidthInteger {
431431

432432
@_manualOwnership
433433
mutating func rotatedLeft(_ distance: Int) {
434-
// FIXME: this doesn't appear to be solvable
435-
self = (copy self).leftRotate(distance) // expected-error {{explicit 'copy' required here}}
434+
self = (copy self).leftRotate(distance)
436435
}
437436
}
438437

0 commit comments

Comments
 (0)