Skip to content

Commit 01add11

Browse files
committed
Add an assertion and a comment
1 parent e26933a commit 01add11

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/SILGen/SILGenBridging.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,15 +1623,20 @@ void SILGenFunction::emitNativeToForeignThunk(SILDeclRef thunk) {
16231623
}
16241624
}
16251625

1626-
// If we are bridging a Swift method with Any return value(s), create a
1627-
// stack allocation to hold the result(s), since Any is address-only.
16281626
SmallVector<SILValue, 4> args;
16291627
if (substConv.hasIndirectSILResults()) {
16301628
if (F.getRepresentation() ==
16311629
SILFunctionType::Representation::CFunctionPointer) {
1632-
args.push_back(F.begin()->createFunctionArgument(
1633-
substConv.getSingleSILResultType(getTypeExpansionContext())));
1630+
// Pass the result address of the thunk to the native function.
1631+
auto resultTy =
1632+
F.getConventions().getSingleSILResultType(getTypeExpansionContext());
1633+
assert(resultTy ==
1634+
substConv.getSingleSILResultType(getTypeExpansionContext()) &&
1635+
"result type mismatch");
1636+
args.push_back(F.begin()->createFunctionArgument(resultTy));
16341637
} else {
1638+
// If we are bridging a Swift method with Any return value(s), create a
1639+
// stack allocation to hold the result(s), since Any is address-only.
16351640
for (auto result : substConv.getResults()) {
16361641
if (!substConv.isSILIndirect(result)) {
16371642
continue;

0 commit comments

Comments
 (0)