Skip to content

Commit fb7020f

Browse files
authored
Merge pull request #31396 from hlopko/static-member-func
Test static member functions
2 parents 5e60fa0 + cf62838 commit fb7020f

File tree

6 files changed

+83
-0
lines changed

6 files changed

+83
-0
lines changed

test/Interop/Cxx/static/Inputs/module.modulemap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ module StaticMemberVar {
1313
module InlineStaticMemberVar {
1414
header "inline-static-member-var.h"
1515
}
16+
17+
module StaticMemberFunc {
18+
header "static-member-func.h"
19+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "static-member-func.h"
2+
3+
int WithStaticMemberFunc::staticMemberFunc() { return 1234; }
4+
WithStaticMemberFunc::Func WithStaticMemberFunc::getStaticMemberFuncAddress() {
5+
return &WithStaticMemberFunc::staticMemberFunc;
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class WithStaticMemberFunc {
2+
public:
3+
static int staticMemberFunc();
4+
typedef int (*Func)();
5+
static Func getStaticMemberFuncAddress();
6+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
2+
3+
import StaticMemberFunc
4+
5+
public func callStaticMemberFunc() -> CInt {
6+
return WithStaticMemberFunc.staticMemberFunc()
7+
}
8+
9+
// CHECK: define {{(protected |dllexport )?}}swiftcc i32 @"$s4main20callStaticMemberFuncs5Int32VyF"()
10+
// CHECK: [[VALUE:%.*]] = call i32 @{{_ZN20WithStaticMemberFunc16staticMemberFuncEv|"\?staticMemberFunc@WithStaticMemberFunc@@SAHXZ"}}()
11+
// CHECK: ret i32 [[VALUE]]
12+
13+
// CHECK: declare {{(dso_local )?}}i32 @{{_ZN20WithStaticMemberFunc16staticMemberFuncEv|"\?staticMemberFunc@WithStaticMemberFunc@@SAHXZ"}}()
14+
15+
public func callStaticMemberFuncAddr() -> CInt {
16+
return WithStaticMemberFunc.getStaticMemberFuncAddress()!()
17+
}
18+
19+
// CHECK: define {{(protected |dllexport )?}}swiftcc i32 @"$s4main24callStaticMemberFuncAddrs5Int32VyF"()
20+
// CHECK: call i32 ()* @{{_ZN20WithStaticMemberFunc26getStaticMemberFuncAddressEv|"\?getStaticMemberFuncAddress@WithStaticMemberFunc@@SAP6AHXZXZ"}}()
21+
22+
// CHECK: declare {{(dso_local )?}}i32 ()* @{{_ZN20WithStaticMemberFunc26getStaticMemberFuncAddressEv|"\?getStaticMemberFuncAddress@WithStaticMemberFunc@@SAP6AHXZXZ"}}()
23+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %target-swift-emit-sil %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
2+
3+
import StaticMemberFunc
4+
5+
func callStaticMemberFunc() -> CInt {
6+
return WithStaticMemberFunc.staticMemberFunc()
7+
}
8+
9+
// CHECK: sil hidden @$s4main20callStaticMemberFuncs5Int32VyF : $@convention(thin) () -> Int32 {
10+
// CHECK: [[FUNC:%.*]] = function_ref @{{_ZN20WithStaticMemberFunc16staticMemberFuncEv|\?staticMemberFunc@WithStaticMemberFunc@@SAHXZ}} : $@convention(c) () -> Int32
11+
// CHECK: [[VALUE:%.*]] = apply [[FUNC]]() : $@convention(c) () -> Int32
12+
// CHECK: return [[VALUE]] : $Int32
13+
14+
// CHECK: sil [clang WithStaticMemberFunc.staticMemberFunc] @{{_ZN20WithStaticMemberFunc16staticMemberFuncEv|\?staticMemberFunc@WithStaticMemberFunc@@SAHXZ}} : $@convention(c) () -> Int32
15+
16+
func callStaticMemberFuncAddr() -> CInt {
17+
return WithStaticMemberFunc.getStaticMemberFuncAddress()!()
18+
}
19+
20+
// CHECK: sil hidden @$s4main24callStaticMemberFuncAddrs5Int32VyF : $@convention(thin) () -> Int32
21+
// CHECK: [[FUNC:%.*]] = function_ref @{{_ZN20WithStaticMemberFunc26getStaticMemberFuncAddressEv|\?getStaticMemberFuncAddress@WithStaticMemberFunc@@SAP6AHXZXZ}} : $@convention(c) () -> Optional<@convention(c) () -> Int32>
22+
// CHECK: [[VALUE:%.*]] = apply [[FUNC]]() : $@convention(c) () -> Optional<@convention(c) () -> Int32>
23+
24+
// CHECK: sil [clang WithStaticMemberFunc.getStaticMemberFuncAddress] @{{_ZN20WithStaticMemberFunc26getStaticMemberFuncAddressEv|\?getStaticMemberFuncAddress@WithStaticMemberFunc@@SAP6AHXZXZ}} : $@convention(c) () -> Optional<@convention(c) () -> Int32>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-clang -c %S/Inputs/static-member-func.cc -I %S/Inputs -o %t/static-member-func.o -std=c++11
3+
// RUN: %target-build-swift %s -I %S/Inputs -o %t/statics %t/static-member-func.o -Xfrontend -enable-cxx-interop -Xcc -std=c++11
4+
// RUN: %target-codesign %t/statics
5+
// RUN: %target-run %t/statics
6+
//
7+
// REQUIRES: executable_test
8+
9+
import StaticMemberFunc
10+
import StdlibUnittest
11+
12+
var StaticMemberFuncTestSuite = TestSuite("StaticMemberFuncTestSuite")
13+
14+
StaticMemberFuncTestSuite.test("call-static-member-func") {
15+
expectEqual(
16+
1234,
17+
WithStaticMemberFunc.staticMemberFunc())
18+
}
19+
20+
runAllTests()

0 commit comments

Comments
 (0)