mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Most of the logic for C++ foreign reference types can be applied to C types as well. Swift had a compiler flag `-Xfrontend -experimental-c-foreign-reference-types` for awhile now which enables foreign reference types without having to enable C++ interop. This change makes it the default behavior. Since we don't expect anyone to pass `experimental-c-foreign-reference-types` currently, this also removes the frontend flag. rdar://150308819
55 lines
1.2 KiB
Swift
55 lines
1.2 KiB
Swift
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -validate-tbd-against-ir=none -Onone -D NO_OPTIMIZATIONS)
|
|
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -validate-tbd-against-ir=none -O)
|
|
//
|
|
// REQUIRES: executable_test
|
|
|
|
// XFAIL: OS=windows-msvc
|
|
// FIXME: Runtime support for C++ foreign reference types is missing on Windows (https://github.com/swiftlang/swift/issues/82643)
|
|
|
|
import StdlibUnittest
|
|
import ForeignReference
|
|
|
|
var ReferenceCountedTestSuite = TestSuite("Foreign reference types that have reference counts")
|
|
|
|
@inline(never)
|
|
public func blackHole<T>(_ _: T) { }
|
|
|
|
ReferenceCountedTestSuite.test("Local") {
|
|
var x = createLocalCount()
|
|
#if NO_OPTIMIZATIONS
|
|
expectEqual(x.value, 2)
|
|
#endif
|
|
|
|
let t = (x, x, x)
|
|
#if NO_OPTIMIZATIONS
|
|
expectEqual(x.value, 5)
|
|
#endif
|
|
}
|
|
|
|
@inline(never)
|
|
func globalTest1() {
|
|
var x = createGlobalCount()
|
|
let t = (x, x, x)
|
|
#if NO_OPTIMIZATIONS
|
|
expectEqual(globalCount, 4)
|
|
#endif
|
|
blackHole(t)
|
|
}
|
|
|
|
@inline(never)
|
|
func globalTest2() {
|
|
var x = createGlobalCount()
|
|
#if NO_OPTIMIZATIONS
|
|
expectEqual(globalCount, 1)
|
|
#endif
|
|
}
|
|
|
|
ReferenceCountedTestSuite.test("Global") {
|
|
expectEqual(globalCount, 0)
|
|
globalTest1()
|
|
globalTest2()
|
|
expectEqual(globalCount, 0)
|
|
}
|
|
|
|
runAllTests()
|