From 43c4b81be7b35a3d1c60590e6f9b9270e8127aeb Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Thu, 3 Oct 2019 15:00:03 -0700 Subject: [PATCH] Add C ABI for wasm-bindgen compat --- src/librustc_target/abi/call/mod.rs | 3 +++ .../abi/call/wasm32_bindgen_compat.rs | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/librustc_target/abi/call/wasm32_bindgen_compat.rs diff --git a/src/librustc_target/abi/call/mod.rs b/src/librustc_target/abi/call/mod.rs index c6853ebd019..17bad189bcf 100644 --- a/src/librustc_target/abi/call/mod.rs +++ b/src/librustc_target/abi/call/mod.rs @@ -21,6 +21,7 @@ mod x86; mod x86_64; mod x86_win64; mod wasm32; +mod wasm32_bindgen_compat; #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub enum PassMode { @@ -564,6 +565,8 @@ impl<'a, Ty> FnType<'a, Ty> { "hexagon" => hexagon::compute_abi_info(self), "riscv32" => riscv::compute_abi_info(self, 32), "riscv64" => riscv::compute_abi_info(self, 64), + "wasm32" if cx.target_spec().target_os != "emscripten" + => wasm32_bindgen_compat::compute_abi_info(self), "wasm32" | "asmjs" => wasm32::compute_abi_info(cx, self), a => return Err(format!("unrecognized arch \"{}\" in target specification", a)) } diff --git a/src/librustc_target/abi/call/wasm32_bindgen_compat.rs b/src/librustc_target/abi/call/wasm32_bindgen_compat.rs new file mode 100644 index 00000000000..2645e30594c --- /dev/null +++ b/src/librustc_target/abi/call/wasm32_bindgen_compat.rs @@ -0,0 +1,27 @@ +// This is not and has never been a correct C ABI for WebAssembly, but +// for a long time this was the C ABI that Rust used. wasm-bindgen +// depends on ABI details for this ABI and is incompatible with the +// correct C ABI, so this ABI is being kept around until wasm-bindgen +// can be fixed to work with the correct ABI. See #63649 for further +// discussion. + +use crate::abi::call::{FnType, ArgType}; + +fn classify_ret_ty(ret: &mut ArgType<'_, Ty>) { + ret.extend_integer_width_to(32); +} + +fn classify_arg_ty(arg: &mut ArgType<'_, Ty>) { + arg.extend_integer_width_to(32); +} + +pub fn compute_abi_info(fty: &mut FnType<'_, Ty>) { + if !fty.ret.is_ignore() { + classify_ret_ty(&mut fty.ret); + } + + for arg in &mut fty.args { + if arg.is_ignore() { continue; } + classify_arg_ty(arg); + } +}