Files
swift-mirror/test/SILOptimizer/moveonly_consume_during_borrow_1.swift
Joe Groff 27a8852290 MoveOnlyAddressChecker: More robust checking for consume-during-borrow.
- While an opaque borrow access occurs to part of a value, the entire scope of
  the access needs to be treated as a liveness range, so add the `EndAccess`es
  to the liveness range.
- The SIL verifier may crash the compiler on SILGen-generated code when the
  developer's source contains consume-during-borrow code patterns. Allow
  `load_borrow` instructions to be marked `[unchecked]`, which suppresses
  verifier checks until the move checker runs and gets a chance to properly
  diagnose these errors.

Fixes rdar://124360175.
2024-06-25 14:10:02 -07:00

16 lines
359 B
Swift

// RUN: %target-swift-frontend -emit-sil -verify %s
func foo(x: consuming Foo) { // expected-error{{'x' used after consume}}
x.bar.foo(x) // expected-error{{overlapping accesses to 'x'}} expected-note 3 {{}}
}
struct Foo: ~Copyable {
var bar: Bar {
_read { fatalError() }
}
}
struct Bar: ~Copyable {
func foo(_: consuming Foo) {}
}