about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2021-06-05 06:13:43 +0900
committerGitHub <noreply@github.com>2021-06-05 06:13:43 +0900
commit5d30ab85b29c217760506770cdce7ee2617d8314 (patch)
treebfee0f789f9a2350868d3cf950e43d2cc29d6c35
parent5ebc4d3697ee12a1484ebc28d0e18d69834b7154 (diff)
parent55769a5ca98452967deb66dc1043a45fe0b2ddba (diff)
downloadrust-5d30ab85b29c217760506770cdce7ee2617d8314.tar.gz
rust-5d30ab85b29c217760506770cdce7ee2617d8314.zip
Rollup merge of #85966 - alexcrichton:wasm-simd-indirect, r=workingjubilee
wasm: Make simd types passed via indirection again

This commit updates wasm target specs to use `simd_types_indirect: true`
again. Long ago this was added since wasm simd types were always
translated to `v128` under-the-hood in LLVM, meaning that it didn't
matter whether that target feature was enabled or not. Now, however,
`v128` is conditionally used in codegen depending on target features
enabled, meaning that it's possible to get linker errors about different
signatures in code that correctly uses simd types. The fix is the same
as for all other platforms, which is to pass the type indirectly.
-rw-r--r--compiler/rustc_target/src/spec/wasm_base.rs6
-rw-r--r--src/test/ui/simd/wasm-simd-indirect.rs33
2 files changed, 33 insertions, 6 deletions
diff --git a/compiler/rustc_target/src/spec/wasm_base.rs b/compiler/rustc_target/src/spec/wasm_base.rs
index 87e740de08e..6c897735194 100644
--- a/compiler/rustc_target/src/spec/wasm_base.rs
+++ b/compiler/rustc_target/src/spec/wasm_base.rs
@@ -103,12 +103,6 @@ pub fn options() -> TargetOptions {
         linker: Some("rust-lld".to_owned()),
         lld_flavor: LldFlavor::Wasm,
 
-        // No need for indirection here, simd types can always be passed by
-        // value as the whole module either has simd or not, which is different
-        // from x86 (for example) where programs can have functions that don't
-        // enable simd features.
-        simd_types_indirect: false,
-
         pre_link_args,
 
         crt_objects_fallback: Some(CrtObjectsFallback::Wasm),
diff --git a/src/test/ui/simd/wasm-simd-indirect.rs b/src/test/ui/simd/wasm-simd-indirect.rs
new file mode 100644
index 00000000000..deac593df43
--- /dev/null
+++ b/src/test/ui/simd/wasm-simd-indirect.rs
@@ -0,0 +1,33 @@
+// build-pass
+
+#![cfg_attr(target_arch = "wasm32", feature(wasm_simd, wasm_target_feature))]
+
+#[cfg(target_arch = "wasm32")]
+fn main() {
+    unsafe {
+        a::api_with_simd_feature();
+    }
+}
+
+#[cfg(target_arch = "wasm32")]
+mod a {
+    use std::arch::wasm32::*;
+
+    #[target_feature(enable = "simd128")]
+    pub unsafe fn api_with_simd_feature() {
+        crate::b::api_takes_v128(u64x2(0, 1));
+    }
+}
+
+#[cfg(target_arch = "wasm32")]
+mod b {
+    use std::arch::wasm32::*;
+
+    #[inline(never)]
+    pub fn api_takes_v128(a: v128) -> v128 {
+        a
+    }
+}
+
+#[cfg(not(target_arch = "wasm32"))]
+fn main() {}