Files
swift-mirror/test/SILOptimizer/moveonly_unchecked_exclusivity.swift
Joe Groff 9b2fa08384 SILGen: Use [unsafe] access markers for move-only storage when exclusivity enforcement is disabled.
The move-only checker relies on access markers to understand access scopes, so eliding them
entirely leads to miscompiles. We can emit `begin_access [unsafe]` to semantically delimit
exclusivity scopes while still doing no runtime checking. Fixes rdar://147546262.
2025-04-08 12:02:24 -07:00

26 lines
886 B
Swift

// RUN: %target-swift-frontend -enforce-exclusivity=unchecked -emit-sil %s | %FileCheck %s
struct Foo: ~Copyable {
var x: Any
}
final class Bar {
init() { fatalError() }
// Ensure that noncopyable bindings still get [unsafe] exclusivity markers
// and get checked properly by the move-only checker.
// Bar.foo.setter:
// CHECK-LABEL: sil {{.*}} @$s{{.*}}3BarC3foo{{.*}}vs
// CHECK: [[FIELD:%.*]] = ref_element_addr {{.*}}, #Bar.foo
// CHECK: [[FIELD_ACCESS:%.*]] = begin_access [modify] [unsafe] [[FIELD]]
// CHECK-NEXT: destroy_addr [[FIELD_ACCESS]]
// CHECK-NEXT: copy_addr [take] {{.*}} to [init] [[FIELD_ACCESS]]
// CHECK-NEXT: end_access [[FIELD_ACCESS]]
// CHECK-NOT: [[FIELD]]
// CHECK-NOT: [[FIELD_ACCESS]]
// CHECK: } // end sil {{.*}} '$s{{.*}}3BarC3foo{{.*}}vs'
var foo: Foo
}