File tree Expand file tree Collapse file tree 6 files changed +83
-0
lines changed Expand file tree Collapse file tree 6 files changed +83
-0
lines changed Original file line number Diff line number Diff line change @@ -13,3 +13,7 @@ module StaticMemberVar {
13
13
module InlineStaticMemberVar {
14
14
header "inline-static-member-var.h"
15
15
}
16
+
17
+ module StaticMemberFunc {
18
+ header "static-member-func.h"
19
+ }
Original file line number Diff line number Diff line change
1
+ #include " static-member-func.h"
2
+
3
+ int WithStaticMemberFunc::staticMemberFunc () { return 1234 ; }
4
+ WithStaticMemberFunc::Func WithStaticMemberFunc::getStaticMemberFuncAddress () {
5
+ return &WithStaticMemberFunc::staticMemberFunc;
6
+ }
Original file line number Diff line number Diff line change
1
+ class WithStaticMemberFunc {
2
+ public:
3
+ static int staticMemberFunc ();
4
+ typedef int (*Func)();
5
+ static Func getStaticMemberFuncAddress ();
6
+ };
Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
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>
Original file line number Diff line number Diff line change
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 ( )
You can’t perform that action at this time.
0 commit comments