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
3 changes: 2 additions & 1 deletion lib/PrintAsClang/PrintClangFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,8 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
}
llvm::Optional<StringRef> indirectFunctionVar;
using DispatchKindTy = IRABIDetailsProvider::MethodDispatchInfo::Kind;
if (dispatchInfo) {
if (dispatchInfo && !isStaticMethod) {
// Always dispatch class methods directly to the concrete class instance.
switch (dispatchInfo->getKind()) {
case DispatchKindTy::Direct:
break;
Expand Down
8 changes: 8 additions & 0 deletions test/Interop/SwiftToCxx/methods/method-in-cxx-execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,13 @@ int main() {
largeStruct.dump();
// CHECK-NEXT: 1, -1, -9075, -2, 9075, -456
}

{
auto x = ClassWithNonFinalMethods::classClassMethod(3);
assert(x == 5);
ClassWithNonFinalMethods::staticClassMethod();
}
// CHECK-NEXT: ClassWithNonFinalMethods.classClassMethod;
// CHECK-NEXT: ClassWithNonFinalMethods.staticClassMethod;
return 0;
}
16 changes: 16 additions & 0 deletions test/Interop/SwiftToCxx/methods/method-in-cxx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ public final class ClassWithMethods {
}
}

public class ClassWithNonFinalMethods {
class public func classClassMethod(x: Int) -> Int {
print("ClassWithNonFinalMethods.classClassMethod;")
return x + 2
}
static public func staticClassMethod() {
print("ClassWithNonFinalMethods.staticClassMethod;")
}
}

public final class PassStructInClassMethod {
var largeStruct: LargeStruct
init() { largeStruct = LargeStruct(x1: 1, x2: 2, x3: 3, x4: 4, x5: 5, x6: 6) }
Expand Down Expand Up @@ -163,6 +173,12 @@ public func createPassStructInClassMethod() -> PassStructInClassMethod {
// CHECK-NEXT: _impl::$s7Methods09ClassWithA0C011staticFinalB6Method1xAA11LargeStructVSi_tFZ(result, x, swift::TypeMetadataTrait<ClassWithMethods>::getTypeMetadata());
// CHECK-NEXT: });
// CHECK-NEXT: }
// CHECK-NEXT: SWIFT_INLINE_THUNK swift::Int ClassWithNonFinalMethods::classClassMethod(swift::Int x) {
// CHECK-NEXT: return _impl::$s7Methods017ClassWithNonFinalA0C05classB6Method1xS2i_tFZ(x, swift::TypeMetadataTrait<ClassWithNonFinalMethods>::getTypeMetadata());
// CHECK-NEXT: }
// CHECK-NEXT: SWIFT_INLINE_THUNK void ClassWithNonFinalMethods::staticClassMethod() {
// CHECK-NEXT: return _impl::$s7Methods017ClassWithNonFinalA0C06staticB6MethodyyFZ(swift::TypeMetadataTrait<ClassWithNonFinalMethods>::getTypeMetadata());
// CHECK-NEXT: }

// CHECK: SWIFT_INLINE_THUNK LargeStruct LargeStruct::doubled() const {
// CHECK-NEXT: return _impl::_impl_LargeStruct::returnNewValue([&](char * _Nonnull result) SWIFT_INLINE_THUNK_ATTRIBUTES {
Expand Down