Skip to content

Commit 6b863f9

Browse files
author
Gabor Horvath
committed
[cxx-interop] Fix calling rvalue ref of a trivial type
The Swift compiler used to generate a direct call to functions taking rvalue references to trivial types even though they expected an indirect calling conventions. This PR changes the calling convention on the Swift side to match C++. rdar://148585343
1 parent 98739a4 commit 6b863f9

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,9 @@ static bool isClangTypeMoreIndirectThanSubstType(TypeConverter &TC,
15431543
if (importer::isCxxConstReferenceType(clangTy))
15441544
return true;
15451545

1546+
if (clangTy->isRValueReferenceType())
1547+
return true;
1548+
15461549
return false;
15471550
}
15481551

test/Interop/Cxx/reference/reference.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,9 @@ ReferenceTestSuite.test("const reference to template") {
103103
expectEqual(53, ref.pointee)
104104
}
105105

106+
ReferenceTestSuite.test("rvalue reference of trivial type") {
107+
setStaticIntRvalueRef(consuming: 2)
108+
expectEqual(2, getStaticInt())
109+
}
110+
106111
runAllTests()

0 commit comments

Comments
 (0)