Skip to content

C++ Interop: cleanup operator tests (NFC) #36144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/Interop/Cxx/operators/Inputs/member-out-of-line.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "member-out-of-line.h"

IntBox IntBox::operator+(IntBox rhs) const {
return IntBox{.value = value + rhs.value};
LoadableIntWrapper LoadableIntWrapper::operator+(LoadableIntWrapper rhs) const {
return LoadableIntWrapper{.value = value + rhs.value};
}
4 changes: 2 additions & 2 deletions test/Interop/Cxx/operators/Inputs/member-out-of-line.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef TEST_INTEROP_CXX_OPERATORS_INPUTS_MEMBER_OUT_OF_LINE_H
#define TEST_INTEROP_CXX_OPERATORS_INPUTS_MEMBER_OUT_OF_LINE_H

struct IntBox {
struct LoadableIntWrapper {
int value;
IntBox operator+(IntBox rhs) const;
LoadableIntWrapper operator+(LoadableIntWrapper rhs) const;
};

#endif
60 changes: 30 additions & 30 deletions test/Interop/Cxx/operators/Inputs/non-member-inline.h
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
#ifndef TEST_INTEROP_CXX_OPERATORS_INPUTS_NON_MEMBER_INLINE_H
#define TEST_INTEROP_CXX_OPERATORS_INPUTS_NON_MEMBER_INLINE_H

struct IntBox {
struct LoadableIntWrapper {
int value;
};

inline IntBox operator+(IntBox lhs, IntBox rhs) {
return IntBox{.value = lhs.value + rhs.value};
inline LoadableIntWrapper operator+(LoadableIntWrapper lhs, LoadableIntWrapper rhs) {
return LoadableIntWrapper{.value = lhs.value + rhs.value};
}

inline IntBox operator-(IntBox lhs, IntBox rhs) {
return IntBox{.value = lhs.value - rhs.value};
inline LoadableIntWrapper operator-(LoadableIntWrapper lhs, LoadableIntWrapper rhs) {
return LoadableIntWrapper{.value = lhs.value - rhs.value};
}

inline IntBox operator*(IntBox lhs, IntBox rhs) {
return IntBox{.value = lhs.value * rhs.value};
inline LoadableIntWrapper operator*(LoadableIntWrapper lhs, LoadableIntWrapper rhs) {
return LoadableIntWrapper{.value = lhs.value * rhs.value};
}

inline IntBox operator/(IntBox lhs, IntBox rhs) {
return IntBox{.value = lhs.value / rhs.value};
inline LoadableIntWrapper operator/(LoadableIntWrapper lhs, LoadableIntWrapper rhs) {
return LoadableIntWrapper{.value = lhs.value / rhs.value};
}

inline IntBox operator%(IntBox lhs, IntBox rhs) {
return IntBox{.value = lhs.value % rhs.value};
inline LoadableIntWrapper operator%(LoadableIntWrapper lhs, LoadableIntWrapper rhs) {
return LoadableIntWrapper{.value = lhs.value % rhs.value};
}

inline IntBox operator&(IntBox lhs, IntBox rhs) {
return IntBox{.value = lhs.value & rhs.value};
inline LoadableIntWrapper operator&(LoadableIntWrapper lhs, LoadableIntWrapper rhs) {
return LoadableIntWrapper{.value = lhs.value & rhs.value};
}

inline IntBox operator|(IntBox lhs, IntBox rhs) {
return IntBox{.value = lhs.value | rhs.value};
inline LoadableIntWrapper operator|(LoadableIntWrapper lhs, LoadableIntWrapper rhs) {
return LoadableIntWrapper{.value = lhs.value | rhs.value};
}

inline IntBox operator<<(IntBox lhs, IntBox rhs) {
return IntBox{.value = lhs.value << rhs.value};
inline LoadableIntWrapper operator<<(LoadableIntWrapper lhs, LoadableIntWrapper rhs) {
return LoadableIntWrapper{.value = lhs.value << rhs.value};
}

inline IntBox operator>>(IntBox lhs, IntBox rhs) {
return IntBox{.value = lhs.value >> rhs.value};
inline LoadableIntWrapper operator>>(LoadableIntWrapper lhs, LoadableIntWrapper rhs) {
return LoadableIntWrapper{.value = lhs.value >> rhs.value};
}

inline bool operator<(IntBox lhs, IntBox rhs) { return lhs.value < rhs.value; }
inline bool operator<(LoadableIntWrapper lhs, LoadableIntWrapper rhs) { return lhs.value < rhs.value; }

inline bool operator>(IntBox lhs, IntBox rhs) { return lhs.value > rhs.value; }
inline bool operator>(LoadableIntWrapper lhs, LoadableIntWrapper rhs) { return lhs.value > rhs.value; }

inline bool operator==(IntBox lhs, IntBox rhs) {
inline bool operator==(LoadableIntWrapper lhs, LoadableIntWrapper rhs) {
return lhs.value == rhs.value;
}

inline bool operator!=(IntBox lhs, IntBox rhs) {
inline bool operator!=(LoadableIntWrapper lhs, LoadableIntWrapper rhs) {
return lhs.value != rhs.value;
}

inline bool operator<=(IntBox lhs, IntBox rhs) {
inline bool operator<=(LoadableIntWrapper lhs, LoadableIntWrapper rhs) {
return lhs.value == rhs.value;
}

inline bool operator>=(IntBox lhs, IntBox rhs) {
inline bool operator>=(LoadableIntWrapper lhs, LoadableIntWrapper rhs) {
return lhs.value != rhs.value;
}

struct BoolBox {
struct LoadableBoolWrapper {
bool value;
};

inline BoolBox operator&&(BoolBox lhs, BoolBox rhs) {
return BoolBox{.value = lhs.value && rhs.value};
inline LoadableBoolWrapper operator&&(LoadableBoolWrapper lhs, LoadableBoolWrapper rhs) {
return LoadableBoolWrapper{.value = lhs.value && rhs.value};
}

inline BoolBox operator||(BoolBox lhs, BoolBox rhs) {
return BoolBox{.value = lhs.value || rhs.value};
inline LoadableBoolWrapper operator||(LoadableBoolWrapper lhs, LoadableBoolWrapper rhs) {
return LoadableBoolWrapper{.value = lhs.value || rhs.value};
}

// Make sure that we don't crash on templated operators
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "non-member-out-of-line.h"

IntBox operator+(IntBox lhs, IntBox rhs) {
return IntBox{.value = lhs.value + rhs.value};
LoadableIntWrapper operator+(LoadableIntWrapper lhs, LoadableIntWrapper rhs) {
return LoadableIntWrapper{.value = lhs.value + rhs.value};
}
4 changes: 2 additions & 2 deletions test/Interop/Cxx/operators/Inputs/non-member-out-of-line.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef TEST_INTEROP_CXX_OPERATORS_INPUTS_NON_MEMBER_OUT_OF_LINE_H
#define TEST_INTEROP_CXX_OPERATORS_INPUTS_NON_MEMBER_OUT_OF_LINE_H

struct IntBox {
struct LoadableIntWrapper {
int value;
};

IntBox operator+(IntBox lhs, IntBox rhs);
LoadableIntWrapper operator+(LoadableIntWrapper lhs, LoadableIntWrapper rhs);

#endif
6 changes: 3 additions & 3 deletions test/Interop/Cxx/operators/member-out-of-line-irgen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import MemberOutOfLine

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

// CHECK: call {{i32|i64}} [[NAME:@_ZNK6IntBoxplES_]](%struct.IntBox* %{{[0-9]+}}, {{i32|\[1 x i32\]|i64|%struct.IntBox\* byval\(.*\) align 4}} %{{[0-9]+}})
// CHECK: declare {{(dso_local )?}}{{i32|i64}} [[NAME]](%struct.IntBox* nonnull dereferenceable(4), {{i32|\[1 x i32\]|i64|%struct.IntBox\* byval\(%struct.IntBox\) align 4}})
// CHECK: call {{i32|i64}} [[NAME:@_ZNK18LoadableIntWrapperplES_]](%struct.LoadableIntWrapper* %{{[0-9]+}}, {{i32|\[1 x i32\]|i64|%struct.LoadableIntWrapper\* byval\(.*\) align 4}} %{{[0-9]+}})
// CHECK: declare {{(dso_local )?}}{{i32|i64}} [[NAME]](%struct.LoadableIntWrapper* nonnull dereferenceable(4), {{i32|\[1 x i32\]|i64|%struct.LoadableIntWrapper\* byval\(%struct.LoadableIntWrapper\) align 4}})
14 changes: 7 additions & 7 deletions test/Interop/Cxx/operators/member-out-of-line-silgen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

import MemberOutOfLine

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

// CHECK: bb0([[LHS:%.*]] : $*IntBox, [[RHS:%.*]] : $IntBox):
// CHECK: [[ACCESS:%.*]] = begin_access [modify] [static] [[LHS]] : $*IntBox
// CHECK: [[FUNC:%.*]] = function_ref [[NAME:@_ZNK6IntBoxplES_]] : $@convention(c) (@inout IntBox, IntBox) -> IntBox
// CHECK: apply [[FUNC]]([[ACCESS]], [[RHS]]) : $@convention(c) (@inout IntBox, IntBox) -> IntBox
// CHECK: end_access [[ACCESS]] : $*IntBox
// CHECK: bb0([[LHS:%.*]] : $*LoadableIntWrapper, [[RHS:%.*]] : $LoadableIntWrapper):
// CHECK: [[ACCESS:%.*]] = begin_access [modify] [static] [[LHS]] : $*LoadableIntWrapper
// CHECK: [[FUNC:%.*]] = function_ref [[NAME:@_ZNK18LoadableIntWrapperplES_]] : $@convention(c) (@inout LoadableIntWrapper, LoadableIntWrapper) -> LoadableIntWrapper
// CHECK: apply [[FUNC]]([[ACCESS]], [[RHS]]) : $@convention(c) (@inout LoadableIntWrapper, LoadableIntWrapper) -> LoadableIntWrapper
// CHECK: end_access [[ACCESS]] : $*LoadableIntWrapper

// CHECK: sil [clang IntBox."+"] [[NAME]] : $@convention(c) (@inout IntBox, IntBox) -> IntBox
// CHECK: sil [clang LoadableIntWrapper."+"] [[NAME]] : $@convention(c) (@inout LoadableIntWrapper, LoadableIntWrapper) -> LoadableIntWrapper
4 changes: 2 additions & 2 deletions test/Interop/Cxx/operators/member-out-of-line.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import StdlibUnittest
var OperatorsTestSuite = TestSuite("Operators")

OperatorsTestSuite.test("plus") {
var lhs = IntBox(value: 42)
let rhs = IntBox(value: 23)
var lhs = LoadableIntWrapper(value: 42)
let rhs = LoadableIntWrapper(value: 23)

let result = lhs + rhs

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// RUN: %target-swift-ide-test -print-module -module-to-print=NonMemberInline -I %S/Inputs -source-filename=x -enable-cxx-interop | %FileCheck %s

// CHECK: func + (lhs: IntBox, rhs: IntBox) -> IntBox
// CHECK-NEXT: func - (lhs: IntBox, rhs: IntBox) -> IntBox
// CHECK-NEXT: func * (lhs: IntBox, rhs: IntBox) -> IntBox
// CHECK-NEXT: func / (lhs: IntBox, rhs: IntBox) -> IntBox
// CHECK-NEXT: func % (lhs: IntBox, rhs: IntBox) -> IntBox
// CHECK-NEXT: func & (lhs: IntBox, rhs: IntBox) -> IntBox
// CHECK-NEXT: func | (lhs: IntBox, rhs: IntBox) -> IntBox
// CHECK-NEXT: func << (lhs: IntBox, rhs: IntBox) -> IntBox
// CHECK-NEXT: func >> (lhs: IntBox, rhs: IntBox) -> IntBox
// CHECK-NEXT: func < (lhs: IntBox, rhs: IntBox) -> Bool
// CHECK-NEXT: func > (lhs: IntBox, rhs: IntBox) -> Bool
// CHECK-NEXT: func == (lhs: IntBox, rhs: IntBox) -> Bool
// CHECK-NEXT: func != (lhs: IntBox, rhs: IntBox) -> Bool
// CHECK-NEXT: func <= (lhs: IntBox, rhs: IntBox) -> Bool
// CHECK-NEXT: func >= (lhs: IntBox, rhs: IntBox) -> Bool
// CHECK: func + (lhs: LoadableIntWrapper, rhs: LoadableIntWrapper) -> LoadableIntWrapper
// CHECK-NEXT: func - (lhs: LoadableIntWrapper, rhs: LoadableIntWrapper) -> LoadableIntWrapper
// CHECK-NEXT: func * (lhs: LoadableIntWrapper, rhs: LoadableIntWrapper) -> LoadableIntWrapper
// CHECK-NEXT: func / (lhs: LoadableIntWrapper, rhs: LoadableIntWrapper) -> LoadableIntWrapper
// CHECK-NEXT: func % (lhs: LoadableIntWrapper, rhs: LoadableIntWrapper) -> LoadableIntWrapper
// CHECK-NEXT: func & (lhs: LoadableIntWrapper, rhs: LoadableIntWrapper) -> LoadableIntWrapper
// CHECK-NEXT: func | (lhs: LoadableIntWrapper, rhs: LoadableIntWrapper) -> LoadableIntWrapper
// CHECK-NEXT: func << (lhs: LoadableIntWrapper, rhs: LoadableIntWrapper) -> LoadableIntWrapper
// CHECK-NEXT: func >> (lhs: LoadableIntWrapper, rhs: LoadableIntWrapper) -> LoadableIntWrapper
// CHECK-NEXT: func < (lhs: LoadableIntWrapper, rhs: LoadableIntWrapper) -> Bool
// CHECK-NEXT: func > (lhs: LoadableIntWrapper, rhs: LoadableIntWrapper) -> Bool
// CHECK-NEXT: func == (lhs: LoadableIntWrapper, rhs: LoadableIntWrapper) -> Bool
// CHECK-NEXT: func != (lhs: LoadableIntWrapper, rhs: LoadableIntWrapper) -> Bool
// CHECK-NEXT: func <= (lhs: LoadableIntWrapper, rhs: LoadableIntWrapper) -> Bool
// CHECK-NEXT: func >= (lhs: LoadableIntWrapper, rhs: LoadableIntWrapper) -> Bool

// CHECK: func && (lhs: BoolBox, rhs: BoolBox) -> BoolBox
// CHECK-NEXT: func || (lhs: BoolBox, rhs: BoolBox) -> BoolBox
// CHECK: func && (lhs: LoadableBoolWrapper, rhs: LoadableBoolWrapper) -> LoadableBoolWrapper
// CHECK-NEXT: func || (lhs: LoadableBoolWrapper, rhs: LoadableBoolWrapper) -> LoadableBoolWrapper
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import NonMemberInline

var lhs = IntBox(value: 42)
var rhs = IntBox(value: 23)
var lhs = LoadableIntWrapper(value: 42)
var rhs = LoadableIntWrapper(value: 23)

let resultPlus = lhs + rhs
let resultMinus = lhs - rhs
Expand All @@ -21,8 +21,8 @@ let resultExclaimEqual = lhs != rhs
let resultLessEqual = lhs <= rhs
let resultGreaterEqual = lhs >= rhs

var lhsBool = BoolBox(value: true)
var rhsBool = BoolBox(value: false)
var lhsBool = LoadableBoolWrapper(value: true)
var rhsBool = LoadableBoolWrapper(value: false)

let resultAmpAmp = lhsBool && rhsBool
let resultPipePipe = lhsBool && rhsBool
Loading