Skip to content

Commit

Permalink
Emit thunk function for specific ABI on WebAssembly.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kateinoigakukun committed Oct 24, 2019
1 parent 2c73d6c commit 6fd3e31
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/SIL/TypeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2538,12 +2538,25 @@ TypeConverter::checkFunctionForABIDifferences(SILFunctionType *fnTy1,
return ABIDifference::NeedsThunk;
}

// There is no ABI compatibility between non-throws and throws on WebAssembly,
// so need thunk.
if (M.getASTContext().LangOpts.Target.isOSBinFormatWasm()) {
if (!fnTy1->hasErrorResult() && fnTy2->hasErrorResult()) {
return ABIDifference::NeedsThunk;
}
}

auto rep1 = fnTy1->getRepresentation(), rep2 = fnTy2->getRepresentation();
if (rep1 != rep2) {
if (rep1 == SILFunctionTypeRepresentation::Thin &&
rep2 == SILFunctionTypeRepresentation::Thick)
rep2 == SILFunctionTypeRepresentation::Thick) {
// There is no ABI compatibility between thin and think on WebAssembly,
// so need thunk.
if (M.getASTContext().LangOpts.Target.isOSBinFormatWasm()) {
return ABIDifference::NeedsThunk;
}
return ABIDifference::ThinToThick;

}
return ABIDifference::NeedsThunk;
}

Expand Down

0 comments on commit 6fd3e31

Please sign in to comment.