Skip to content

Commit 527d3db

Browse files
committed
[cxx-interop] Fix execution test for reference types
When compiling with optimizations, the compiler might reorder some instructions, leading to test failures. rdar://127795755 (cherry picked from commit 27829b7)
1 parent a329940 commit 527d3db

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

test/Interop/Cxx/foreign-reference/reference-counted.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -enable-experimental-cxx-interop -Xfrontend -validate-tbd-against-ir=none -Xfrontend -disable-llvm-verify -Xfrontend -disable-availability-checking)
1+
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -enable-experimental-cxx-interop -Xfrontend -validate-tbd-against-ir=none -Xfrontend -disable-llvm-verify -Xfrontend -disable-availability-checking -Onone -D NO_OPTIMIZATIONS)
2+
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -enable-experimental-cxx-interop -Xfrontend -validate-tbd-against-ir=none -Xfrontend -disable-llvm-verify -Xfrontend -disable-availability-checking -O)
23
//
34
// REQUIRES: executable_test
45
// TODO: This should work without ObjC interop in the future rdar://97497120
@@ -15,13 +16,17 @@ public func blackHole<T>(_ _: T) { }
1516
@inline(never)
1617
func localTest() {
1718
var x = NS.LocalCount.create()
19+
#if NO_OPTIMIZATIONS
1820
expectEqual(x.value, 8) // This is 8 because of "var x" "x.value" * 2, two method calls on x, and "(x, x, x)".
21+
#endif
1922

2023
expectEqual(x.returns42(), 42)
2124
expectEqual(x.constMethod(), 42)
2225

2326
let t = (x, x, x)
27+
#if NO_OPTIMIZATIONS
2428
expectEqual(x.value, 5)
29+
#endif
2530
}
2631

2732
ReferenceCountedTestSuite.test("Local") {
@@ -41,14 +46,18 @@ ReferenceCountedTestSuite.test("Global optional holding local ref count") {
4146
func globalTest1() {
4247
var x = GlobalCount.create()
4348
let t = (x, x, x)
49+
#if NO_OPTIMIZATIONS
4450
expectEqual(globalCount, 4)
51+
#endif
4552
blackHole(t)
4653
}
4754

4855
@inline(never)
4956
func globalTest2() {
5057
var x = GlobalCount.create()
58+
#if NO_OPTIMIZATIONS
5159
expectEqual(globalCount, 1)
60+
#endif
5261
}
5362

5463
ReferenceCountedTestSuite.test("Global") {

0 commit comments

Comments
 (0)