Skip to content
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: 4 additions & 0 deletions test/Interop/Cxx/operators/Inputs/module.modulemap
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module NonMemberInline {
header "non-member-inline.h"
}

module NonMemberOutOfLine {
header "non-member-out-of-line.h"
}
5 changes: 5 additions & 0 deletions test/Interop/Cxx/operators/Inputs/non-member-out-of-line.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "non-member-out-of-line.h"

IntBox operator+(IntBox lhs, IntBox rhs) {
return IntBox{.value = lhs.value + rhs.value};
}
10 changes: 10 additions & 0 deletions test/Interop/Cxx/operators/Inputs/non-member-out-of-line.h
Original file line number Diff line number Diff line change
@@ -0,0 +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 {
int value;
};

IntBox operator+(IntBox lhs, IntBox rhs);

#endif
8 changes: 8 additions & 0 deletions test/Interop/Cxx/operators/non-member-out-of-line-irgen.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s

import NonMemberOutOfLine

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

// CHECK: call i32 [[NAME:@(_Zpl6IntBoxS_|"\?\?H@YA\?AUIntBox@@U0@0@Z")]](i32 %{{[0-9]+}}, i32 %{{[0-9]+}})
// CHECK: declare {{(dso_local )?}}i32 [[NAME]](i32, i32)
10 changes: 10 additions & 0 deletions test/Interop/Cxx/operators/non-member-out-of-line-silgen.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %target-swift-emit-sil %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s

import NonMemberOutOfLine

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

// CHECK: [[COUNTER:%.*]] = function_ref [[NAME:@(_Zpl6IntBoxS_|\?\?H@YA\?AUIntBox@@U0@0@Z)]] : $@convention(c) (IntBox, IntBox) -> IntBox
// CHECK: apply [[COUNTER]](%0, %1) : $@convention(c) (IntBox, IntBox) -> IntBox

// CHECK: sil [serializable] [clang "+"] [[NAME]] : $@convention(c) (IntBox, IntBox) -> IntBox
23 changes: 23 additions & 0 deletions test/Interop/Cxx/operators/non-member-out-of-line.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %empty-directory(%t)
// RUN: %target-clang -c %S/Inputs/non-member-out-of-line.cpp -I %S/Inputs -o %t/non-member-out-of-line.o -std=c++17
// RUN: %target-build-swift %s -I %S/Inputs -o %t/non-member-out-of-line %t/non-member-out-of-line.o -Xfrontend -enable-cxx-interop
// RUN: %target-codesign %t/non-member-out-of-line
// RUN: %target-run %t/non-member-out-of-line
//
// REQUIRES: executable_test

import NonMemberOutOfLine
import StdlibUnittest

var OperatorsTestSuite = TestSuite("Operators")

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

let result = lhs + rhs

expectEqual(65, result.value)
}

runAllTests()