Skip to content

Test static member functions #31396

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
Apr 30, 2020
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/static/Inputs/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ module StaticMemberVar {
module InlineStaticMemberVar {
header "inline-static-member-var.h"
}

module StaticMemberFunc {
header "static-member-func.h"
}
6 changes: 6 additions & 0 deletions test/Interop/Cxx/static/Inputs/static-member-func.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "static-member-func.h"

int WithStaticMemberFunc::staticMemberFunc() { return 1234; }
WithStaticMemberFunc::Func WithStaticMemberFunc::getStaticMemberFuncAddress() {
return &WithStaticMemberFunc::staticMemberFunc;
}
6 changes: 6 additions & 0 deletions test/Interop/Cxx/static/Inputs/static-member-func.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class WithStaticMemberFunc {
public:
static int staticMemberFunc();
typedef int (*Func)();
static Func getStaticMemberFuncAddress();
};
23 changes: 23 additions & 0 deletions test/Interop/Cxx/static/static-member-func-irgen.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s

import StaticMemberFunc

public func callStaticMemberFunc() -> CInt {
return WithStaticMemberFunc.staticMemberFunc()
}

// CHECK: define {{(protected |dllexport )?}}swiftcc i32 @"$s4main20callStaticMemberFuncs5Int32VyF"()
// CHECK: [[VALUE:%.*]] = call i32 @{{_ZN20WithStaticMemberFunc16staticMemberFuncEv|"\?staticMemberFunc@WithStaticMemberFunc@@SAHXZ"}}()
// CHECK: ret i32 [[VALUE]]

// CHECK: declare {{(dso_local )?}}i32 @{{_ZN20WithStaticMemberFunc16staticMemberFuncEv|"\?staticMemberFunc@WithStaticMemberFunc@@SAHXZ"}}()

public func callStaticMemberFuncAddr() -> CInt {
return WithStaticMemberFunc.getStaticMemberFuncAddress()!()
}

// CHECK: define {{(protected |dllexport )?}}swiftcc i32 @"$s4main24callStaticMemberFuncAddrs5Int32VyF"()
// CHECK: call i32 ()* @{{_ZN20WithStaticMemberFunc26getStaticMemberFuncAddressEv|"\?getStaticMemberFuncAddress@WithStaticMemberFunc@@SAP6AHXZXZ"}}()

// CHECK: declare {{(dso_local )?}}i32 ()* @{{_ZN20WithStaticMemberFunc26getStaticMemberFuncAddressEv|"\?getStaticMemberFuncAddress@WithStaticMemberFunc@@SAP6AHXZXZ"}}()

24 changes: 24 additions & 0 deletions test/Interop/Cxx/static/static-member-func-silgen.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: %target-swift-emit-sil %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s

import StaticMemberFunc

func callStaticMemberFunc() -> CInt {
return WithStaticMemberFunc.staticMemberFunc()
}

// CHECK: sil hidden @$s4main20callStaticMemberFuncs5Int32VyF : $@convention(thin) () -> Int32 {
// CHECK: [[FUNC:%.*]] = function_ref @{{_ZN20WithStaticMemberFunc16staticMemberFuncEv|\?staticMemberFunc@WithStaticMemberFunc@@SAHXZ}} : $@convention(c) () -> Int32
// CHECK: [[VALUE:%.*]] = apply [[FUNC]]() : $@convention(c) () -> Int32
// CHECK: return [[VALUE]] : $Int32

// CHECK: sil [clang WithStaticMemberFunc.staticMemberFunc] @{{_ZN20WithStaticMemberFunc16staticMemberFuncEv|\?staticMemberFunc@WithStaticMemberFunc@@SAHXZ}} : $@convention(c) () -> Int32

func callStaticMemberFuncAddr() -> CInt {
return WithStaticMemberFunc.getStaticMemberFuncAddress()!()
}

// CHECK: sil hidden @$s4main24callStaticMemberFuncAddrs5Int32VyF : $@convention(thin) () -> Int32
// CHECK: [[FUNC:%.*]] = function_ref @{{_ZN20WithStaticMemberFunc26getStaticMemberFuncAddressEv|\?getStaticMemberFuncAddress@WithStaticMemberFunc@@SAP6AHXZXZ}} : $@convention(c) () -> Optional<@convention(c) () -> Int32>
// CHECK: [[VALUE:%.*]] = apply [[FUNC]]() : $@convention(c) () -> Optional<@convention(c) () -> Int32>

// CHECK: sil [clang WithStaticMemberFunc.getStaticMemberFuncAddress] @{{_ZN20WithStaticMemberFunc26getStaticMemberFuncAddressEv|\?getStaticMemberFuncAddress@WithStaticMemberFunc@@SAP6AHXZXZ}} : $@convention(c) () -> Optional<@convention(c) () -> Int32>
20 changes: 20 additions & 0 deletions test/Interop/Cxx/static/static-member-func.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %empty-directory(%t)
// RUN: %target-clang -c %S/Inputs/static-member-func.cc -I %S/Inputs -o %t/static-member-func.o -std=c++11
// RUN: %target-build-swift %s -I %S/Inputs -o %t/statics %t/static-member-func.o -Xfrontend -enable-cxx-interop -Xcc -std=c++11
// RUN: %target-codesign %t/statics
// RUN: %target-run %t/statics
//
// REQUIRES: executable_test

import StaticMemberFunc
import StdlibUnittest

var StaticMemberFuncTestSuite = TestSuite("StaticMemberFuncTestSuite")

StaticMemberFuncTestSuite.test("call-static-member-func") {
expectEqual(
1234,
WithStaticMemberFunc.staticMemberFunc())
}

runAllTests()