summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorCheng Shao <astrohavoc@gmail.com>2022-10-21 13:47:58 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-11-11 00:26:55 -0500
commit07e92c92673c48db0325f101d07d73134ed79fe9 (patch)
tree26554fec5e7cc1c27108e76b3adbc6b3aefd73ff /utils
parent32ae62e61e811bf99def141a388a3f0abc8b7107 (diff)
downloadhaskell-07e92c92673c48db0325f101d07d73134ed79fe9.tar.gz
rts: workaround cmm's improper variadic ccall breaking wasm32 typechecking
Unlike other targets, wasm requires the function signature of the call site and callee to strictly match. So in Cmm, when we call a C function that actually returns a value, we need to add an _unused local variable to receive it, otherwise type error awaits. An even bigger problem is calling variadic functions like barf() and such. Cmm doesn't support CAPI calling convention yet, so calls to variadic functions just happen to work in some cases with some target's ABI. But again, it doesn't work with wasm. Fortunately, the wasm C ABI lowers varargs to a stack pointer argument, and it can be passed NULL when no other arguments are expected to be passed. So we also add the additional unused NULL arguments to those functions, so to fix wasm, while not affecting behavior on other targets.
Diffstat (limited to 'utils')
-rw-r--r--utils/genapply/Main.hs7
1 files changed, 4 insertions, 3 deletions
diff --git a/utils/genapply/Main.hs b/utils/genapply/Main.hs
index f3b4c174dd..74351ee5f0 100644
--- a/utils/genapply/Main.hs
+++ b/utils/genapply/Main.hs
@@ -639,6 +639,7 @@ genApply regstatus args =
text "RET_SMALL, W_ info_ptr, " <> (cat $ zipWith formalParam args [1..]) <>
text ")\n{",
nest 4 (vcat [
+ text "W_ _unused;",
text "W_ info;",
text "W_ arity;",
text "unwind Sp = Sp + WDS(" <> int (1+all_args_size) <> text ");",
@@ -668,9 +669,9 @@ genApply regstatus args =
tickForArity (length args),
text "",
text "IF_DEBUG(apply,foreign \"C\" debugBelch(\"" <> fun_ret_label <>
- text "... \"); foreign \"C\" printClosure(R1 \"ptr\"));",
+ text "... \", NULL); foreign \"C\" printClosure(R1 \"ptr\"));",
- text "IF_DEBUG(sanity,foreign \"C\" checkStackFrame(Sp+WDS(" <> int (1 + all_args_size)
+ text "IF_DEBUG(sanity,(_unused) = foreign \"C\" checkStackFrame(Sp+WDS(" <> int (1 + all_args_size)
<> text ")\"ptr\"));",
-- text "IF_DEBUG(sanity,checkStackChunk(Sp+" <> int (1 + all_args_size) <>
@@ -795,7 +796,7 @@ genApply regstatus args =
text "default: {",
nest 4 (
- text "foreign \"C\" barf(\"" <> fun_ret_label <> text "\") never returns;"
+ text "foreign \"C\" barf(\"" <> fun_ret_label <> text "\", NULL) never returns;"
),
text "}"