Skip to content

Commit cfdfff3

Browse files
committed
[addr-move-function] Add some simple defer tests for lets. We always error on these.
To improve the diagnostics though I think I am going to have to add a closure operand analysis to copyable values like I did for copyable addresses...
1 parent e6a9ac3 commit cfdfff3

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

test/SILOptimizer/move_function_kills_copyable_addressonly_lets.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,16 @@ public func partialApplyTest<T>(_ x: __owned T) { // expected-error {{'x' used a
389389
}
390390
f()
391391
}
392+
393+
/////////////////
394+
// Defer Tests //
395+
/////////////////
396+
397+
// TODO: Emit an error in the defer.
398+
public func deferTest<T>(_ x: __owned T) { // expected-error {{'x' used after being moved}}
399+
let _ = _move(x) // expected-note {{move here}}
400+
defer { // expected-note {{use here}}
401+
nonConsumingUse(x)
402+
}
403+
print("do Something")
404+
}

test/SILOptimizer/move_function_kills_copyable_values.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,19 @@ public func partialApplyTest(_ x: __owned Klass) { // expected-error {{'x' used
363363
}
364364
f()
365365
}
366+
367+
/////////////////
368+
// Defer Tests //
369+
/////////////////
370+
371+
// TODO: Improve this error msg.
372+
//
373+
// NOTE: This will require adding knowledge about captured defer arguments for
374+
// values. This at least prevents the error from happening.
375+
public func deferTest(_ x: __owned Klass) { // expected-error {{'x' used after being moved}}
376+
let _ = _move(x) // expected-note {{move here}}
377+
defer { // expected-note {{use here}}
378+
nonConsumingUse(x)
379+
}
380+
print("do Something")
381+
}

0 commit comments

Comments
 (0)