Skip to content

Commit 3308a62

Browse files
authored
Merge pull request #41186 from zoecarver/fix-indirect-self-param
[cxx-interop] Fix crash when calling method that returns specialization of parent.
2 parents 5cc85b4 + c6aee24 commit 3308a62

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2698,19 +2698,17 @@ class CXXMethodConventions : public CFunctionTypeConventions {
26982698
TheDecl(decl), isMutating(isMutating) {}
26992699
ParameterConvention
27002700
getIndirectSelfParameter(const AbstractionPattern &type) const override {
2701-
llvm_unreachable(
2702-
"cxx functions do not have a Swift self parameter; "
2703-
"foreign self parameter is handled in getIndirectParameter");
2701+
if (isMutating)
2702+
return ParameterConvention::Indirect_Inout;
2703+
return ParameterConvention::Indirect_In_Guaranteed;
27042704
}
27052705

27062706
ParameterConvention
27072707
getIndirectParameter(unsigned int index, const AbstractionPattern &type,
27082708
const TypeLowering &substTL) const override {
27092709
// `self` is the last parameter.
27102710
if (index == TheDecl->getNumParams()) {
2711-
if (isMutating)
2712-
return ParameterConvention::Indirect_Inout;
2713-
return ParameterConvention::Indirect_In_Guaranteed;
2711+
return getIndirectSelfParameter(type);
27142712
}
27152713
return super::getIndirectParameter(index, type, substTL);
27162714
}

test/Interop/Cxx/templates/Inputs/member-templates.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ template <class T> struct TemplateClassWithMemberTemplates {
2828

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

31+
template<class U> TemplateClassWithMemberTemplates<U> toOtherSpec(const U& u) const {
32+
return {u};
33+
}
34+
3135
TemplateClassWithMemberTemplates(T val) : value(val) {}
3236
};
3337

test/Interop/Cxx/templates/member-templates.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//
55
// We can't yet call member functions correctly on Windows (SR-13129).
66
// XFAIL: OS=windows-msvc
7-
// REQUIRES: fixing-after-30630
87

98
import MemberTemplates
109
import StdlibUnittest
@@ -23,4 +22,11 @@ TemplatesTestSuite.test("Templated Add") {
2322
expectEqual(h.addMixedTypeParams(2, 1), 3)
2423
}
2524

25+
TemplatesTestSuite.test("Returns other specialization") {
26+
let t = TemplateClassWithMemberTemplates<CInt>(42)
27+
var _5 = 5
28+
let o = t.toOtherSpec(&_5)
29+
// TODO: why is "o" Void here? rdar://88443730
30+
}
31+
2632
runAllTests()

0 commit comments

Comments
 (0)