Skip to content

Commit 3070daf

Browse files
Emit thunk function for specific ABI on WebAssembly.
Changed to make thunk to convert thin-to-thick and non-throws-to-throws, We needs it on WebAssembly host because WASM checks number of arguments strictly for indirect function call.
1 parent 5dc86fd commit 3070daf

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Diff for: lib/SIL/TypeLowering.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -2644,12 +2644,25 @@ TypeConverter::checkFunctionForABIDifferences(SILModule &M,
26442644
return ABIDifference::NeedsThunk;
26452645
}
26462646

2647+
// There is no ABI compatibility between non-throws and throws on WebAssembly,
2648+
// so need thunk.
2649+
if (M.getASTContext().LangOpts.Target.isOSBinFormatWasm()) {
2650+
if (!fnTy1->hasErrorResult() && fnTy2->hasErrorResult()) {
2651+
return ABIDifference::NeedsThunk;
2652+
}
2653+
}
2654+
26472655
auto rep1 = fnTy1->getRepresentation(), rep2 = fnTy2->getRepresentation();
26482656
if (rep1 != rep2) {
26492657
if (rep1 == SILFunctionTypeRepresentation::Thin &&
2650-
rep2 == SILFunctionTypeRepresentation::Thick)
2658+
rep2 == SILFunctionTypeRepresentation::Thick) {
2659+
// There is no ABI compatibility between thin and thick on WebAssembly,
2660+
// so need thunk.
2661+
if (M.getASTContext().LangOpts.Target.isOSBinFormatWasm()) {
2662+
return ABIDifference::NeedsThunk;
2663+
}
26512664
return ABIDifference::ThinToThick;
2652-
2665+
}
26532666
return ABIDifference::NeedsThunk;
26542667
}
26552668

0 commit comments

Comments
 (0)