Files
swift-mirror/test/Interop/C/struct/foreign-reference.swift
Egor Zhdan 9178af3ec7 [cxx-interop] Enable foreign reference types in C interop
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
2025-07-01 18:46:22 +01:00

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()