forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test C++ out-of-line operator functions
Add a test to verify that C++ out-of-line operator functions are imported correctly. Includes fixes for armv7 and arm64. This is part of addressing SR-12748.
- Loading branch information
Showing
6 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
test/Interop/Cxx/operators/Inputs/non-member-out-of-line.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
8
test/Interop/Cxx/operators/non-member-out-of-line-irgen.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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|i64}} [[NAME:@(_Zpl6IntBoxS_|"\?\?H@YA\?AUIntBox@@U0@0@Z")]]({{i32|\[1 x i32\]|i64}} %{{[0-9]+}}, {{i32|\[1 x i32\]|i64}} %{{[0-9]+}}) | ||
// CHECK: declare {{(dso_local )?}}{{i32|i64}} [[NAME]]({{i32|\[1 x i32\]|i64}}, {{i32|\[1 x i32\]|i64}}) |
10 changes: 10 additions & 0 deletions
10
test/Interop/Cxx/operators/non-member-out-of-line-silgen.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |