Files
swift-mirror/test/SILOptimizer/dse_with_union.swift
Erik Eckstein 5a5cbf78a0 EscapeAnalysis: fix a problem with unchecked_addr_cast
In case an unchecked_addr_cast is used to convert between pointer and non-pointer, we missed some escaping values.
This can be the case when using C unions.

https://bugs.swift.org/browse/SR-12427
rdar://problem/60983997
2020-04-03 09:07:34 +02:00

29 lines
687 B
Swift

// RUN: %empty-directory(%t)
// RUN: %target-build-swift -O %s -import-objc-header %S/Inputs/dse_with_union.h -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s
// REQUIRES: executable_test
// Check that EscapeAnalysis does not mess up with a union.
@inline(never)
func printit(_ u: inout U) {
print(u.p![0])
}
@inline(never)
func testit(s: S) {
var vs = s
withUnsafeMutablePointer(to: &vs) {
// A C union is an opaque type in swift and not considered as a "pointer"
// in escape analysis. Converting between pointer and non-pointer resulted
// in a wrong connection graph.
var u = U(p: $0)
printit(&u)
}
}
// CHECK: S(i: 27)
testit(s: S(i: 27))