Skip to content

Commit a3d30c9

Browse files
committed
[cxx-interop] Test std::optional with AddressableParameters
Enabling AddressableParameters feature resolves a miscompile with `var pointee` properties of `std::optional`. rdar://154945438 / #82765
1 parent 6c87a0c commit a3d30c9

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

test/Interop/Cxx/stdlib/use-std-optional.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -cxx-interoperability-mode=swift-5.9)
22
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -cxx-interoperability-mode=swift-6)
33
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -cxx-interoperability-mode=upcoming-swift)
4+
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -cxx-interoperability-mode=upcoming-swift -enable-experimental-feature AddressableParameters)
45
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -cxx-interoperability-mode=upcoming-swift -Xcc -std=c++20)
56
//
67
// REQUIRES: executable_test
@@ -58,10 +59,18 @@ StdOptionalTestSuite.test("std::optional init(_:Wrapped)") {
5859

5960
// FIXME: making these variables immutable triggers a miscompile on Linux
6061
// (https://github.com/swiftlang/swift/issues/82765)
61-
var optBoolT = StdOptionalBool(true)
62-
var optBoolF = StdOptionalBool(false)
62+
var optBoolTMutable = StdOptionalBool(true)
63+
var optBoolFMutable = StdOptionalBool(false)
64+
expectTrue(optBoolTMutable.pointee)
65+
expectFalse(optBoolFMutable.pointee)
66+
67+
// If AddressableParameters are enabled, this issue does not happen.
68+
#if hasFeature(AddressableParameters)
69+
let optBoolT = StdOptionalBool(true)
70+
let optBoolF = StdOptionalBool(false)
6371
expectTrue(optBoolT.pointee)
6472
expectFalse(optBoolF.pointee)
73+
#endif
6574

6675
let optString = StdOptionalString(std.string("abc"))
6776
expectEqual(std.string("abc"), optString.pointee)

0 commit comments

Comments
 (0)