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
1 change: 1 addition & 0 deletions lib/ClangImporter/SwiftDeclSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2106,6 +2106,7 @@ clang::CXXMethodDecl *SwiftDeclSynthesizer::synthesizeCXXForwardingMethod(
newMethod->setImplicit();
newMethod->setImplicitlyInline();
newMethod->setAccess(clang::AccessSpecifier::AS_public);
newMethod->addAttr(clang::NoDebugAttr::CreateImplicit(clangCtx));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit curious what is going on here. We are specifying the source range for the created method here, so I would suspect codegen to generate the right debug info based on that. Or is this due to missing source locations in the body of the function? Should we add this attribute to other synthesized functions as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add this attribute to other synthesized functions as well?

Yeah I think so, but let's make it a separate change to make this diff smaller and easier to cherry-pick.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is this due to missing source locations in the body of the function?

Yes, exactly - particularly on calls to destructors in the body of the synthesized function. I've updated the PR description.

if (method->hasAttr<clang::CFReturnsRetainedAttr>()) {
// Return an FRT field at +1 if the base method also follows this
// convention.
Expand Down
9 changes: 9 additions & 0 deletions test/Interop/Cxx/class/inheritance/Inputs/virtual-methods.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ struct DerivedFromCallsPureMethod : CallsPureMethod {

struct DerivedFromDerivedFromCallsPureMethod : DerivedFromCallsPureMethod {};

struct HasDestructor {
~HasDestructor() {}
};

// MARK: Reference Types:

#define IMMORTAL_FRT \
Expand All @@ -76,6 +80,11 @@ struct IMMORTAL_FRT DerivedFromImmortal : public Immortal {
static DerivedFromImmortal *_Nonnull create() { return new DerivedFromImmortal(); }
};

struct IMMORTAL_FRT Immortal2 {
public:
virtual void virtualMethod(HasDestructor) = 0;
};

inline const ImmortalBase *_Nonnull castToImmortalBase(
const Immortal *_Nonnull immortal) {
return static_cast<const ImmortalBase *>(immortal);
Expand Down
11 changes: 11 additions & 0 deletions test/Interop/Cxx/class/inheritance/virtual-methods.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=swift-5.9)
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=swift-6)
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift)
// RUN: %target-run-simple-swift(-g -I %S/Inputs -cxx-interoperability-mode=default)

// REQUIRES: executable_test

Expand Down Expand Up @@ -53,4 +54,14 @@ if #available(SwiftStdlib 5.8, *) {
}
}

#if !os(Windows)
// FIXME in Windows, non-trivial C++ class with trivial ABI is not yet available in Swift
VirtualMethodsTestSuite.test("C++ virtual method with complex parameter") {
@available(macOS 13.3, *)
func f(simpleClass: HasDestructor, immortalClass: Immortal2) {
immortalClass.virtualMethod(simpleClass)
}
}
#endif

runAllTests()