mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Type annotations for instruction operands are omitted, e.g. ``` %3 = struct $S(%1, %2) ``` Operand types are redundant anyway and were only used for sanity checking in the SIL parser. But: operand types _are_ printed if the definition of the operand value was not printed yet. This happens: * if the block with the definition appears after the block where the operand's instruction is located * if a block or instruction is printed in isolation, e.g. in a debugger The old behavior can be restored with `-Xllvm -sil-print-types`. This option is added to many existing test files which check for operand types in their check-lines.
58 lines
2.1 KiB
Plaintext
58 lines
2.1 KiB
Plaintext
// RUN: %target-sil-opt -sil-print-types -enforce-exclusivity=none -enable-sil-verify-all %s -copy-forwarding -enable-copyforwarding | %FileCheck %s
|
|
|
|
// CopyForwarding currently only runs on OSSA. This file only contains
|
|
// tests that will break is CopyForwarding were to run on non-OSSA SIL.
|
|
|
|
sil_stage canonical
|
|
|
|
import Builtin
|
|
import Swift
|
|
|
|
struct ObjWrapper {
|
|
var obj: AnyObject
|
|
}
|
|
|
|
// If CopyForwarding (with destroy-hoisting) runs on non-OSSA SIL it
|
|
// may result in a use-after-free in this case.
|
|
//
|
|
// In this example, some other pass, such as retain-sinking, has
|
|
// already moved an object's retain (bb1) below the destroy of the
|
|
// memory from which the object was originally loaded (copy_addr
|
|
// [take] in bb0). This seems crazy but still follows non-OSSA SIL
|
|
// rules.
|
|
//
|
|
// If destroy hoisting reorders the retain and destroy_addr in bb1,
|
|
// then the object passed as a guaranteed argument will be incorrectly
|
|
// destroyed.
|
|
// CHECK-LABEL: sil @testDestroyHoistOverRetain : $@convention(thin) (@guaranteed AnyObject) -> () {
|
|
// CHECK: bb1:
|
|
// CHECK: retain_value %{{.*}} : $AnyObject
|
|
// CHECK: destroy_addr %{{.*}} : $*ObjWrapper
|
|
// CHECK-LABEL: } // end sil function 'testDestroyHoistOverRetain'
|
|
sil @testDestroyHoistOverRetain : $@convention(thin) (@guaranteed AnyObject) -> () {
|
|
bb0(%0 : $AnyObject):
|
|
%alloc1 = alloc_stack $ObjWrapper
|
|
%objaddr = struct_element_addr %alloc1 : $*ObjWrapper, #ObjWrapper.obj
|
|
store %0 to %objaddr : $*AnyObject
|
|
%ref = load %objaddr : $*AnyObject
|
|
%alloc2 = alloc_stack $ObjWrapper
|
|
// The location loaded from is destroyed here with no corresponding
|
|
// retain.
|
|
copy_addr [take] %alloc1 to [init] %alloc2 : $*ObjWrapper
|
|
cond_br undef, bb1, bb2
|
|
bb1:
|
|
// This retain and destroy are not obviously related but need to
|
|
// execute in this order to cancel each other out.
|
|
retain_value %ref : $AnyObject
|
|
destroy_addr %alloc2 : $*ObjWrapper
|
|
br bb3
|
|
bb2:
|
|
copy_addr [take] %alloc2 to [init] %alloc1 : $*ObjWrapper
|
|
br bb3
|
|
bb3:
|
|
dealloc_stack %alloc2 : $*ObjWrapper
|
|
dealloc_stack %alloc1 : $*ObjWrapper
|
|
%99 = tuple ()
|
|
return %99 : $()
|
|
}
|