Skip to content

[cxx-interop] Clone all of the attributes from base method correctly #75058

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
Jul 9, 2024
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
12 changes: 5 additions & 7 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5699,9 +5699,10 @@ makeBaseClassMemberAccessors(DeclContext *declContext,
}

// Clone attributes that have been imported from Clang.
DeclAttributes cloneImportedAttributes(ValueDecl *decl, ASTContext &context) {
auto attrs = DeclAttributes();
for (auto attr : decl->getAttrs()) {
void cloneImportedAttributes(ValueDecl *fromDecl, ValueDecl* toDecl) {
ASTContext& context = fromDecl->getASTContext();
DeclAttributes& attrs = toDecl->getAttrs();
for (auto attr : fromDecl->getAttrs()) {
switch (attr->getKind()) {
case DeclAttrKind::Available: {
attrs.add(cast<AvailableAttr>(attr)->clone(context, true));
Expand Down Expand Up @@ -5739,8 +5740,6 @@ DeclAttributes cloneImportedAttributes(ValueDecl *decl, ASTContext &context) {
break;
}
}

return attrs;
}

static ValueDecl *
Expand Down Expand Up @@ -5770,8 +5769,7 @@ cloneBaseMemberDecl(ValueDecl *decl, DeclContext *newContext) {
fn->getThrownInterfaceType(),
fn->getGenericParams(), fn->getParameters(),
fn->getResultInterfaceType(), newContext);
auto inheritedAttributes = cloneImportedAttributes(decl, context);
out->getAttrs().add(inheritedAttributes);
cloneImportedAttributes(decl, out);
out->copyFormalAccessFrom(fn);
out->setBodySynthesizer(synthesizeBaseClassMethodBody, fn);
out->setSelfAccessKind(fn->getSelfAccessKind());
Expand Down
2 changes: 1 addition & 1 deletion test/Interop/Cxx/class/inheritance/Inputs/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct Base {
return i * 2;
}

void pure() const __attribute__((pure)) {}
int pure() const __attribute__((pure)) { return 123; }

inline int sameMethodNameSameSignature() const {
return 42;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
// CHECK-NEXT: mutating func swiftRenamed(input i: Int32) -> Int32
// CHECK-NEXT: @available(swift, obsoleted: 3, renamed: "swiftRenamed(input:)")
// CHECK-NEXT: mutating func renamed(_ i: Int32) -> Int32
// CHECK-NEXT: @_effects(readonly) func pure()
// CHECK-NEXT: @discardableResult
// CHECK-NEXT: @_effects(readonly) func pure() -> Int32
// CHECK-NEXT: @discardableResult
// CHECK-NEXT: func sameMethodNameSameSignature() -> Int32
// CHECK-NEXT: @discardableResult
Expand Down Expand Up @@ -65,7 +66,8 @@
// CHECK-NEXT: mutating func swiftRenamed(input i: Int32) -> Int32
// CHECK-NEXT: @available(swift, obsoleted: 3, renamed: "swiftRenamed(input:)")
// CHECK-NEXT: mutating func renamed(_ i: Int32) -> Int32
// CHECK-NEXT: @_effects(readonly) func pure()
// CHECK-NEXT: @discardableResult
// CHECK-NEXT: @_effects(readonly) func pure() -> Int32
// CHECK-NEXT: @discardableResult
// CHECK-NEXT: func sameMethodDifferentSignature() -> Int32
// CHECK-NEXT: @discardableResult
Expand Down Expand Up @@ -96,7 +98,8 @@
// CHECK-NEXT: mutating func swiftRenamed(input i: Int32) -> Int32
// CHECK-NEXT: @available(swift, obsoleted: 3, renamed: "swiftRenamed(input:)")
// CHECK-NEXT: mutating func renamed(_ i: Int32) -> Int32
// CHECK-NEXT: @_effects(readonly) func pure()
// CHECK-NEXT: @discardableResult
// CHECK-NEXT: @_effects(readonly) func pure() -> Int32
// CHECK-NEXT: @discardableResult
// CHECK-NEXT: func sameMethodDifferentSignature() -> Int32
// CHECK-NEXT: @discardableResult
Expand Down