File: noimplicitcopy.sil

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (48 lines) | stat: -rw-r--r-- 2,073 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
// RUN: %target-sil-opt -enable-experimental-move-only -enable-sil-verify-all -sil-move-only-object-checker %s

//////////////////
// Declarations //
//////////////////

class Klass {}

struct CopyableStruct {
  var k = Klass()
}

sil @classUseMoveOnlyWithoutEscaping : $@convention(thin) (@guaranteed Klass) -> ()

///////////
// Tests //
///////////

// This test makes sure that we eliminate %2 after checking and that
// sil-verify-all does not trigger.
sil [ossa] @test_remove_early_copyvalue : $@convention(thin) (@guaranteed Klass) -> () {
bb0(%0 : @noImplicitCopy @guaranteed $Klass):
  %1 = copyable_to_moveonlywrapper [guaranteed] %0 : $Klass
  %2 = copy_value %1 : $@moveOnly Klass
  %3 = mark_unresolved_non_copyable_value [no_consume_or_assign] %2 : $@moveOnly Klass
  debug_value %3 : $@moveOnly Klass, let, name "x2", argno 1
  %5 = begin_borrow %3 : $@moveOnly Klass
  %6 = function_ref @classUseMoveOnlyWithoutEscaping : $@convention(thin) (@guaranteed Klass) -> ()
  %7 = moveonlywrapper_to_copyable [guaranteed] %5 : $@moveOnly Klass
  %8 = apply %6(%7) : $@convention(thin) (@guaranteed Klass) -> ()
  end_borrow %5 : $@moveOnly Klass
  destroy_value %3 : $@moveOnly Klass
  %11 = tuple ()
  return %11 : $()
}

sil [ossa] @testSimpleBorrowParameter : $@convention(thin) (@in_guaranteed CopyableStruct) -> () {
bb0(%0 : @noImplicitCopy $*CopyableStruct):
  %1 = load_borrow %0 : $*CopyableStruct                       // users: %7, %2
  %2 = copyable_to_moveonlywrapper [guaranteed] %1 : $CopyableStruct // user: %3
  %3 = copy_value %2 : $@moveOnly CopyableStruct               // user: %4
  %4 = mark_unresolved_non_copyable_value [no_consume_or_assign] %3 : $@moveOnly CopyableStruct // users: %6, %5
  debug_value %4 : $@moveOnly CopyableStruct, let, name "x", argno 1 // id: %5
  destroy_value %4 : $@moveOnly CopyableStruct                 // id: %6
  end_borrow %1 : $CopyableStruct                              // id: %7
  %8 = tuple ()                                   // user: %9
  return %8 : $()                                 // id: %9
}