Skip to content

Commit 56e0ea6

Browse files
Xazax-hunGabor Horvath
authored andcommitted
[6.2][cxx-interop] Fix calling rvalue ref of a trivial type
Explanation: Fixes a runtime crash in the generated binary due to mismatched calling convention when calling a function taking an rvalue reference. Scope: Affects C++ APIs taking rvalue references to directly passed types (e.g., trivially destructible types). Issue: rdar://148585343 Risk: Low, targeted to rvalue references which is a newly supported feature. Testing: Added tests to test suite Reviewer: John Hui
1 parent 1b2f8c3 commit 56e0ea6

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)