Skip to content

Commit 6fd3e31

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 2c73d6c commit 6fd3e31

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
@@ -2538,12 +2538,25 @@ TypeConverter::checkFunctionForABIDifferences(SILFunctionType *fnTy1,
25382538
return ABIDifference::NeedsThunk;
25392539
}
25402540

2541+
// There is no ABI compatibility between non-throws and throws on WebAssembly,
2542+
// so need thunk.
2543+
if (M.getASTContext().LangOpts.Target.isOSBinFormatWasm()) {
2544+
if (!fnTy1->hasErrorResult() && fnTy2->hasErrorResult()) {
2545+
return ABIDifference::NeedsThunk;
2546+
}
2547+
}
2548+
25412549
auto rep1 = fnTy1->getRepresentation(), rep2 = fnTy2->getRepresentation();
25422550
if (rep1 != rep2) {
25432551
if (rep1 == SILFunctionTypeRepresentation::Thin &&
2544-
rep2 == SILFunctionTypeRepresentation::Thick)
2552+
rep2 == SILFunctionTypeRepresentation::Thick) {
2553+
// There is no ABI compatibility between thin and think on WebAssembly,
2554+
// so need thunk.
2555+
if (M.getASTContext().LangOpts.Target.isOSBinFormatWasm()) {
2556+
return ABIDifference::NeedsThunk;
2557+
}
25452558
return ABIDifference::ThinToThick;
2546-
2559+
}
25472560
return ABIDifference::NeedsThunk;
25482561
}
25492562

0 commit comments

Comments
 (0)