Skip to content

Commit d647794

Browse files
committed
[cxx-interop] Replace inline member "operator+" with "operator-".
Adding integers is a commutative operation meaning the old tests would fail to detect an error if the arguments were passed in the wrong order. Testing inline member operators using subtraction ensures that arguments are passed in the correct order.
1 parent c6a266e commit d647794

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

test/Interop/Cxx/operators/Inputs/member-inline.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
struct IntBox {
55
int value;
6-
IntBox operator+(IntBox rhs) { return IntBox{.value = value + rhs.value}; }
6+
IntBox operator-(IntBox rhs) { return IntBox{.value = value - rhs.value}; }
77
};
88

99
#endif

test/Interop/Cxx/operators/member-inline-irgen.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import MemberInline
77

8-
public func add(_ lhs: inout IntBox, _ rhs: IntBox) -> IntBox { lhs + rhs }
8+
public func sub(_ lhs: inout IntBox, _ rhs: IntBox) -> IntBox { lhs - rhs }
99

10-
// CHECK: call [[RES:i32|i64]] [[NAME:@(_ZN6IntBoxplES_|"\?\?HIntBox@@QEAA\?AU0@U0@@Z")]](%struct.IntBox* {{%[0-9]+}}, {{i32|\[1 x i32\]|i64|%struct.IntBox\* byval align 4}} {{%[0-9]+}})
10+
// CHECK: call [[RES:i32|i64]] [[NAME:@(_ZN6IntBoxmiES_|"\?\?GIntBox@@QEAA\?AU0@U0@@Z")]](%struct.IntBox* {{%[0-9]+}}, {{i32|\[1 x i32\]|i64|%struct.IntBox\* byval align 4}} {{%[0-9]+}})
1111
// CHECK: define linkonce_odr [[RES]] [[NAME]](%struct.IntBox* %this, {{i32 %rhs.coerce|\[1 x i32\] %rhs.coerce|i64 %rhs.coerce|%struct.IntBox\* byval\(%struct.IntBox\) align 4 %rhs}})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %target-swift-ide-test -print-module -module-to-print=MemberInline -I %S/Inputs -source-filename=x -enable-cxx-interop | %FileCheck %s
22

33
// CHECK: struct IntBox {
4-
// CHECK: static func + (lhs: inout IntBox, rhs: IntBox) -> IntBox
4+
// CHECK: static func - (lhs: inout IntBox, rhs: IntBox) -> IntBox
55
// CHECK: }

test/Interop/Cxx/operators/member-inline-silgen.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import MemberInline
44

5-
public func add(_ lhs: inout IntBox, _ rhs: IntBox) -> IntBox { lhs + rhs }
5+
public func sub(_ lhs: inout IntBox, _ rhs: IntBox) -> IntBox { lhs - rhs }
66

77
// CHECK: bb0([[SELF:%.*]] : $*IntBox, [[RHS:%.*]] : $IntBox):
88

99
// CHECK: [[SELFACCESS:%.*]] = begin_access [modify] [static] [[SELF]] : $*IntBox
10-
// CHECK: [[OP:%.*]] = function_ref [[NAME:@(_ZN6IntBoxplES_|\?\?HIntBox@@QEAA\?AU0@U0@@Z)]] : $@convention(c) (@inout IntBox, IntBox) -> IntBox
10+
// CHECK: [[OP:%.*]] = function_ref [[NAME:@(_ZN6IntBoxmiES_|\?\?GIntBox@@QEAA\?AU0@U0@@Z)]] : $@convention(c) (@inout IntBox, IntBox) -> IntBox
1111
// CHECK: apply [[OP]]([[SELFACCESS]], [[RHS]]) : $@convention(c) (@inout IntBox, IntBox) -> IntBox
1212
// CHECK: end_access [[SELFACCESS]] : $*IntBox
1313

14-
// CHECK: sil [clang IntBox."+"] [[NAME]] : $@convention(c) (@inout IntBox, IntBox) -> IntBox
14+
// CHECK: sil [clang IntBox."-"] [[NAME]] : $@convention(c) (@inout IntBox, IntBox) -> IntBox

test/Interop/Cxx/operators/member-inline-typechecker.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ import MemberInline
55
var lhs = IntBox(value: 42)
66
let rhs = IntBox(value: 23)
77

8-
let resultPlus = lhs + rhs
8+
let resultPlus = lhs - rhs

test/Interop/Cxx/operators/member-inline.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ OperatorsTestSuite.test("plus") {
1414
var lhs = IntBox(value: 42)
1515
let rhs = IntBox(value: 23)
1616

17-
let result = lhs + rhs
17+
let result = lhs - rhs
1818

19-
expectEqual(65, result.value)
19+
expectEqual(19, result.value)
2020
}
2121

2222
runAllTests()

0 commit comments

Comments
 (0)