Skip to content
  • Cheng Shao's avatar
    rts: workaround cmm's improper variadic ccall breaking wasm32 typechecking · 07e92c92
    Cheng Shao authored and Marge Bot's avatar Marge Bot committed
    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.
    07e92c92