Skip to content

[cxx-interop] Fix crash when calling method that returns specialization of parent. #41186

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
Feb 3, 2022
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
10 changes: 4 additions & 6 deletions lib/SIL/IR/SILFunctionType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2698,19 +2698,17 @@ class CXXMethodConventions : public CFunctionTypeConventions {
TheDecl(decl), isMutating(isMutating) {}
ParameterConvention
getIndirectSelfParameter(const AbstractionPattern &type) const override {
llvm_unreachable(
"cxx functions do not have a Swift self parameter; "
"foreign self parameter is handled in getIndirectParameter");
if (isMutating)
return ParameterConvention::Indirect_Inout;
return ParameterConvention::Indirect_In_Guaranteed;
}

ParameterConvention
getIndirectParameter(unsigned int index, const AbstractionPattern &type,
const TypeLowering &substTL) const override {
// `self` is the last parameter.
if (index == TheDecl->getNumParams()) {
if (isMutating)
return ParameterConvention::Indirect_Inout;
return ParameterConvention::Indirect_In_Guaranteed;
return getIndirectSelfParameter(type);
}
return super::getIndirectParameter(index, type, substTL);
}
Expand Down
4 changes: 4 additions & 0 deletions test/Interop/Cxx/templates/Inputs/member-templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ template <class T> struct TemplateClassWithMemberTemplates {

template <class U> void setValue(U val) { value = val; }

template<class U> TemplateClassWithMemberTemplates<U> toOtherSpec(const U& u) const {
return {u};
}

TemplateClassWithMemberTemplates(T val) : value(val) {}
};

Expand Down
8 changes: 7 additions & 1 deletion test/Interop/Cxx/templates/member-templates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//
// We can't yet call member functions correctly on Windows (SR-13129).
// XFAIL: OS=windows-msvc
// REQUIRES: fixing-after-30630

import MemberTemplates
import StdlibUnittest
Expand All @@ -23,4 +22,11 @@ TemplatesTestSuite.test("Templated Add") {
expectEqual(h.addMixedTypeParams(2, 1), 3)
}

TemplatesTestSuite.test("Returns other specialization") {
let t = TemplateClassWithMemberTemplates<CInt>(42)
var _5 = 5
let o = t.toOtherSpec(&_5)
// TODO: why is "o" Void here? rdar://88443730
}

runAllTests()