Skip to content

Commit 39f826c

Browse files
authored
Merge pull request swiftlang#74822 from swiftlang/egorzhdan/frt-safety-heuristic-test
[cxx-interop] Add tests for methods of reference types returning reference types
2 parents 02a8f24 + deea1e8 commit 39f826c

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

test/Interop/Cxx/foreign-reference/Inputs/pod.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ __attribute__((swift_attr("release:immortal"))) IntPair {
4747
int test() const { return b - a; }
4848
int testMutable() { return b - a; }
4949

50+
IntPair &instancePassThroughByRef(IntPair& ref) { return ref; }
51+
static IntPair &staticPassThroughByRef(IntPair& ref) { return ref; }
5052
static IntPair *create() { return new (malloc(sizeof(IntPair))) IntPair(); }
5153
};
5254

@@ -55,6 +57,7 @@ void mutateIt(IntPair &x) {
5557
x.b = 4;
5658
}
5759
IntPair passThroughByValue(IntPair x) { return x; }
60+
IntPair &passThroughByRef(IntPair &x) { return x; }
5861

5962
struct __attribute__((swift_attr("import_reference")))
6063
__attribute__((swift_attr("retain:immortal")))
@@ -118,6 +121,17 @@ struct ValueHoldingPair {
118121
}
119122
};
120123

124+
struct ValueHoldingPairRef {
125+
IntPair &pair = *IntPair::create();
126+
127+
int sub(const IntPair &other) const {
128+
return pair.test() - other.test();
129+
};
130+
const IntPair &max(const IntPair &other) const {
131+
return pair.test() > other.test() ? pair : other;
132+
};
133+
};
134+
121135
struct __attribute__((swift_attr("import_reference")))
122136
__attribute__((swift_attr("retain:immortal")))
123137
__attribute__((swift_attr("release:immortal"))) BigType {

test/Interop/Cxx/foreign-reference/pod-module-interface.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424
// CHECK-NOT: init
2525
// CHECK: func test() -> Int32
2626
// CHECK: func testMutable() -> Int32
27+
// CHECK: func instancePassThroughByRef(_ ref: IntPair) -> IntPair
28+
// CHECK: class func staticPassThroughByRef(_ ref: IntPair) -> IntPair
2729
// CHECK: class func create() -> IntPair
2830
// CHECK: var a: Int32
2931
// CHECK: var b: Int32
3032
// CHECK: }
3133
// CHECK: func mutateIt(_ x: IntPair)
3234
// CHECK-NOT: func passThroughByValue(_ x: IntPair) -> IntPair
35+
// CHECK: func passThroughByRef(_ x: IntPair) -> IntPair
3336

3437
// CHECK: class RefHoldingPair {
3538
// CHECK-NOT: init
@@ -68,6 +71,13 @@
6871
// CHECK: var otherValue: Int32
6972
// CHECK: }
7073

74+
// CHECK: struct ValueHoldingPairRef {
75+
// CHECK-NOT: pair
76+
// CHECK: init()
77+
// CHECK: func sub(_ other: IntPair) -> Int32
78+
// CHECK: func max(_ other: IntPair) -> IntPair
79+
// CHECK: }
80+
7181
// CHECK: class BigType {
7282
// CHECK-NOT: init
7383
// CHECK: func test() -> Int32

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ PODTestSuite.test("RefHoldingPairPtr") {
114114
expectEqual(x.test(), 41)
115115
}
116116

117+
PODTestSuite.test("ValueHoldingPairRef") {
118+
let x = ValueHoldingPairRef()
119+
expectEqual(x.pair.test(), 1)
120+
121+
let pair2 = IntPair.create()
122+
pair2.b = 123
123+
expectEqual(x.sub(pair2), -121)
124+
expectEqual(x.max(pair2).test(), pair2.test())
125+
}
126+
117127
PODTestSuite.test("StructHoldingPair") {
118128
var x = StructHoldingPair(pair: IntPair.create())
119129
expectEqual(x.pair.test(), 1)

0 commit comments

Comments
 (0)