File: moveonly_unsafeAddress.sil

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (57 lines) | stat: -rw-r--r-- 2,003 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// RUN: %target-sil-opt -sil-move-only-address-checker -enable-sil-verify-all -verify %s | %FileCheck %s

// Verify move-only diagnostics on unsafe addressors.
//
// Note: .sil tests cannot easily recover variable names, so we see 'unknown' variables.

sil_stage raw

import Builtin
import Swift
import SwiftShims

class C {
  deinit
  init()
}

struct NC : ~Copyable {
  @_hasStorage @_hasInitialValue var c: C { get set }
  deinit
  init()
  init(c: C = C())
}

struct SNC : ~Copyable {
  var data: NC { get }
  var mutableData: NC { get set }
  init()
}

sil @unsafeAddressor : $@convention(method) (@guaranteed SNC) -> UnsafePointer<NC>

sil @consumeNC : $@convention(thin) (@owned NC) -> ()

// CHECK-LABEL: sil hidden [ossa] @test_read_borrow : $@convention(thin) (@inout SNC) -> () {
sil hidden [ossa] @test_read_borrow : $@convention(thin) (@inout SNC) -> () {
bb0(%0 : $*SNC):
  debug_value %0 : $*SNC, var, name "snc", argno 1, expr op_deref
  %2 = mark_unresolved_non_copyable_value [consumable_and_assignable] %0 : $*SNC
  %3 = begin_access [read] [static] %2 : $*SNC
  %4 = load_borrow [unchecked] %3 : $*SNC
  %5 = function_ref @unsafeAddressor : $@convention(method) (@guaranteed SNC) -> UnsafePointer<NC>
  %6 = apply %5(%4) : $@convention(method) (@guaranteed SNC) -> UnsafePointer<NC>
  %7 = struct_extract %6 : $UnsafePointer<NC>, #UnsafePointer._rawValue
  %8 = pointer_to_address %7 : $Builtin.RawPointer to [strict] $*NC
  %9 = mark_dependence [unresolved] %8 : $*NC on %3 : $*SNC
  %10 = begin_access [read] [unsafe] %9 : $*NC
  %11 = mark_unresolved_non_copyable_value [no_consume_or_assign] %10 : $*NC  // expected-error {{'unknown' is borrowed and cannot be consumed}}
  %12 = load [copy] %11 : $*NC
  end_access %10 : $*NC
  end_borrow %4 : $SNC
  end_access %3 : $*SNC
  %16 = function_ref @consumeNC : $@convention(thin) (@owned NC) -> ()
  %17 = apply %16(%12) : $@convention(thin) (@owned NC) -> () // expected-note {{consumed here}}
  %18 = tuple ()
  return %18 : $()
}