File: basic.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 (108 lines) | stat: -rw-r--r-- 4,441 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// RUN: %target-sil-opt -sil-opt-remark-ignore-always-infer -assemblyvisionremarkgen-declless-debugvalue-use-sildebugvar-info -assembly-vision-remark-generator -sil-remarks-missed=sil-assembly-vision-remark-gen -verify %s -o /dev/null

sil_stage canonical

import Builtin

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

class Klass {}

enum TrivialState {
case first
case second
case third
}

struct StructWithOwner {
  var owner: Klass
  var state: TrivialState
}

struct KlassPair {
  var lhs: Klass
  var rhs: Klass
}

struct StructWithOwnerAndState {
  var structWithOwner: StructWithOwner
  var state: TrivialState
}

struct _SwiftEmptyArrayStorage {
  var nonTrivialField: Klass = Klass()
}

class EmptyArrayStorage {
  var state: TrivialState = .first
}

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

sil @simple : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
bb0(%0 : $Builtin.NativeObject):
  debug_value %0 : $Builtin.NativeObject, let, name "arg"
  strong_retain %0 : $Builtin.NativeObject  // expected-remark {{retain of type 'Builtin.NativeObject'}}
                                            // expected-note @-2 {{of 'arg'}}
  retain_value %0 : $Builtin.NativeObject   // expected-remark {{retain of type 'Builtin.NativeObject'}}
                                            // expected-note @-4 {{of 'arg'}}
  strong_release %0 : $Builtin.NativeObject // expected-remark {{release of type 'Builtin.NativeObject'}}
                                            // expected-note @-6 {{of 'arg'}}
  release_value %0 : $Builtin.NativeObject  // expected-remark {{release of type 'Builtin.NativeObject'}}
                                            // expected-note @-8 {{of 'arg'}}
  %9999 = tuple()
  return %9999 : $()
}

sil @extract_out_singleobj_struct_subfield_1 : $@convention(thin) (@guaranteed StructWithOwner) -> Klass {
bb0(%0 : $StructWithOwner):
  debug_value %0 : $StructWithOwner, let, name "x"
  %1 = struct_extract %0 : $StructWithOwner, #StructWithOwner.owner
  strong_retain %1 : $Klass // expected-remark {{retain of type 'Klass'}}
                                           // expected-note @-3 {{of 'x.owner'}}
  return %1 : $Klass
}

// This case should never actually happen like this, but we should handle it in
// a sound way by printing both notes for y and x and also make sure that we do
// not infer .owner on y since y is on owner itself.
sil @extract_out_singleobj_struct_subfield_multiple_debugvalue : $@convention(thin) (@guaranteed StructWithOwner) -> Klass {
bb0(%0 : $StructWithOwner):
  debug_value %0 : $StructWithOwner, let, name "x"
  %1 = struct_extract %0 : $StructWithOwner, #StructWithOwner.owner
  debug_value %1 : $Klass, let, name "y"
  strong_retain %1 : $Klass // expected-remark {{retain of type 'Klass'}}
                            // expected-note @-4 {{of 'x.owner'}}
                            // expected-note @-3 {{of 'y'}}
  return %1 : $Klass
}

// In this case, we emit the remark for x since its operand %2 is rc-identical
// to %0 the value we found while traversing our access path.
sil @rcidentity_based_use : $@convention(thin) (@guaranteed StructWithOwner, TrivialState) -> @owned Klass {
bb0(%0 : $StructWithOwner, %1 : $TrivialState):
  %2 = struct $StructWithOwnerAndState(%0 : $StructWithOwner, %1 : $TrivialState)
  debug_value %2 : $StructWithOwnerAndState, let, name "x"
  %3 = struct_extract %0 : $StructWithOwner, #StructWithOwner.owner
  strong_retain %3 : $Klass // expected-remark {{retain of type 'Klass'}}
                            // expected-note @-3 {{of 'x'}}
  return %3 : $Klass
}

// Please keep these next to this test to make the note on the decl not far from its check.
var swiftEmptyArrayStorage: _SwiftEmptyArrayStorage
sil_global hidden @$s20opt_remark_generator22swiftEmptyArrayStorageAA06_SwiftefG0Vvp : $_SwiftEmptyArrayStorage

sil @retainOnEmptyArrayStorage : $@convention(thin) () -> @owned EmptyArrayStorage {
bb0:
  %0 = global_addr @$s20opt_remark_generator22swiftEmptyArrayStorageAA06_SwiftefG0Vvp : $*_SwiftEmptyArrayStorage
  %1 = address_to_pointer %0 : $*_SwiftEmptyArrayStorage to $Builtin.RawPointer
  %2 = raw_pointer_to_ref %1 : $Builtin.RawPointer to $EmptyArrayStorage
  strong_retain %2 : $EmptyArrayStorage // expected-remark {{retain of type 'EmptyArrayStorage'}}
                                        // expected-note @-9 {{of 'swiftEmptyArrayStorage'}}
  return %2 : $EmptyArrayStorage
}