diff --git a/lib/SIL/TypeLowering.cpp b/lib/SIL/TypeLowering.cpp index 13e8d03cca814..c5a382b5c5784 100644 --- a/lib/SIL/TypeLowering.cpp +++ b/lib/SIL/TypeLowering.cpp @@ -2609,6 +2609,14 @@ TypeConverter::checkFunctionForABIDifferences(SILModule &M, 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 && @@ -2620,8 +2628,14 @@ TypeConverter::checkFunctionForABIDifferences(SILModule &M, } else { return ABIDifference::CompatibleRepresentation_ThinToThick; } - } + // There is no ABI compatibility between thin and thick on WebAssembly, + // so need thunk. + if (M.getASTContext().LangOpts.Target.isOSBinFormatWasm()) { + return ABIDifference::NeedsThunk; + } + return ABIDifference::ThinToThick; + } return ABIDifference::NeedsThunk; }