File: escape_analysis_release_hoisting.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,506 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-sil-verify-all -release-hoisting %s | %FileCheck %s
// REQUIRES: CPU=x86_64
// REQUIRES: OS=macosx

sil_stage canonical

import Builtin
import Swift
import SwiftShims

// Test <rdar://59559805> miscompile; use-after-free
// Avoid hoisting strong_release of an existential
// over a store to the value.
protocol ArrayElementProtocol {}

struct ArrayElementStruct : ArrayElementProtocol {
  @_hasStorage @_hasInitialValue var dummy: Int { get set }
}

// CHECK-LABEL: sil @testArrayStorageInitAfterFree : $@convention(thin) () -> () {
// CHECK:   [[ARRAY:%.*]] = alloc_ref [stack] [tail_elems $any ArrayElementProtocol * undef : $Builtin.Word] $_ContiguousArrayStorage<any ArrayElementProtocol>
// CHECK:   [[CAST:%.*]] = upcast [[ARRAY]] : $_ContiguousArrayStorage<any ArrayElementProtocol> to $__ContiguousArrayStorageBase
// CHECK:   [[TAIL:%.*]] = ref_tail_addr [[CAST]] : $__ContiguousArrayStorageBase, $any ArrayElementProtocol
// CHECK:   [[ADR:%.*]] = init_existential_addr [[TAIL]] : $*any ArrayElementProtocol, $ArrayElementStruct
// CHECK:   store %{{.*}} to [[ADR]] : $*ArrayElementStruct
// CHECK:   strong_release [[ARRAY]] : $_ContiguousArrayStorage<any ArrayElementProtocol>
// CHECK-LABEL: } // end sil function 'testArrayStorageInitAfterFree'
sil @testArrayStorageInitAfterFree : $@convention(thin) () -> () {
bb0:
  %0 = alloc_ref [stack] [tail_elems $ArrayElementProtocol * undef : $Builtin.Word] $_ContiguousArrayStorage<ArrayElementProtocol>
  %1 = upcast %0 : $_ContiguousArrayStorage<ArrayElementProtocol> to $__ContiguousArrayStorageBase
  %2 = struct $_SwiftArrayBodyStorage (undef : $Int, undef : $UInt)
  %3 = struct $_ArrayBody (%2 : $_SwiftArrayBodyStorage)
  %4 = ref_element_addr %1 : $__ContiguousArrayStorageBase, #__ContiguousArrayStorageBase.countAndCapacity
  store %3 to %4 : $*_ArrayBody
  %6 = ref_tail_addr %1 : $__ContiguousArrayStorageBase, $ArrayElementProtocol
  %7 = value_to_bridge_object undef : $Builtin.Int64
  %8 = struct $_StringObject (undef : $UInt64, %7 : $Builtin.BridgeObject)
  %9 = struct $_StringGuts (%8 : $_StringObject)
  %10 = struct $String (%9 : $_StringGuts)
  %11 = struct $ArrayElementStruct (undef : $Int)
  %12 = init_existential_addr %6 : $*ArrayElementProtocol, $ArrayElementStruct
  store %11 to %12 : $*ArrayElementStruct
  strong_release %0 : $_ContiguousArrayStorage<ArrayElementProtocol>
  dealloc_stack_ref %0 : $_ContiguousArrayStorage<ArrayElementProtocol>
  %16 = tuple ()
  return %16 : $()
}