|
| 1 | +// RUN: %target-sil-opt -sil-move-only-address-checker -enable-sil-verify-all -verify %s | %FileCheck %s |
| 2 | + |
| 3 | +// Verify move-only diagnostics on unsafe addressors. |
| 4 | +// |
| 5 | +// Note: .sil tests cannot easily recover variable names, so we see 'unknown' variables. |
| 6 | + |
| 7 | +sil_stage raw |
| 8 | + |
| 9 | +import Builtin |
| 10 | +import Swift |
| 11 | +import SwiftShims |
| 12 | + |
| 13 | +class C { |
| 14 | + deinit |
| 15 | + init() |
| 16 | +} |
| 17 | + |
| 18 | +struct NC : ~Copyable { |
| 19 | + @_hasStorage @_hasInitialValue var c: C { get set } |
| 20 | + deinit |
| 21 | + init() |
| 22 | + init(c: C = C()) |
| 23 | +} |
| 24 | + |
| 25 | +struct SNC : ~Copyable { |
| 26 | + var data: NC { get } |
| 27 | + var mutableData: NC { get set } |
| 28 | + init() |
| 29 | +} |
| 30 | + |
| 31 | +sil @unsafeAddressor : $@convention(method) (@guaranteed SNC) -> UnsafePointer<NC> |
| 32 | + |
| 33 | +sil @consumeNC : $@convention(thin) (@owned NC) -> () |
| 34 | + |
| 35 | +// CHECK-LABEL: sil hidden [ossa] @test_read_borrow : $@convention(thin) (@inout SNC) -> () { |
| 36 | +sil hidden [ossa] @test_read_borrow : $@convention(thin) (@inout SNC) -> () { |
| 37 | +bb0(%0 : $*SNC): |
| 38 | + debug_value %0 : $*SNC, var, name "snc", argno 1, expr op_deref |
| 39 | + %2 = mark_unresolved_non_copyable_value [consumable_and_assignable] %0 : $*SNC |
| 40 | + %3 = begin_access [read] [static] %2 : $*SNC |
| 41 | + %4 = load_borrow [unchecked] %3 : $*SNC |
| 42 | + %5 = function_ref @unsafeAddressor : $@convention(method) (@guaranteed SNC) -> UnsafePointer<NC> |
| 43 | + %6 = apply %5(%4) : $@convention(method) (@guaranteed SNC) -> UnsafePointer<NC> |
| 44 | + %7 = struct_extract %6 : $UnsafePointer<NC>, #UnsafePointer._rawValue |
| 45 | + %8 = pointer_to_address %7 : $Builtin.RawPointer to [strict] $*NC |
| 46 | + %9 = mark_dependence [unresolved] %8 : $*NC on %3 : $*SNC |
| 47 | + %10 = begin_access [read] [unsafe] %9 : $*NC |
| 48 | + %11 = mark_unresolved_non_copyable_value [no_consume_or_assign] %10 : $*NC // expected-error {{'unknown' is borrowed and cannot be consumed}} |
| 49 | + %12 = load [copy] %11 : $*NC |
| 50 | + end_access %10 : $*NC |
| 51 | + end_borrow %4 : $SNC |
| 52 | + end_access %3 : $*SNC |
| 53 | + %16 = function_ref @consumeNC : $@convention(thin) (@owned NC) -> () |
| 54 | + %17 = apply %16(%12) : $@convention(thin) (@owned NC) -> () // expected-note {{consumed here}} |
| 55 | + %18 = tuple () |
| 56 | + return %18 : $() |
| 57 | +} |
0 commit comments