Skip to content

Commit da4951b

Browse files
committed
noncopyable diagnostics fix to correct error message wording
Turns out if you write `_ = consume s` you get different enough SIL than `_ = s` that it fools the ad-hoc test for whether we've mark-must-check'd a closure capture, since the former will have a begin_access. There doesn't appear to be a simple way to reuse the existing information or checking routine for this that was used by the checker itself to flag this.
1 parent 93e209c commit da4951b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyDiagnostics.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,9 @@ void DiagnosticEmitter::emitObjectDiagnosticsForPartialApplyUses(
547547
static bool isClosureCapture(MarkMustCheckInst *markedValue) {
548548
SILValue val = markedValue->getOperand();
549549

550+
// Sometimes we've mark-must-check'd a begin_access.
551+
val = stripAccessMarkers(val);
552+
550553
// look past any project-box
551554
if (auto *pbi = dyn_cast<ProjectBoxInst>(val))
552555
val = pbi->getOperand();

test/SILOptimizer/moveonly_addresschecker_diagnostics.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3862,6 +3862,22 @@ func blackHoleKlassTestCase2(_ k: consuming Klass) {
38623862
// expected-note @-1 {{consumed again here}}
38633863
}
38643864

3865+
// rdar://109908383
3866+
struct NonCopyableStruct: ~Copyable {}
3867+
var globFn: () -> () = {}
3868+
func forceEscaping(_ esc: @escaping () -> ()) {
3869+
globFn = esc
3870+
}
3871+
func closureDiagnosticsSimple() {
3872+
var s = NonCopyableStruct()
3873+
let f = {
3874+
_ = consume s // expected-error {{missing reinitialization of closure capture 's' after consume}} // expected-note {{consumed here}}
3875+
s = NonCopyableStruct()
3876+
}
3877+
forceEscaping(f)
3878+
f()
3879+
}
3880+
38653881
///////////////////////////////////////
38663882
// Copyable Type in a Move Only Type //
38673883
///////////////////////////////////////

0 commit comments

Comments
 (0)