Files
swift-mirror/test/SILOptimizer/illegal_escaping_address.swift
Erik Eckstein 9de45ac92e tests: remove -enforce-exclusivity=unchecked from tests which check the optimization result.
Tests which check if the optimizer is able to generate a certain code should never be "worked around" by adding command line options.
This defeats the purpose of such tests.
Unfortunately some optimizer deficiencies got unnoticed by adding this option.

to-do: there are more such cases which I didn't fix in this PR yet.
2020-02-11 14:21:22 +01:00

52 lines
1.1 KiB
Swift

// RUN: %target-swift-frontend -O -sil-verify-all -emit-sil -parse-as-library %s
// Check that the compiler does not crash for illegal escaping of an address
// of a local variable.
var gg = 0
@inline(never)
public func consume(_ x: Int) {
gg = x
}
public func test_load_after_dealloc_multi_block(b: Bool) {
var p: UnsafePointer<Int>? = nil
if (true) {
var local = 42
p = withUnsafePointer(to: &local) { p in
return p
}
}
if b {
consume(p!.pointee)
}
}
public func test_load_after_dealloc_single_block() {
var p: UnsafePointer<Int>? = nil
if (true) {
var local = 42
p = withUnsafePointer(to: &local) { p in
return p
}
}
consume(p!.pointee)
}
public func test_address_escaping_function_multi_block(b: Bool) -> UnsafePointer<Int>? {
var local = 42
let p: UnsafePointer<Int> = withUnsafePointer(to: &local) { p in return p }
if b {
return p
}
return nil
}
public func test_address_escaping_function_single_block() -> UnsafePointer<Int> {
var local = 42
let p: UnsafePointer<Int> = withUnsafePointer(to: &local) { p in return p }
return p
}